Submit form using only PHP? Without JavaScript?

2019-03-03 18:53发布

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)

5条回答
Melony?
2楼-- · 2019-03-03 19:35

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).

查看更多
看我几分像从前
3楼-- · 2019-03-03 19:39

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.

查看更多
倾城 Initia
4楼-- · 2019-03-03 19:40

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' />

查看更多
Bombasti
5楼-- · 2019-03-03 19:41

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>
查看更多
Lonely孤独者°
6楼-- · 2019-03-03 19:41

add a submit button.

<input type="submit" value="Submit" />
查看更多
登录 后发表回答