I'm using jQuery to, in some cases, automatically submit a form. Here's my code:
$("form [data-autosubmit]").closest("form").submit();
It works, however it doesn't send the name and value of the input type=submit
button.
To elaborate, the following code:
<form method="POST">
<input type="text" name="input" value="text they entered">
<input type="submit" name="submit" value="Submit">
</form>
would send the following POSTdata when submitted by the user:
input: text they entered
submit: Submit
However when the form is submitted by JavaScript, only this POSTdata is sent:
input: text they entered
My PHP scripts rely on the presence of a "submit" value in the POSTdata.
I was thinking I could do:
$("form [data-autosubmit]").closest("form").find("input[type=submit]").click();
But it seems to defy logic, when there is a submit
event on the form intended for this purpose.