Simon336697
asked on
3 forms on one page --> 1 submit button?
Hi guys, hope you are all well.
Guys, I have attached my php page that has 3 forms.
I need to have separate forms due to the way I have structured my page, but have them all sent to the same receiving page to grab their values.
What Id like to know, is, is this possible to have 3 forms on a page, and have only one submit button that caters for all 3 forms?
Basically, Im selecting and deselecting checkboxes on this page, which would be done in different parts of the page, which is why I have 3 forms.
The receiving page needs to grab the value of all those checkboxes selected, with name "checkbox".
So I need the 3 forms to behave as one, that is....any checkboxes selected in any of the 3 forms need to be collectively "summed" and sent to the receiving page, which will then set a variable to grab the posted values.
I dont want to have to add 3 submit buttons in order to do this, so was wondering if you kind gurus could see if there was a solution for this.
Any help greatly appreciated.
Guys, I have attached my php page that has 3 forms.
I need to have separate forms due to the way I have structured my page, but have them all sent to the same receiving page to grab their values.
What Id like to know, is, is this possible to have 3 forms on a page, and have only one submit button that caters for all 3 forms?
Basically, Im selecting and deselecting checkboxes on this page, which would be done in different parts of the page, which is why I have 3 forms.
The receiving page needs to grab the value of all those checkboxes selected, with name "checkbox".
So I need the 3 forms to behave as one, that is....any checkboxes selected in any of the 3 forms need to be collectively "summed" and sent to the receiving page, which will then set a variable to grab the posted values.
I dont want to have to add 3 submit buttons in order to do this, so was wondering if you kind gurus could see if there was a solution for this.
Any help greatly appreciated.
<?php
/**********************************************************************
Define the page number so we know what page we are on:
***********************************************************************/
$pageNumber = (isset($_GET["page"]) && is_numeric($_GET["page"])) ? $_GET["page"] : 1;
/**********************************************************************
Define the number of results to show per page:
**********************************************************************/
$perPage = 270;
/**********************************************************************
Define our PADDING VALUE: eg. "..." is 3, "......." is 7
**********************************************************************/
$padding = 10;
/**********************************************************************
Get the starting index of our results: (on a per page basis)
eg. $startIndex = ( 3 * 10 ) - 10 = 20 (on page 3, 20 is start index)
**********************************************************************/
$startIndex = ($pageNumber * $perPage) - $perPage;
/**********************************************************************
Get the total number of database records:
**********************************************************************/
// $totalCount = "SELECT COUNT(*) as 'Total' FROM technologies_tek";
$totalCount = "SELECT COUNT(*) as 'Total' FROM entries_ent";
$rsCount = mysql_query($totalCount, $conn) or die(mysql_error());
$rowCount = mysql_fetch_object($rsCount);
// echo mysql_result($rsCount,0); // this works and gives a count of 10.
/**********************************************************************
List the page numbers/listings here:
**********************************************************************/
?>
<?php
// print "<div align=\"center\">"; // ------------------------------------------------------------------- DIV holding navigation:
// GET OUR TOTAL NUMBER OF PAGES:
// --------------------------------
$numofPages = ceil($rowCount->Total / $perPage);
// print $numofPages; // this gives total pages:
// eg. 500 rows / 10 = 50 pages.
// PRINT LINK TO FIRST PAGE:
// --------------------------------
print "<div id=\"div_first\">";
print "<a href=\"delete_entry.php?page=1\">FIRST</a> ";
print "</div>";
// print "<a href=\"#\" onclick=\"resetVariable()\">Reset</a>";
// PRINT START AND END RECORD NUMBERS FOR CURRENT PAGE:
// --------------------------------
print "<div id=\"div_start2end\">";
echo "Records: " . ($startIndex + 1) . " to " . ($startIndex + 1 + 269);
print "</div>";
// PRINT A PREVIOUS LINK IF CURRENT PAGE IS NOT THE LAST PAGE:
// --------------------------------
if ($pageNumber > 1) {
print "<div id=\"div_previous\">";
print "<a href=\"delete_entry?page=".($pageNumber - 1)."\">PREVIOUS</a> ";
print "</div>";
}
/*********************************************************************************************
TAKE CARE OF EVERYTHING TO THE LEFT OF THE CURRENT PAGE: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
*********************************************************************************************/
// PRINT THE LOWER LIMIT '...' dots:
// --------------------------------
// If our current page, minus the padding, is > 1 (eg. page 1), then PRINT ...
// to indicate that there are more pages before the padding value, eg.
// FIRST ... 10 11 12 13 14 <15>
// If our current page, minus our padding, is greater than 1:
if (($pageNumber - $padding) > 1) {
print " ... ";
// Set our lower limit:
$lowerLimit = $pageNumber - $padding;
// print $lowerLimit;
// PRINT ALL THE PAGES BETWEEN THE LOWER LIMIT AND THE CURRENT PAGE:
// --------------------------------
// eg. if current page is 7, and lower limit is 2, then
// we need to print all pages 3, 4, 5 and 6.
// Print all padded numbers between lower limit and current page
for ($i = $lowerLimit; $i < $pageNumber; $i++) {
print " <a href=\"delete_entry.php?page=".$i."\">".$i."</a> ";
}
// If we take away the padding, which puts us down to page 1, what do we do
// if we are not on the first page, but maybe on page 3, where no padding applies?
// Without the following, all we would get is 'FIRST LAST'
} else {
for ($i = 2; $i < $pageNumber; $i++) {
print "<a href=\"delete_entry.php?page=".$i."\">".$i."</a> ";
}
}
/*********************************************************************************************
###########################################
TAKE CARE OF WHAT PAGE WE ARE CURRENTLY ON:
###########################################
*********************************************************************************************/
// If we're not on the first page, or the last page, print current page:
if (($pageNumber !=0) && ($pageNumber !=1) && ($pageNumber !=$numofPages)) {
print "<b> - " . $pageNumber . " - </b>";
}
/*********************************************************************************************
TAKE CARE OF EVERYTHING TO THE RIGHT OF THE CURRENT PAGE: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
*********************************************************************************************/
// PRINT THE UPPER LIMIT '...' dots:
// --------------------------------
// If our current page, plus our padding, is less than the total number of pages:
if (($pageNumber + $padding) < $numofPages) {
// Set upper limit:
$upperLimit = $pageNumber + $padding;
// Print all numbers from padded pages above current page:
for ($i = ($pageNumber + 1); $i <= $upperLimit; $i++) {
print " <a href=\"delete_entry.php?page=".$i."\">".$i."</a> ";
}
print " ... ";
} else {
// Print all page numbers between number of pages and current page:
for (($i = $pageNumber + 1); $i < $numofPages; $i++) {
print "<a href=\"delete_entry.php?page=".$i."\">".$i."</a> ";
}
}
// PRINT A NEXT LINK IF CURRENT PAGE IS NOT THE LAST PAGE:
// --------------------------------
if ($pageNumber < $numofPages) {
print "<div id=\"div_next\">";
print "<a href=\"delete_entry.php?page=".($pageNumber + 1)."\">NEXT</a> ";
print "</div>";
}
// PRINT THE NUMBER OF RECORDS IN TOTAL:
// --------------------------------
print "<div id=\"div_totalrecords\">";
echo " Total Records: " . mysql_result($rsCount,0) . " Pages: " . $numofPages;
print "</div>";
// PRINT LINK TO LAST PAGE:
// --------------------------------
print "<div id=\"div_last\">";
print " <a href=\"delete_entry.php?page=".$numofPages."\">LAST</a>";
print "</div>";
print "</div>"; // ----------------------------------------------------------------------------------- end of div_navigation_top_row_wrapper:
/**********************************************************************
Get page results, and LIMIT by the startIndex:
**********************************************************************/
/*
$sql = "SELECT id_tek, name_tek
FROM technologies_tek ORDER BY id_tek
LIMIT $startIndex, $perPage";
*/
/*
$sql = "SELECT id_ent, name_ent, image_ent, header_cat_ent
FROM entries_ent order by fk_id_cat_ent, header_cat_ent, name_ent asc
LIMIT $startIndex, $perPage";
*/
$sql = "select name_ent, name_cat, header_cat_ent, image_ent, id_ent, code_ent from
categories_cat, entries_ent
where fk_id_cat_ent = id_cat
order by name_cat, header_cat_ent asc
LIMIT $startIndex, $perPage";
/**********************************************************************
Get the result set:
**********************************************************************/
$rs = mysql_query($sql, $conn) or die(mysql_error());
/**********************************************************************
Do we have results?:
**********************************************************************/
if (mysql_num_rows ($rs) > 0) {
$count = mysql_num_rows($rs); // total number of rows in table: entries_ent
echo "<div style=\"position:absolute; left:18%;\">Simon: " . $count . "</div>";
// print "You have rows!";
?>
<div id ="div_results_wrapper"> <!-- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> div_results_wrapper: -->
<?php
$x = 1;
while ($row = mysql_fetch_object($rs)) {
// $hiya = $row->id_ent;
// DEFINE ALTERNATING ROW STYLE CLASSES
// -------------------------------------
$header = "headerclass";
$class1 = "noncolumns1";
$class2 = "noncolumns2";
$last_chr = substr ( $row->header_cat_ent, -1 );
if ($class == $class1) {
$class = $class2;
}
else {
$class = $class1;
}
// START OF DETERMINING ROW COLOR AND ALTERNATING ROWS IF-ELSE STATEMENTS
// ----------------------------------------------------------------------
// If the first record is record 1, AND it is a header row (eg. ends with '0'), then do this.
if($x == 1 && $last_chr == "0"){
echo '<div class="column">';
?>
<div class="<?php echo $header; ?>">
<?php
echo $row->name_ent;
?>
</div>
<?php
$x++;
}
// If the first record is record 1, AND it is NOT a header row, then do this.
elseif($x == 1 && $last_chr !== "0"){
echo '<div class="column">';
?>
<div class="top_row">
<div id="div_nameholder">
<?php
echo $row->name_ent;
?>
</div>
</div>
<div class="checker">
<form name="formall_delete" id="formall_delete" method="post" action="delete_entry_ac.php">
<input type="checkbox" name="checkbox[]" id="checkbox" value="<?php echo $row->id_ent; ?>">
<input type="hidden" name="countofnumrows" value="<?php echo $count; ?>">
</form>
</div>
<?php
$x++;
}
elseif($x == 45 && $last_chr == "0"){
?>
<div class="<?php echo $header; ?>">
<?php
echo $row->name_ent;
?>
</div>
</div> <!-- end of div class = column -->
<?php
$x=1;
}
elseif($x == 45 && $last_chr !== "0"){
?>
<div class="bottom_row">
<div id="div_nameholder">
<?php
echo $row->name_ent;
?>
</div>
</div>
<div class="checker">
<form name="formall_delete" id="formall_delete" method="post" action="delete_entry_ac.php">
<input type="checkbox" name="checkbox[]" id="checkbox" value="<?php echo $row->id_ent; ?>">
<input type="hidden" name="countofnumrows" value="<?php echo $count; ?>">
</form>
</div>
</div> <!-- end of div class = column -->
<?php
$x=1;
}
else {
// If any row other than the top or bottom row has a header_cat_ent of '0', then style the record with the $header style..
if( $last_chr == "0" ) {
?>
<div class="<?php echo $header; ?>">
<?php
echo $row->name_ent;
?>
</div>
<?php
$x++;
}
if( $last_chr == "1" ) {
?>
<div class="<?php echo $class; ?>">
<div id="div_nameholder">
<?php
echo $row->name_ent;
// function wz_tooltip_image ($displaynamelink, $title, $image)
// print $row->name_ent;
// print ": ";
?>
</div>
</div>
<div class="checker">
<form name="formall_delete" id="formall_delete" method="post" action="delete_entry_ac.php">
<input type="checkbox" name="checkbox[]" id="checkbox" value="<?php echo $row->id_ent; ?>">
<input type="hidden" name="countofnumrows" value="<?php echo $count; ?>">
</form>
</div>
<?php
$x++;
}
} // end of last else statement
} // end of while statement
}
else {
print "Sorry, no results found.";
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Some rows lpxtech will not have data posted as well.
ASKER
That is....some rows will not have the checkbox element.
ASKER
Here is another reason why its not as simple as wrapping them all in the one form :>)
Notice the black rows have no checkbox element, and thus no form associated with it.
page.jpg
Notice the black rows have no checkbox element, and thus no form associated with it.
page.jpg
ASKER
Thanks for your help lpxtech.
ASKER
Thanks for your help mate.
I would love to wrap all the input tags in one form tag.
I have tried that lpxtech, but because there are different if else sections that fire different css stylings depending on the content of each row returned from a mysql table, I cant just do for example the following...
Open in new window