midnite Posted July 3, 2008 Share Posted July 3, 2008 i have several forms with different names. Each with its own submit buttons. But they all send to the same php. Such as: <form name="one" method="post" action="same.php">...</form><form name="two" method="post" action="same.php">...</form> In "same.php", is it possible to retrieve the value one or two? So that i know which form is sending.Thanks! Link to comment Share on other sites More sharing options...
shadowayex Posted July 3, 2008 Share Posted July 3, 2008 Um, if you have a submit button inside the form, it will only take the information from that form. At least for everything I've done it has. And if you want to avoid potential mix ups, make sure each field has a different name then have the page process the fields you actually want processed. You could also have something like this: <form action="same.php?form=one" method="post">...</form><form action="same.php?form=two" method="post">...</form> And have your PHP look like: <?php$form = mysql_real_escape_string($_GET['form']); //I use mysql escape to prevent injection attacksif($form == "one") {*code for one*}elseif($form == "two") {*code for two*} Link to comment Share on other sites More sharing options...
justsomeguy Posted July 3, 2008 Share Posted July 3, 2008 There's a description of using one PHP script to process multiple forms or have multiple forms on one page in this thread:http://w3schools.invisionzone.com/index.php?showtopic=12509 Link to comment Share on other sites More sharing options...
midnite Posted July 3, 2008 Author Share Posted July 3, 2008 thanks ragae and justsomeguy. i think i will use the name of the submit button. It is a bit disappointing that the name of the <form> seems to be redundant (or i dont know what it is used for ...?) Link to comment Share on other sites More sharing options...
justsomeguy Posted July 3, 2008 Share Posted July 3, 2008 It's not sent to the server on submit. Javascript is the only thing that has access to it. I actually never use a name for my forms, if I want Javascript to access the form I just give it an ID and access it that way. Link to comment Share on other sites More sharing options...
jhecht Posted July 3, 2008 Share Posted July 3, 2008 when i need to access a form, i use a CSS selector to look through the document, since i usually know where the forms are going to be in relation to the document and other div's Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.