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"
?>
Need help with php form
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Need help with php form
Yes, in your HTML code simply give the two forms different action properties.Is it possible for just the form chosen to be called and retrieve no information from the other form?
Code: Select all
<form action="page1.php" method="post">
</form>
<form action="page2.php" method="post">
</form>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
- akuji36
- Forum Contributor
- Posts: 190
- Joined: Tue Oct 14, 2008 9:53 am
- Location: Hartford, Connecticut
Re: Need help with php form
Separate forms with fieldsets and use a class for each form and name submit buttons.
Each button will target a form and give each form the action of script which directs
info to mysql table.
<input type="submit" name="submit" value="Add More books" onClick="document.theForm.action='http://www.bearsare us.com/books.html', target='blank'">
Above is the script placed on submit button. Note it is javascript --must use php
in case js is disabled.
Use php case statement to determine where info sent.
example:
button 1 clicked directs info to site 1
or
button 2 clicked directs info to site 2
or
button 3 clicked directs info to site 3
thanks
Rod
Each button will target a form and give each form the action of script which directs
info to mysql table.
<input type="submit" name="submit" value="Add More books" onClick="document.theForm.action='http://www.bearsare us.com/books.html', target='blank'">
Above is the script placed on submit button. Note it is javascript --must use php
in case js is disabled.
Use php case statement to determine where info sent.
example:
button 1 clicked directs info to site 1
or
button 2 clicked directs info to site 2
or
button 3 clicked directs info to site 3
thanks
Rod
Re: Need help with php form
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.