On a single php page I have 2 forms. Each form calls to a different mySQL table (ex table1, table2, table3, etc). When I select 1 form on the page the other form is also called. Is it possible for just the form chosen to be called and retrieve no information from the other form? Right now when I click on the submit button all the areas where a form is being used displays results. I have 1 func.php page with the text as below and call it to any spot I need with an include. First off is it possible to use a function, like this, in this manner? I'm coding in strict so <form ='name'> is not allowed. In its place I'm using id="<?php echo $idLetter ?>" and then using (on index.php page) $idLetter = 'A'; (then using $idLetter = 'B'; , etc) to differentiate the forms also using <input type='submit' name='<?php echo $inputName ?>' value='CHECK THIS DATE' /> and then using (on index.php page) $inputName = "submit1"; (then using $inputName = "submit2"; , etc) to differentiate the forms Those 2 changes for every form do not seem to be enough. It doesn't matter which submit button is clicked on, all forms are called. The first part of this text is the func.php and then call it with the second part of this text on any PHP page I wish to use it. THIS THE FUNC.PHP <form action="<?php echo $PHP_SELF;?>" method="post" id="<?php echo $idLetter ?>"> <p>Check if this <?php echo $product ?> is available for your event date</p> <p><select name='month'> <option value=''>Month</option> <option value='january'>January</option> ...... <option value='november'>November</option> <option value='december'>December</option> </select> <select name='day'> <option value=''>Day</option> <option value='1'>1</option> <option value='2'>2</option> ..... <option value='30'>30</option> <option value='31'>31</option> </select></p> <p><input type='submit' name='<?php echo $inputName ?>' value='CHECK THIS DATE' /></p> <?php // WHEN SUBMIT IS PRESSED ............................................................................................................................................................................. if (isset($month)&&$month!=""){ // GET ALL THE RECORDS FROM THE TABLE ............................................................................................................................................ $result=mysql_query("SELECT * FROM $selectTable WHERE month ='$month' and day ='$day'"); $row=mysql_fetch_assoc($result); if ($row['available'] == 'Y') { echo "<p>This $product is available on: <br /> $month $day</p> <h2>Book this $product?"; }else{ echo "<p>Sorry, but this $product is not available on $month $day</p> <p>Please try another date or choose a different $product.</p>"; } } ?> </form> THIS IS USED ON ANY PHP(XHTML ) PAGE WHERE I WANT TO CALL THE FUNCTION <?php $idLetter = 'A'; $product = "bouncer"; $inputName = "submit1"; $availabiltyAddress = " selectTable"; include "elements/functions/checkForAvailability.func.php" ?>
make sure submit1 is inside form1 and submit2 is inside form2. so if you press submit1 then it will get data from form1.
Please correct me if I'm wrong but is it not already coded that way? I have the form opening and closing What am I missing?
<?php echo "<pre>"; print_r ($_POST); echo "</pre>"; ?> <form action="test.php" method="post"> <input type="text" name="hey" value="1" /> <input type="submit" /> </form> <form action="test.php" method="post"> <input type="text" name="hey" value="2" /> <input type="submit" /> </form> PHP: Here is an example
This is why I use coldfusion. You need some way to seperate the forms to know which one you are going to be processing example <input type="hidden" name="somename" value="somevalue"> Code (markup): Then just do a check to see what you are processing <?php if( $_POST["somename"] == "somevalue" ){ //process form 1 } else { process other form } Code (markup): Hope it makes sense.
Sorry but that does not work for me (probably due to I'm not using it correctly or putting it in the right place). Shouldn't my <form action="<?php echo $PHP_SELF;?>" method="post" id="<?php echo $idLetter ?>"> (where id replaces name, because its coded in strict and name is not allowed here) and then using a different id example id ='A' , id ='B' etc for every form) be enough to differentiate the forms?