sending $_POST
Moderator: General Moderators
sending $_POST
Hi All,
Im having trouble with the syntax for the following:
I have a page that captures some form vars. After writting these values to a csv file I then to take the name/value pair and send them using $_POST not GET to a secure page so they may be submitted to an email db.
Im not sure how I send these via $_POST instead of page.php?var1=value1& etc....
Anyone steer me in the right direction?
Thanks
Im having trouble with the syntax for the following:
I have a page that captures some form vars. After writting these values to a csv file I then to take the name/value pair and send them using $_POST not GET to a secure page so they may be submitted to an email db.
Im not sure how I send these via $_POST instead of page.php?var1=value1& etc....
Anyone steer me in the right direction?
Thanks
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
So you want to send these values as a post without submitting a form? If thats the case you on option would be cURL. Have a read, give it a try and if you have any more problems let us know.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I have done some research on CURL as you have suggested.
Here is my delima:
Some form data is submitted from "register.php" to "registerdb.php". registerdb.php connect to a db checking to see if the username is already taken. If it is, I need to send all form data back to the register.php, so the user does not have to fill out all fields again.
Here is what I have: (first I do some checking... left that out of snippet)
This seems to be loading my form twice on registerdb.php page. If I remove the echo $results; line it just displays a blank registerdb.php page.
Im trying to get it to redirect back to register.php, fill in the fields, and tell the user the "username" has been taken. However, it is sending back the post data, as I can echo the data, but loading to the wrong page.
Im confused how the redirect works.... How do I handle this?
Thanks,
Keith
Here is my delima:
Some form data is submitted from "register.php" to "registerdb.php". registerdb.php connect to a db checking to see if the username is already taken. If it is, I need to send all form data back to the register.php, so the user does not have to fill out all fields again.
Here is what I have: (first I do some checking... left that out of snippet)
Code: Select all
$postArray = "fullname=".urlencode($fullname)."&title=".urlencode($title); //this is just part of my form data used for example
$url = "http://www.geneva-scientific.com/includes/register.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postArray);
$results = curl_exec($ch);
echo $results;
curl_close($ch);Im trying to get it to redirect back to register.php, fill in the fields, and tell the user the "username" has been taken. However, it is sending back the post data, as I can echo the data, but loading to the wrong page.
Im confused how the redirect works.... How do I handle this?
Thanks,
Keith
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Everah,
Just to clarify, the post above is a different issue with a different site and different problem.
But, regarding your post, yes, I will being doing both CSV and db stuff together on one page. The db is simply used for a backup in case something odd happens to the csv file.
I then need to take those same name=value and pass them using POST to a secure Email campaign service. (Exact Target)
So my confusion is how to POST them without a user actually pressing submit.
And after finding some info on CURL, I believe I could do the following?
Just to clarify, the post above is a different issue with a different site and different problem.
But, regarding your post, yes, I will being doing both CSV and db stuff together on one page. The db is simply used for a backup in case something odd happens to the csv file.
I then need to take those same name=value and pass them using POST to a secure Email campaign service. (Exact Target)
So my confusion is how to POST them without a user actually pressing submit.
And after finding some info on CURL, I believe I could do the following?
Code: Select all
@extract($_POST);
$postArray = "fullname=".urlencode($fullname)."&title=".urlencode($title);
$url = "https://www.someurl.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postArray);
$results = curl_exec($ch);
curl_close($ch);- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Looks about right, provided "fullname" and "title" were in the submission. I would suggest staying away from extract() however, or at least check that the fields you are expecting are there and you filter out any other fields submitted.
edit: grammar.
edit: grammar.
Last edited by feyd on Tue Oct 17, 2006 2:46 pm, edited 1 time in total.
Going back to my post about returning vars back to my form, I figured out why it my form was displaying twice. A loop was firing twice... duh...
anyway, the only issue Im still having is that when I submit the form:
it loads my register.php page on my registerdb.php page. So in my address bar is http://www.site.com/includes/registerdb.php... is that just how CURL works or can I have the actual regester.php page be the one to display?
So by setting
shouldnt that redirect to register.php? or is that now how CURL works?
Sorry for the lame posts, I just really want to get my head around this.
Thanks,
anyway, the only issue Im still having is that when I submit the form:
it loads my register.php page on my registerdb.php page. So in my address bar is http://www.site.com/includes/registerdb.php... is that just how CURL works or can I have the actual regester.php page be the one to display?
So by setting
Code: Select all
$url = "http://www.geneva-scientific.com/includes/register.php";
curl_setopt($ch, CURLOPT_URL,$url);Sorry for the lame posts, I just really want to get my head around this.
Thanks,
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Im getting an odd statement:
When I send my data to email_updates.php, I get this after I hit submit "Object moved to here." "here" being a link to the actual page that needs to load. I get the return url from the form page, see below: $thx, $err, $usub, then the data is sent to email collection page and it returns the url depending on what happens (ie. error, success).
Arggg... I dont know any other methods to send these through POST except CURL...
Thanks again
When I send my data to email_updates.php, I get this after I hit submit "Object moved to here." "here" being a link to the actual page that needs to load. I get the return url from the form page, see below: $thx, $err, $usub, then the data is sent to email collection page and it returns the url depending on what happens (ie. error, success).
Code: Select all
$SubscribeDate = date("F j, Y");
$fname = $_POST['First Name'];
$lname = $_POST['Last Name'];
$emailAdd = $_POST['Email Address'];
$source = $_POST['Source'];
$thx = $_POST['thx']; //http://www.site.com/thankyou.htm
$err = $_POST['err']; //http://www.site.com/error.php
$usub = $_POST['usub'];
************* will write to csv file here **************************
$postArray = "First Name=".urlencode($fname)."&Last Name=".urlencode($lname)."&Email Address=".urlencode($emailAdd)."&Source=".urlencode($source)."&thx=".urlencode($thx)."&err=".urlencode($err)."&usub=".urlencode($usub)."&Subscribe Date".urlencode($SubscribeDate);
$url = "http://cl.exct.net/subscribe.aspx?lid=55555555";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postArray);
$results = curl_exec($ch);
echo $results;
curl_close($ch);Thanks again