Need help with php form
Posted: Fri Jan 22, 2010 9:39 am
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"
?>
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"
?>