I have a form
<form method='post' action='action.php' name='myForm'>
<input type='' name='id' value='id'>
<script>document.myForm.submit();</script>
</form>
Can I submit this form without using JavaScript - only PHP without clicking on the submit button, automatically?
This form must be auto submitted on page load, but not using JavaScript (without onload
)
The act of form submission is done on the client side (browser) and has very little to do with PHP (server side).
You could add a submit button like <input type='submit' value='click here to complete step' />
A form must be submit, by the client side. On client-side, there's only two way: by Javascript or by human (clicking on the submit button).
Why not just use the <input type="submit" />
like the following:
<form method='post' action='action.php' name='myForm'>
<input type='text' name='id' value='id' />
<input type='submit' name='submission' value='Submit id'>
</form>
add a submit button.
<input type="submit" value="Submit" />
Unfortunately, what you are trying to do is not possible. The best you can do is probably this:
<form method='post' action='action.php' name='myForm'>
<input type='' name='id' value='id'>
<input type='submit' id='submit-button' />
<script>domument.getElementByID('submit-button').style.display="none";document.myForm.submit();</script>
</form>
A submit button is displayed when client side scripting is disabled. When it's enabled, the submit button is immediately hidden and the form is automatically submitted.
EDIT
Or you could simply include the PHP file. <?php include action.php; ?>
. You won't have access to the _POST
array, but considering, the client hasn't had chance to enter any data, that won't really matter.