Reputation: 13
I am using the following code to submit a form automatically:
<form id="reg_form" name="reg_form" method="post" action="../mm2/register.php" >
<input ..... />
<input ..... />
<script type="text/javascript">
document.reg_form.submit(); // SUBMIT FORM
</script>
</form>
However, the manual way I was submitting it was using the following button:
<input type="submit" name="save_user" value=" Register >> " >
The problem is the file where the "action" parameter send the data (register.php) READS THE "name" attribute OF THE SUBMIT BUTTON and executes different code based on whether it sees it or not. In other words, I get a different results when I submit using the automatic method or the button.
When I use the submit button, all is well. But when I use the automatic submission method, I get on undesired result.
I DO NOT have access to the "register.php" file to modify this behavior.
Is there any way I can automatically submit a form as if it was sent using a button with a particular "name" attribute?
Thanks for any help!
Upvotes: 0
Views: 5126
Reputation: 250
You can trigger click event on your submit button
document.getElementById('submitButtonId').click();
if you want not to display submit button then you can hide it from css:
<input type="submit" name="save_user" id="submitButtonId" value="Register >>" style="display:none;">
Upvotes: 0
Reputation: 1571
Add this line to your form (or replace the button):
<input type="hidden" name="save_user" value=" Register >> " >
I guess the register.php requires a POST field named save_user
to be present, so a simple
<input type="hidden" name="save_user" value="ok" />
should do the trick too.
Upvotes: 1