I have tried the following but it only works either in submitting the form or updating to the Firestore database.
I want to submit my form first then after the form is submitted I want to update a doc in Firestore.
<form action='/search' method="post">
<input type="text" value="{{ query }}"/>
<input type="submit" value="submit"/>
</form>
and my javascript code
<script>
function update()
{
db = firebase.firestore()
db.collection("users").doc(userid).update({
"number": 2,
})
.then(() => {
console.log("Document successfully written!");
})
.catch((error) => {
console.error("Error writing document: ", error);
});
}
</script>
Intercept the form submit and then programmatically submit the form via an asynchronous request (so that your current page is not reloaded). After this, call the code to update your db.
Refer to this article for sample code on how to intercept your form submit and then do an asynchronous request. Your call to update your db will go into the bit that says .done(function (data) {