Hey!
Iām writing a website where a user fills out fields in an HTML form. There is a button (not a type SUBMIT), which, when clicked, calls an NFT Mint Function through Javascript. This executes properly, and the transactions complete on the Rinkeby testnet. However, Iām not getting what I expect after that. I want my code to change the buttonās text to āTransaction Pendingā and Grey it out, while the transaction is pending. On completion, I want the async function to POST the form data to a .php file on my server. On failure, I want to do error handling. Iām not getting any sort of ātransaction pendingā updates in my page, nor am I getting success or failure actions. Am I missing something? Here are what I believe are relevant code snippets:
<form action="createJSON.php" method="post" name="MintForm">
<div class="form-group">
<label for="ShortName">Short Name: </label>
<input type="text" class="form-control" placeholder="" id="ShortName" name="ShortName">
<label for="DescriptionData">Enter Description:</label>
<textarea class="form-control" placeholder="" name="DescriptionData" id="DescriptionData" rows="15"></textarea>
<input type="hidden" name="fullID" id="fullID" value="25"/> //value = 25 is a placeholder until I get the next stage of code done
<a href="#" class="btn btn-primary" id="MintButton" onclick="mintNewToken()">Mint Token</a>
</div>
async function mintNewToken()
{
console.log("mint function called");
const ABI = [.................. // ABI pulled from Remix goes here
];
const options = {
contractAddress: myContractAddress,
functionName: "mintItem",
abi: ABI,
params: {
to: useraddress,
tokenURI: "myroottokenURIgoeshere"
},
};
console.log("GetElementSection called");
document.getElementById("MintButton").innerHTML = "Transaction Pending...";
document.getElementById("MintButton").style.backgroundColor = "grey";
const receipt = await Moralis.executeFunction(options);
try{
const result = await receipt.wait(5);
console.log("Confirmed Received");
document.MintForm.submit();
}
catch(e) {
console.error(e);
}
}
I feel like Iām missing something glaringly obvious. I get āmint function calledā in console, but I never āGetElementID Sectionā called. And so, obviously, never get the button greying out, never get MintForm being submitted through the javascript, or get any sort of error logging. Am I missing something?
Minor Edit: Going back after posting and ensuring all fields have Name AND id set in the form did not make a difference.