Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

posting values from multiple forms 1

Status
Not open for further replies.

rekenaar

Technical User
Feb 16, 2005
38
ZA
Hello

I have one form that is dynamically created from a mysql database.

Code:
echo ("<form name=selectform method=\"POST\">");
	
	while ($myrow = mysql_fetch_array($result))
	{
		echo ("<TR>");
		echo ("<TD>");
		
		echo ("<label><input type=\"radio\" name=\"details\" value=\"{$myrow["ID"]}\">");
		echo ("<TD>");
		 printf ($myrow["Date"]);
		echo ("<TD>");  
		 printf ($myrow["Client"]);
		echo ("<TD>");
		 printf ($myrow["TelW"]);
		echo ("<TD>");
		 printf ($myrow["TelH"]);
		echo ("<TD>");
		 printf ("R ");
		 printf ($myrow["Amount"]);
		echo ("<TD>");
		 printf ($myrow["Consultant"]);
		echo ("<TD>");
		 printf ($myrow["Bank"]);
		echo ("<TD>");
		 printf ($myrow["Status"]);
		echo ("<TD>");
		 printf ($myrow["Description"]);
		
	}

	echo("</form>");

At the bottom I want to have buttons that do different things (add/edit/delete/etc.). When the buttons are clicked to open different pages or just reload the same one. I need to post the selected radiobutton to whatever page needs it.

Example of the submit buttons.
Code:
<form name=addnewform method="POST" action="newentry.php">
<input type=submit name="addnewentry" value="Add New Entry" onclick=submit()>
</form>


<form name=delform method="POST" action="details.php">
<input type=submit name="delentry" value="Delete Entry" onclick=delSubmit()>
</form>

The javascript functions just calls:

Code:
	function submit()
	{
		document.addnewform.submit();
	}

	function delSubmit()
	{
	        document.delform.submit();
	}

How can I sumbit the values selectform when submitting an other form?

Thanks in advance.
 
I see no need for your javascript functions. Input submit will submit current form anyway. So having that javascript function is just a useless overhead. Now, html can submit only one form per submission. However, you have a couple of options:

1. You could make it all one form. That way you will have different buttons and the necessary information (including the name of the button -- which determines which action to take) will be carried over to the next page.

2. Use javascript to submit the "selectform". Since you seem to not be averse to using javascript, you can simply submit the main form with the buttons in other forms. Bad thing about that is that you do not know which button was pushed unless you use another technique to carry that information over. Also, you are relying too much on client side solution.
 
Thanks for the reply Vragabond.

My problem is that I want 3 different submit buttons with different actions:
newentry button goes to newentry.php (This is not a problem and is working fine)
delentry goes to a different page (delentry.php perhaps)
editentry goes to a different page (editentry.php)
With the last 2 I need the selected radiobutton value (The value corresponds to the ID in the database, which I need to know how to update or delete). If this is not possible I guess
I will put all it all one in one php page and then let the page display the necessary information/fields/whatnot corresponding to the button pushed.

Thanks for pointing out my overhead, I am still learning. :D
 
What you want could be accomplished via javascript. When button is clicked, action attribute could change the value to the corresponding file. However, this being a client side solution is not the best.

I would suggest one of the following server-side solutions:

1. Join all the files into one script that uses switch statement to determine what to do.
2. Include all the files in a new file that will be called in the form. Files will be included regarding which action was called.
3. Make a new file that will be called by the form. In this file simply put everything in session variables and redirect to appropriate page.

Hope these suggestions will help you.
 
Allright. I put it all in one form going to one page that does different things depending on the button pressed and I used a session variable to store the selected id. Works like a charm.
Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top