开发者

php forms, how to use multiple forms in one page?

i have 2 or more forms in one page. like this:

<form method="post" >
  <table border="0">
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
<input type="submit" value="get" />
</form>

<form method="post" >
  <table border="0">
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
<input type="submit" value="get1" />
</form>

the forms are similar but with different content.

what happens is when i click the get button on one form, all other forms get triggered also.

is there a way to differentiate the forms so that when i click on a but开发者_Python百科ton only the form that has that button to get triggered?

edit: if i press on get1 the form with get gets also triggered

thanks


Only the form which contains your submit-button should be triggered. Are you sure you closed both forms properly in the HTML?

Can you post a link to the page or paste all the HTML?


If your code is set like...

if(!empty($_POST)) {}

then it'll seem like both forms are submitted, but really you can only access data from the form that was actually submitted. If you put a name on the two submit buttons you can test for $_POST['submitButtonName'].

You can use this page to see the differences pretty easily.

http://pastie.org/pastes/2290937/text


You can't submit more than one form, your first form is just probably wrongly closed, which causes you a trouble


Hope this code will help you. If you want to submitt particular form use javascript or jquery. In my case i will choose jquery. Here is the example of my solution. You will need to change formid and objectid.

$( "#buttonid" ).click(function() {
    $( "#formid" ).submit();
});


The short answer is you really only have one form on your page.

You should give each of your forms a name and id to uniquely identify them.

<form name="form1" id="form1" method="post" action=""> is the way to make each of your forms different. It is important because you may want controls other than a submit button to submit the form. Consider this code in the OnChange event of a dropdown list:

"document.forms.form1.submit()"

This will make the form submit as soon as a value is picked in the dropdown list. For advanced features to work, you need to know what your form's name is. The id for the form can be used to access it using document.getElementById('form1')

Finally, do not use tables to display your forms. Use CSS.

I hope this helps someone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜