PDA

View Full Version : Any way to post using header ?


Richard
05-28-2003, 11:53 PM
Is there a way of using 'header' to post things to another php page ?

Spookster
05-29-2003, 12:46 AM
Huh? :confused:

firepages
05-29-2003, 01:14 AM
;)

if you mean sending a POST request a'la form variables then no, you would have to use fsockopen() etc or use an existing script like snoopy (http://snoopy.sourceforge.net)

Richard
05-29-2003, 02:39 PM
Thanks firepages.

I have tested the snoopy class with a simple 'fetchtext' and it worked fine the first time, but now it doesn't want to work again and just shows a blank page :confused: What am I doing wrong ?

<?
include "Snoopy.class";
$snoopy = new Snoopy;

$snoopy->fetchtext("'http://www.php.net/");
print $snoopy->results;
?>

firepages
05-29-2003, 02:56 PM
if you just cut and paste your code then the extra single quote won't help ~

("'http://www.php.net/");

Richard
05-29-2003, 03:52 PM
Oh.. I didn't notice that :)

Thanks

Richard
05-29-2003, 07:26 PM
I have this now:


If ((!$firstname)OR(!$surname)OR(!$address)OR(!$town)OR(!$county)OR(!$postcode)OR(!$email1)OR($echeck == "0")) {
include "/home/domains/xyz.com/user/htdocs/directory/Snoopy.class";
$snoopy = new Snoopy;

$submit_url = "http://www.xyz.com/abc/def.php";

$submit_vars["error"] = "yes";
$submit_vars["title"] = $title;
if ($firstname) { $submit_vars["name1"] = $firstname; }
if ($surname) { $submit_vars["name2"] = $surname; }
if ($address) { $submit_vars["address"] = $address; }
if ($town) { $submit_vars["town"] = $town; }
if ($county) { $submit_vars["county"] = $county; }
if ($postcode) { $submit_vars["postcode"] = $postcode; }
if ($country) { $submit_vars["country"] = $country; }
if ($email1) { $submit_vars["email"] = $email1; }

$snoopy->submit($submit_url,$submit_vars);
}


So if one of the form fields that have been submitted to the page has been left blank, it should post back to the form page with the fields that were filled in, so that they will be already filled out saving the user having to type it again.

But when I submit the form, it goes to the page that this is on, and just blank and doesn't do anything :confused:.

firepages
05-30-2003, 12:35 AM
ahhhhh , now I see what you are tying to do and Snoopy won't help you sorry ;)


Often people do all the processing on 1 page to get over the issue you are talking about, eg

<?
if($_POST['submit']){
//process form
}else{
?>
//show form//
<form action="<?=$_SERVER['PHP_SELF'];?>" etc
blah
<input type="text" name="var" value="<?=$_REQUEST['var'];?>">
</form>
<?}?>


that way the $_REQUEST variables ($_POST/$_GET/etc) are already available.

now if you can't do that with your existing system ... think about using sessions.

on your form display page..

<?
session_start();
if($_SESSION['request']){
$_REQUEST=$_SESSION['request'];
}
?>

that will auto fill any existing data..

then your form processing page...

<?
session_start()
//check your form variables..//
if($error){
$_SESSION['request']=$_REQUEST;
header("location:form_page.php");
}else{
//if we got this far we don't need the session variable//
unset($_SESSION['request']);
}
?>