Link to home
Start Free TrialLog in
Avatar of nanharbison
nanharbisonFlag for United States of America

asked on

Need to submit a form to two different pages

I have a form on my website but now I have joined constantcontact.com, so I want the name and email address to automatically be submitted to the URL constant contact has provided, and I also need to submit it to my submit code (I use PHP). Is there a way to do this?
Avatar of Fero45
Fero45

Try this
test.php checks of the value has passed. If TRUE, it creates a for and submit it automatically at onload.


// test.html
<form action='test.php' method='post'>
	<input type='text' name='something'>
	<input type='submit' value='Submit to both'>
</form>
// -------------------------------------------------------------
// test.php
<?
$smth = $_POST['something'];
 
if ($smth)	{
	echo "<body onload='document.forms.forma.submit();'>";
	echo "<form id='forma' action='test2.php' method='post'>";
	echo "<input type='hidden' name='something2' value='$smth'>";
	echo "<input type='submit' value='Submit to both'></form>";
}
?>
 
// ---------------------------------------------------------------
// test2.php
<?
$smth2 = $_POST['something2'];
echo $smth2;
?>

Open in new window

.... line 15 should be only
  echo "</form>";
We do not need a submit button.
Avatar of nanharbison

ASKER

thanks, I will try this tomorrow.
You might have several options, depending on the methods needed to post the data.  If you have a RESTful interface that can take data from the URL, you can use file_get_contents() to send data to as many places as you would like.  RESTful interfaces use an API key to avoid unwanted input.

You can also use CURL or fsockopen to post the data.  I prefer fsockopen.

If you want to post the code you've go so far, I will be glad to show you how to make the post go to two places (or more) with a single script.

Best regards, ~Ray
Sorry I have been away from this for such a long time! Other things got in the way.
Anyway, I have a form, obviously, with a lot of fields, for people to register on our site.
I call an onsubmit:
onsubmit="return CheckData()
CheckData basically makes sure nothing required has been left blank. I included the first few parts of this function below. This all works just fine.
But now I have to make it so the person also automatically gets added to our Constant Contact account, which is a form all by itself, provided by ConstantContact. INSTEAD of using their form, I would like to submit data from the form I am already using. But I still have to use the constantcontact action link.
I have included the constantcontact code below also. I have changed a few of the values, since this will be shown publicly.
So how can I merge these into one submit? I am not a javascript whiz!
Thank you

function CheckData() {
 
	if (document.form.fname.value.length <= 0) {
		alert ("Enter your first name.");
		document.form.fname.focus();
		var problem = true;	
	}
	if (document.form.lname.value.length <= 0) {
		alert ("Enter your last name.");
		document.form.lname.focus();
		var problem = true;	
	}
}
 
//constantcontact
<!-- BEGIN: Constant Contact Stylish Email Newsletter Form -->
<div align="center">
<div style="width:160px; background-color: #ffffff;">
<form name="ccoptin" action="http://visitor.constantcontact.com/xxx.jsp" target="_blank" method="post" style="margin-bottom:3;"><span style="background-color: #006699; float:right;margin-right:5;margin-top:3"><img src="http://img.constantcontact.com/ui/images1/visitor/email1_trans.gif" alt="Email Newsletter icon, E-mail Newsletter icon, Email List icon, E-mail List icon" border="0"></span>
<font style="font-weight: bold; font-family:Arial; font-size:16px; color:#006699;">Sign up for our Email Newsletter</font>
<input type="text" name="ea" size="20" value="" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:10px; border:1px solid #999999;">
<input type="submit" name="go" value="GO" class="submit"  style="font-family:Verdana,Arial,Helvetica,sans-serif; font-size:10px;">
<input type="hidden" name="k" value="000000000000">
<input type="hidden" name="y" value="xx">
</form>
</div>
</div>
<!-- END: Constant Contact Stylish Email Newsletter Form -->

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the points!  Hope it all goes well for you, ~Ray