rickzwebz Posted January 22, 2010 Share Posted January 22, 2010 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 i d="<?php echo $idLetter ?>" and then using (on a 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 a 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" i d="<?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? <input type='submit' name='submit' value='BOOK NOW' /></h2>"; }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" ?> Quote Link to comment https://forums.phpfreaks.com/topic/189435-ned-help-with-php-forms/ Share on other sites More sharing options...
mapleleaf Posted January 22, 2010 Share Posted January 22, 2010 didn't read your whole post but for two forms you need both forms to be closed </form> and also a submit button for each. Quote Link to comment https://forums.phpfreaks.com/topic/189435-ned-help-with-php-forms/#findComment-1000059 Share on other sites More sharing options...
rickzwebz Posted January 22, 2010 Author Share Posted January 22, 2010 Ok my problem is that the form is in a function and I'm using for every place I need to call it The function starts with a <form> and ends with a </form> I am using id (name can't be used for strict) like this : id="<?php echo $idLetter ?> and then in the php page using : $idLetter = 'A'; (then $idLetter = 'B'; , etc) for submit button <input type='submit' name='<?php echo $inputName ?>' value='CHECK THIS DATE' /></p> then on php page $inputName = 'submit1'; (then $inputName = 'submit2'; , etc Would this work? Quote Link to comment https://forums.phpfreaks.com/topic/189435-ned-help-with-php-forms/#findComment-1000071 Share on other sites More sharing options...
wildteen88 Posted January 22, 2010 Share Posted January 22, 2010 PHP cannot identify forms by their ids. You'll want to give your submit buttons unique names, for example name your submit buttons like form1_submit, form2_submit etc. Now to see which form has been submitted use if(isset($_POST['form1_submit'])) { // code for form1 here } elseif(isset($_POST['form2_submit'])) { // code for form2 here } etc Quote Link to comment https://forums.phpfreaks.com/topic/189435-ned-help-with-php-forms/#findComment-1000084 Share on other sites More sharing options...
jl5501 Posted January 22, 2010 Share Posted January 22, 2010 As has been said, any submit button on a form will always submit all fields btween the same pair of <form> </form> tags as the button. If you want to have a button that submits certain fields only from within a form, then you would have to not use a submit button but a type="button" button and then onclick of that button you would call some javascript to extract the fields you want that button to submit, and send the values to the server via ajax either with GET or POST depending on the volume of data involved. Quote Link to comment https://forums.phpfreaks.com/topic/189435-ned-help-with-php-forms/#findComment-1000175 Share on other sites More sharing options...
rickzwebz Posted January 25, 2010 Author Share Posted January 25, 2010 Thank-you to all, I appreciate all the replies and have tried them all, but I guess I wasn't to clear on my question. I need the form to open to an area on the same page and not open a new page. As when you click on the submit, just below, will display "yes this is available" or what ever. This works now, but for every item on the page a result is displayed and not just the item chosen. Quote Link to comment https://forums.phpfreaks.com/topic/189435-ned-help-with-php-forms/#findComment-1001432 Share on other sites More sharing options...
mapleleaf Posted January 28, 2010 Share Posted January 28, 2010 I think what you are looking for is an onblur call to your database using ajax. Something like a username check that you see on some sites. Like here http://medalsdirect.com/live/register.php When you tab out of the username field the page checks if the username is available. Quote Link to comment https://forums.phpfreaks.com/topic/189435-ned-help-with-php-forms/#findComment-1002841 Share on other sites More sharing options...
teamatomic Posted January 28, 2010 Share Posted January 28, 2010 Not sure exactly what you are trying to do but maybe this example will help you. Even though you can fill in both input boxes only the one associated with its own submit button will post data. <form action="" method=post> <input name=in1 value=""> <br> <input type=submit value=form1> </form> <form action="" method=post> <input name=in2 value=""> <br> <input type=submit value=form2> </form> <?php $in1=$_POST['in1']; $in2=$_POST['in2']; echo "1::$in1<br>"; echo "2::$in2"; ?> if you want both inputs can have the same name and again only the one associated with its own form will post. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189435-ned-help-with-php-forms/#findComment-1002858 Share on other sites More sharing options...
rickzwebz Posted January 28, 2010 Author Share Posted January 28, 2010 Thank-you for your suggestion, but still not working right for me. This is a page I'm having troubles on http://www.rickzwebz.com/bounceNmore/bouncers.php These items have data in mySQL table and are checked for availability. Both show a result when 1 is selected, I only wish for the one selected to display a result. Quote Link to comment https://forums.phpfreaks.com/topic/189435-ned-help-with-php-forms/#findComment-1003126 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.