Solved

3 forms on one page --> 1 submit button?

Posted on 2008-11-02
6
204 Views
Last Modified: 2011-10-19
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.


<?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>&nbsp;&nbsp;&nbsp;";
	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>&nbsp;&nbsp;&nbsp;";		
		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 "&nbsp;...&nbsp;";
		// 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 "&nbsp;&nbsp;&nbsp;<a href=\"delete_entry.php?page=".$i."\">".$i."</a>&nbsp;&nbsp;&nbsp;";	
		}
		// 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>&nbsp;&nbsp;&nbsp;";			
		}
	}
	
	/*********************************************************************************************
	###########################################
	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 "&nbsp;&nbsp;&nbsp;<a href=\"delete_entry.php?page=".$i."\">".$i."</a>&nbsp;&nbsp;&nbsp;";	
		}
		print "&nbsp;...&nbsp;";		
	} 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>&nbsp;&nbsp;&nbsp;";	
		}		
	}
 
	// 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>&nbsp;&nbsp;&nbsp;";	
		print "</div>";							
	}
	
	// PRINT THE NUMBER OF RECORDS IN TOTAL:
	// --------------------------------		
	print "<div id=\"div_totalrecords\">";	
	echo "&nbsp;Total Records: " . mysql_result($rsCount,0) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pages: " . $numofPages;
	print "</div>";
	
	// PRINT LINK TO LAST PAGE:
	// --------------------------------	
	print "<div id=\"div_last\">";	
	print "&nbsp;&nbsp;&nbsp;<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.";
}		  
		  
?>

Open in new window

0
Comment
Question by:Simon336697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 6

Accepted Solution

by:
lpxtech earned 500 total points
ID: 22864604
Hi,

Why are you using 3 seperate forms if you would like to post all of the data?
If you wrap all of the input tags within one form tag, wouldn't that be the best way to go about it?
If the input fields are seperated down the page, you could simple wrap the page or section which holds the input tags with the form tag. This seems to be the most logical way to do what you are describing.
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22864743
Hi lpxtech,

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...


if($x == 1 && $last_chr == "0"){
echo '<div class="column">';
.......
 
elseif($x == 1 && $last_chr !== "0"){
<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; ?>">	
 
...
elseif($x == 45 && $last_chr == "0"){
<div class="checker">
<input type="checkbox" name="checkbox[]" id="checkbox" value="<?php echo $row->id_ent; ?>">
 
....
 
...
 
<div class="checker">
<input type="checkbox" name="checkbox[]" id="checkbox" value="<?php echo $row->id_ent; ?>">
 
...
 
</form

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 22864746
Some rows lpxtech will not have data posted as well.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Simon336697
ID: 22864748
That is....some rows will not have the checkbox element.
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22864759
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
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22864902
Thanks for your help lpxtech.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question