Maintain button submit value when using link to su

2019-09-02 08:10发布

i am trying to create a link that submits a form. I use this and works fine :

<a name="submit" href="javascript:document.theForm.submit();" class="rollover-button gray small"><span>Send Message</span></a>

However, i have a problem. My previous submit button was :

<input type="submit" name="submit" value="Send Message" />

When this was clicked, i was getting a $_POST['submit'] value that i was checking with isset in my php script, to see whether the form is submitted or not. However, this does not work with my submit link. Does anybody know how i can do that ?

EDIT:

I tried that, as suggested :

<form action="." name="theForm" class="contactForm" method="post">

<input type="hidden" name="submit" value="Send Message" />

</form>

<a name="submit" href="javascript:document.theForm.submit();" class="rollover-button gray small"><span>Send Message</span></a>

But still does not work.

4条回答
Anthone
2楼-- · 2019-09-02 08:26

You can use a hidden field instead. So when the form is submitted, you can check if the hidden element exists.

Like this:

<input type="hidden" name="submit" value="Send Message" />

This way, you can check for $_POST['submit'] when you submit the form. Just make sure the hidden <input> is inside the <form> element, so it will POST with the rest of the form.

查看更多
Anthone
3楼-- · 2019-09-02 08:32

You can create input type of hidden and check for its existence:

if (isset($_POST['hiddenName'])) {....}
查看更多
Luminary・发光体
4楼-- · 2019-09-02 08:33

add a hidden input.

<input type="hidden" name="submit" value="Send Message" />

it will not be visible to the user, but it will be send with the form contents.

查看更多
冷血范
5楼-- · 2019-09-02 08:47

You can always hide the submit button (with css display: none) and click it with JavaScript:

document.forms.theForm.elements.submit.click();
查看更多
登录 后发表回答