Solved

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

Posted on 2008-11-02
6
185 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
  • 5
6 Comments
 
LVL 6

Accepted Solution

by:
lpxtech earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Some rows lpxtech will not have data posted as well.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

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

Author Comment

by:Simon336697
Comment Utility
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
Comment Utility
Thanks for your help lpxtech.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now