Clicky

   
 I'm trying to send form data to 3 different php documents but it only goes to one.
 How should it be written to function properly and send 1 as a POST and 2 as a GET method?
Below is a simplified version of my document.
Thanks for the help,
Sas
 <form method="post"  name="ContactForm" onSubmit="return doValidate(this)">  <script language="javascript" type="text/javascript"> <!-- function doValidate(ContactForm) { if      ( ContactForm.Name.value=="")     {alert("What\'s your full name?");ContactForm.Name.focus();return false;} else if ( ContactForm.Phone.value=="")    {alert("Your phone number is required");ContactForm.Phone.focus();return false;}        document.forms[0].action = "Mail_MASTER.php" ;    // This should be method=POST     document.forms[0].action = "FillDatabase1.php";   // This should be method=GET     document.forms[0].action = "FillDatabase2.php";  // This should be method=GET      document.ContactForm.submit();        return true; } --> </script>  <input name="Name" type="text" id="Name"  maxlength="60"/> <input name="Phone" type="text" id="Phone"  maxlength="10"/>  <input type="submit" name="submit" id="submit" value="SUBMIT"  onClick="return doValidate(this)" >                              
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 

Select allOpen in new window

asked 11/29/2011 01:02

sasnaktiv's gravatar image

sasnaktiv ♦♦


7 Answers:
IMO, it sounds like you have a brittle design. Nonetheless, I believe to accomplish what you are after, you will need to use AJAX [or rethink your design ; ) ]. For starters:  http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
link

answered

kaufmed's gravatar image

kaufmed

think of it... if you have 3 roads you must select only one. same goes for the form action attribute.

kaufmed suggestion can be one possibility to solve your problem.
other alternative will be to prepare php that will call from server side to the desired pages with http request.
link

answered 2011-11-29 at 21:14:03

Eyal's gravatar image

Eyal

the first part is some javascript that calls another URL (AJAX is similar).  In your case you'd have to build a GET URL that looks like:

  js_test.php?variable1=value&variable2=value2

put the javascript in your code and call the loadURLContent with the long url you create from your form variables.

js_test.php is the second snippet which echos 99 so you can test the concept quickly.  In your case js_test.php would be the form handling routines.

This way you can call as many GETs as you want within javascript.

The limitation of this way is that a GET may have a limit to its length (may be different on different servers), so if you have many form variables it may be difficult.

Looping through a few form variables and putting them in the form of a GET url isn't a large task in javascript.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var stuff = loadURLContent("js_test.php");
alert(stuff);

function loadURLContent(url) {
	var req = new XMLHttpRequest();
	req.open("GET", url, false);
	req.send(null);
	text = req.responseText;
	return text;
}
1:
2:
3:
<?php
print "999";
?>
link

answered 2011-11-29 at 22:35:17

ropenner's gravatar image

ropenner

Uhh, if you're going to update anything on the server as a result of the submission of the form, you need to be using the POST method.  GET is only for inquiries which do not change the state of the data model.

But to the question about three scripts, my general sense is that the application is misdesigned and should be refactored so that only one script is needed to perform the three functions.  Of course you can use CURL to act as a "repeater" sending the data off to three different scripts, but that would not be an idea that would win any design contests in professional circles.  If it were my problem, I would start over and use the HTML forms and the PHP scripts in the way they are designed to work together.
http://php.net/manual/en/tutorial.forms.php

Best of luck, ~Ray
link

answered 2011-11-30 at 00:13:43

Ray_Paseur's gravatar image

Ray_Paseur

Thanks Guys,
I found a very simple way to accomplish the feat.
Sas
link

answered 2011-11-30 at 04:01:55

sasnaktiv's gravatar image

sasnaktiv

The Administrator "modus_in_rebus" requested that I post my solution. So here it is.
In order to INSERT data into one table and UPDATA in another table, I simply created two documents.
One that did the INSERT then passed the appropriate values to another that executed the UPDATE.
It's a simple solution and works like a charm.
Thanks for the attention guys,
Sas
link

answered 2011-12-03 at 13:02:23

sasnaktiv's gravatar image

sasnaktiv

As per Administrator's instructions.

link

answered 2011-12-12 at 08:40:29

sasnaktiv's gravatar image

sasnaktiv

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

Asked: 11/29/2011 01:02

Seen: 249 times

Last updated: 12/16/2011 05:19