Menu
Say I have a form like so:
<form action=”ex.php” method=”post” name=”frm”>
<input type=”text” name=”fn” />
<input type=”text” name=”ln” />
<input type=”button” value=”submit” />
</form>
I need these input values to be posted to ex.php and once submission is done redirected to a different .php or .html page after. Basically, I would like it to look like the viewer never even went to ex.php. Does that make sense? Sorry if I am confusing!!!!
[CODE]<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/path/to/form");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$data = array(
'foo' => 'foo foo foo',
'bar' => 'bar bar bar',
'baz' => 'baz baz baz'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);[/CODE]
[code=php]
<?php
/*
process the $_POST data...
then...
*/
header("Location: http://yoursite.com/success.html");
exit;
?>
[/code]
[code=php]
<?php
if(!empty($_POST)) {
/*
/ Process the form data
/ write any errors to the $errors array
*/
if(empty($errors)) {
header("Location: http://yoursite.com/success.html");
exit; // we're done here and don't want to do anything else
}
}
<html><head><title>form</title></head><body>
<h1>My Form</h1>
<?php
if(!empty($errors)) {
echo "<div class='error'>n";
foreach($errors as $err) {
echo "<p>$err</p>n";
}
echo "</div>n";
}
?>
<form action="" method="post"> <!-- empty action submits to self -->
<div>
<input type="text" name="foo" value="<?php
if(isset($_POST['foo'])) { echo htmlentities($_POST['foo'], ENT_QUOTES); }
?>" /><br />
<input type="text" name="bar" value="<?php
if(isset($_POST['bar'])) { echo htmlentities($_POST['bar'], ENT_QUOTES); }
?>" /><br />
<input type='submit' value='Submit' />
</div>
</form>
</body></html>
[/code]
For some reason I was thinking you wanted to submit the data to another site, then have it redirect back to yours.[/QUOTE]
This is exactly what I want (what you said above)...
Sorry I made things so confusing. I need to submit data to another URL and redirect back to mine. I have been reading up on CURL, but haven't figured it out yet.[/QUOTE]
[code=php]
$data = array();
$data[] = 'foo='.urlencode($_POST['foo']);
$data[] = 'bar='.urlencode($_POST['bar']);
// etc....
// use implode() to create the data string:
curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $data));
[/code]
[code=php]
$post_data = array();
foreach($data as $key => $value) {
$post_data[] = urlencode($key)."=".urlencode($value);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/path/to/form");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $post_data));
$output = curl_exec($ch);
/* now parse $output to get the results of the transaction */
[/code]
[CODE]curl_setopt($ch, CURLOPT_URL, "http://www.example.com/path/to/form");[/CODE]
[CODE]curl_setopt($ch, CURLOPT_URL, "http://www.example.com/path/to/form");[/CODE]
So this is the path to my html with the form on it?
Where do I put the URL that the form is being sent to?[/QUOTE]
[CODE]
<?php
echo "
<html>
<body onload='document.formAuto.submit();'>
<form method='post' action='www.thankyou.php' name='formAuto' >
<input type='hidden' name='firstname' value='$i1' />
<input type='hidden' name='lastname' value='$i2' />
<input type='hidden' name='email' value='$i3' />
<input type='hidden' name='address1' value='$i4' />
<input type='hidden' name='city' value='$i5' />
<input type='hidden' name='state' value='$i6' />
<input type='hidden' name='country' value='$i7' />
<input type='hidden' name='zip' value='$iz' />
<input type='hidden' name='birthyear' value='$i8' />
<input type='hidden' name='ph1' value='$i9$i10$i11' />
<input type='hidden' name='laprotocolkey' value='332' />
<input type='hidden' name='LAPKEY' value='332' />
<input type='hidden' name='listcode' value='http://www.mylocaljoblisting.com' />
<input type='hidden' name='listcodedate' value='$today' />
<input type='hidden' name='source' value='CoReg' />
<input type='hidden' name='channel' value='Web1' />
<input type='hidden' name='lpartner' value='DMI' />
<input type='hidden' name='debug' value='No' />
</form>
</body>
</html>
";
$data = array();
foreach($data as $key => $value) {
$data[] = urlencode($key)."=".urlencode($value);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://laprotocol.com/xml/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $data));
$output = curl_exec($ch);
?>[/CODE]
[CODE]$data = array();
foreach($data as $key => $value) {
$data[] = urlencode($key)."=".urlencode($value);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.external-site.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $data));
$output = curl_exec($ch);
curl_close($ch);
echo "
<html>
<body onload='document.formAuto.submit();'>
<form method='post' action='http://www.my-site.com/thankyou.php' name='formAuto'>
<input type='hidden' name='firstname' value='$i1' />
<input type='hidden' name='lastname' value='$i2' />
<input type='hidden' name='email' value='$i3' />
<input type='hidden' name='address1' value='$i4' />
<input type='hidden' name='city' value='$i5' />
<input type='hidden' name='state' value='$i6' />
<input type='hidden' name='country' value='$i7' />
<input type='hidden' name='zip' value='$iz' />
<input type='hidden' name='birthyear' value='$i8' />
<input type='hidden' name='ph1' value='$i9$i10$i11' />
<input type='hidden' name='d_url' value='$d_url' />
</form>
</body>
</html>
";
[/CODE]
[code=php]
<?php
session_start();
/*
Do the cURL processing
*/
if($result_from_curl_is_ok) {
$_SESSION = array_merge($_SESSION, $data); // replace $data with applicable array
session_write_close(); // makes sure session data saved before redirect
header('Location: http://your-site.com/success.php');
exit; // our work is done here
}
/*
Do whatever is needed if the cURL stuff failed, or the remote site complained
about the data, or whatever....
*/
[/code]
Is this pseudo code or is it an actual curl expression?
if($result_from_curl_is_ok)[/QUOTE]
[CODE]
$data = array();
$data[] = 'firstname='.urlencode($i1);
$data[] = 'lastname='.urlencode($i2);
$data[] = 'keyCode='.urlencode('12343233');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "www.external-url.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $data));
$output = curl_exec($ch);
curl_close($ch);
echo "
<html>
<body onload='document.formAuto.submit();'>
<form method='post' action='www.my-site.com/thankyou.php' name='formAuto'>
<input type='hidden' name='firstname' value='$i1' />
<input type='hidden' name='lastname' value='$i2' />
</form>
</body>
</html>
";[/CODE]
0.1.9 — BETA 5.15