|
-
Jun 22nd, 2012, 07:54 PM
#1
Thread Starter
Addicted Member
Send form to two places to capture data from a user registration form?
Hello Folks,
Can somebody help me out please?
I want to create a registration form so that when a use clicks send, it will go to two different applications. I do not really know if this is possible or I am doing it right. I will appreciate any help and suggestion you can give please.
The task is, when a user clicks send after filling the form, one application will retrive some part of the data (eg firstname, lastname, age, etc) and the other will also retrive some part of the data (also firstname, lastname, age, etc). Is there a way of capturing user registration form values on submission, please?
You can see the files i am currently using.
My MySQL database code and the PHP code are below.
When I fill and test the form, I get the error message 'subscription' was empty and 'attendance was empty' even when they are both checked.
Or when the form gets sent to the database, values for age, subscription, gender and attendance are empty. I don't know if it is because of the checkbox, radiobutton and select menu that I have in those fields.
I would want the form to go two two different places, that is the data on the form will be captured in two places. One place is a web application while the other is an API.
Can this be achived with one form or do I need two forms?
I hope it makes sense what I am aiming at.
The code for my database
Code:
create table players(
fname VARCHAR(25),
lname VARCHAR(25),
email VARCHAR(60),
age VARCHAR(8),
city VARCHAR(20),
gender CHAR(1),
subscription CHAR(1),
phone VARCHAR(20),
hobbies VARCHAR(25),
attendance CHAR(1)
);
The code for my php page
Code:
<?php
//here we set our database log in details.
$hostname = "localhost";
$username = "root";
$password = "";
//connection to t he database with details set above
//if the connections fail, it will show us errors
$link = mysql_connect($hostname,$username,$password);
if(!$link)
{die("No Database connection" .mysql_error());
}
//here we select a database to use.
//If the link fails, show the message below and tell us why.
$selected = mysql_select_db("members",$link)
or die("I cannot find that database" .mysql_error());
?>
<!doctype html>
<html>
<head>
<style type="text/css"> p {margin: 0px;}</style>
<meta charset=utf-8>
<title>Form data entry validation and capturing </title>
</head>
<body>
<h1>User registration form</h1>
<h2>Please complete the form below</h2>
<?php
//we should always show the form unless the data is incomplete
$formdisplay = true;
//initialize the error array
$errors = array();
//has this form been submitted?
if($_SERVER['REQUEST_METHOD'] == "POST"){
//loop through $_POST to check if any values were empty
foreach($_POST as $key => $value){
if(strlen(trim($value)) == 0) $errors[] = "{$key} was empty";
}
//if the $errors array is empty, we can proceed
if(!count($errors)){
//the data was validated, we don't want to show the form now
$formdisplay = false;
//entering data into the database
$fname = mysql_real_escape_string($_POST['fname']);
$lname = mysql_real_escape_string($_POST['lname']);
$email = mysql_real_escape_string($_POST['email']);
$age = mysql_real_escape_string($_POST['age']);
$city = mysql_real_escape_string($_POST['city']);
$gender = mysql_real_escape_string($_POST['gender']);
$subscription = mysql_real_escape_string($_POST['subscription']);
$phone = mysql_real_escape_string($_POST['phone']);
$hobbies = mysql_real_escape_string($_POST['hobbies']);
$hobbies = mysql_real_escape_string($_POST['attendance']);
mysql_query("INSERT INTO `players` VALUES ('$fname', '$lname', '$email', '$age', '$city', '$gender','$subscription','$phone','$hobbies', '$attendance')");
}
}
if($formdisplay):
//yes! We can show the form now.
//are there any errors?
if(count($errors)):
?>
<blockquote>
<h3>There were errors with your form please:</h3>
<!---We use a foreach to check for errors and show them--->
<ul>
<?php foreach($errors as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
</blockquote>
<?php endif; ?>
<!--our form goes in here! We can use CSS to style it -->
<form method="post" />
<p>First name: <input type="text" size="50" name="fname" value="<?php echo htmlentities(@$_POST['fname']); ?>"/></p> <br />
<p>Last name: <input type="text" size="50" name="lname" value="<?php echo htmlentities(@$_POST['lname']); ?>"/></p> <br />
<p>Email: <input type="text" size="50" name="email" value="<?php echo htmlentities(@$_POST['email']); ?>"/></p> <br />
<p>Age: <select name="agegroup" value="<?php echo htmlentities(@$_POST['age']); ?>">
<option value="select">Select</option>
<option value="u18">Under 18</option>
<option value="o18">Over 18</option>
</select></p><br/>
<p>City: <input type="text" size="50" name="city" value="<?php echo htmlentities(@$_POST['city']); ?>"/></p> <br />
<p>Gender: <select name="sex" value="<?php echo htmlentities(@$_POST['gender']); ?>">
<option value="select">Select</option>
<option value="male">M</option>
<option value="female">F</option>
</select></p><br/>
<p>Tick this box to subscribe to our monthly promos: <input type="checkbox" name="subscription" value="<?php echo htmlentities(@$_POST['subscription']); ?>"/></p> <br />
<p>Phone: <input type="text" size="50" name="phone" value="<?php echo htmlentities(@$_POST['phone']); ?>"/> </p> <br />
<p>Hobbies: <input type="text" size="50" name="hobbies" value="<?php echo htmlentities(@$_POST['hobbies']); ?>"/></p> <br />
<p>Morning: <input name="attendance" type="radio" value="<?php echo htmlentities(@$_POST['attendance']); ?>"/>
Afternoon: <input name="attendance" type="radio" value="<?php echo htmlentities(@$_POST['attendance']); ?>"/>
Evening: <input name="attendance" type="radio" value="<?php echo htmlentities(@$_POST['attendance']); ?>"/></p> <br /><br/>
<input type="submit" value="Send">
</form>
<?php else: ?>
<h1>Message sent successfully!</h1>
<p>Thanks for registering!</p>
<?php endif; ?>
<!--I would like to use an API here-->
</body>
</html>
Thanks in advance.
Last edited by menre; Jun 23rd, 2012 at 04:54 AM.
-
Jun 23rd, 2012, 03:57 PM
#2
Lively Member
Re: Send form to two places to capture data from a user registration form?
It is doable using jQuery, or if you want the simplest way that I can think of:
The form posts to php1
php1 uses the values it needs
then it does a curl post to php2 with all the values from the form
php2 uses the values it needs
end
Shouldn't be too hard to fix
-
Jun 23rd, 2012, 05:19 PM
#3
Thread Starter
Addicted Member
Re: Send form to two places to capture data from a user registration form?
Hello,
Thanks for the response. Firstly, I am glad you understand my problem and know how to fix it (as you said it is doable). I actually thought about jQuery but could not get my head around it for this task. So, I will go for the second option with PHP that you suggested. But how do I do that with what I have at the moment?
Secondly, you said it shouldn't be hard to fix. I will really appreciate your help with the fixing please.
I am not usually the kind of person that waits to be spoon-fed. But I have been going about this task (reading tutorials, etc) for some time now that I have become blind to even a simple solution.
Could you help me out with my posted code or share some other example code with me to modify please?
Your help will be MUCH appreciated.
Menre
-
Jun 24th, 2012, 04:58 AM
#4
Lively Member
Re: Send form to two places to capture data from a user registration form?
Let's try to solve this piece by piece.
First of all, you say that you have a problem with the checkboxes not giving you a value, check this link:
http://www.html-form-guide.com/php-f...-checkbox.html
I think you should set the value to something static, like "1". Because then the post variables for the checkboxes will be "1" if it is checked, or "" if it isn't checked.
The same goes with the radio buttons, set the values to something static.
Then you want to pass some of the values on to another php script.
You can do that by using some curl:
Code:
//set POST variables
$url = 'http://yourdomain.com/your.php;
$fields = array(
'lname'=>urlencode($last_name),
'fname'=>urlencode($first_name),
);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
Then the other php doc will also be executed. You just add all the wanted variables to the $fields var.
-
Jun 24th, 2012, 01:36 PM
#5
Thread Starter
Addicted Member
Re: Send form to two places to capture data from a user registration form?
Hello,
Thanks for your message and suggestions.
The examples on that link for creating a form were really easy to understand and follow.
But when I tried applying their techniques to solve my problem, I got some error messages.
I changed my original file to the one below using their techniques.
Code:
<?php
//here we set our database log in details.
$hostname = "localhost";
$username = "root";
$password = "";
//connection to t he database with details set above
//if the connections fail, it will show us errors
$link = mysql_connect($hostname,$username,$password);
if(!$link)
{die("No Database connection" .mysql_error());
}
//here we select a database to use.
//If the link fails, show the message below and tell us why.
$selected = mysql_select_db("members",$link)
or die("I cannot find that database" .mysql_error());
?>
<?php
if (isset($_POST['subscription']) &&
$_POST['subscription'] == "1")
{
echo "a subscribed user";
}
?>
<?php
/***
if (isset($_POST['attendance']) &&
$_POST['attendance'] == "")
{
echo "attendance time unknown";
}
****/
?>
<!doctype html>
<html>
<head>
<style type="text/css"> p {margin: 0px;}</style>
<meta charset=utf-8>
<title>Form data entry validation and capturing </title>
</head>
<body>
<h1>User registration form</h1>
<h2>Please complete the form below</h2>
<?php
//we should always show the form unless the data is incomplete
$formdisplay = true;
//initialize the error array
$errors = array();
//has this form been submitted?
if($_SERVER['REQUEST_METHOD'] == "POST"){
//loop through $_POST to check if any values were empty
foreach($_POST as $key => $value){
if(strlen(trim($value)) == 0) $errors[] = "{$key} was empty";
}
//if the $errors array is empty, we can proceed
if(!count($errors)){
//the data was validated, we don't want to show the form now
$formdisplay = false;
//entering data into the database
$fname = mysql_real_escape_string($_POST['fname']);
$lname = mysql_real_escape_string($_POST['lname']);
$email = mysql_real_escape_string($_POST['email']);
$age = mysql_real_escape_string($_POST['age'] == "");
$city = mysql_real_escape_string($_POST['city']);
$gender = mysql_real_escape_string($_POST['gender'] == "");
$subscription = mysql_real_escape_string($_POST['subscription'] == "1");
$phone = mysql_real_escape_string($_POST['phone']);
$hobbies = mysql_real_escape_string($_POST['hobbies']);
$attendance = mysql_real_escape_string($_POST['attendance'] == "");
mysql_query("INSERT INTO `players` VALUES ('$fname', '$lname', '$email', '$age', '$city', '$gender','$subscription','$phone','$hobbies', $attendance)");
}
}
//do we show the form now?
if($formdisplay):
//yes! We can show the form now.
//are there any errors?
if(count($errors)):
?>
<blockquote>
<h3>There were errors with your form please:</h3>
<!---We use a foreach to check for errors and show them--->
<ul>
<?php foreach($errors as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
</blockquote>
<?php endif; ?>
<!--our form goes in here! We can use CSS to style it -->
<form method="post" />
<p>First name: <input type="text" size="50" name="fname" value="<?php echo htmlentities(@$_POST['fname']); ?>"/></p> <br />
<p>Last name: <input type="text" size="50" name="lname" value="<?php echo htmlentities(@$_POST['lname']); ?>"/></p> <br />
<p>Email: <input type="text" size="50" name="email" value="<?php echo htmlentities(@$_POST['email']); ?>"/></p> <br />
<p>Age: <select name="agegroup" value="<?php echo htmlentities(@$_POST['age'] == ""); ?>">
<option value="select">Select</option>
<option value="u18">Under 18</option>
<option value="o18">Over 18</option>
</select></p><br/>
<p>City: <input type="text" size="50" name="city" value="<?php echo htmlentities(@$_POST['city']); ?>"/></p> <br />
<p>Gender: <select name="sex" value="<?php echo htmlentities(@$_POST['gender'] ==""); ?>">
<option value="select">Select</option>
<option value="male">M</option>
<option value="female">F</option>
</select></p><br/>
<p>Tick this box to subscribe to our monthly promos: <input type="checkbox" name="subscription" value="<?php echo htmlentities(@$_POST['subscription'] == "1"); ?>"/></p> <br />
<p>Phone: <input type="text" size="50" name="phone" value="<?php echo htmlentities(@$_POST['phone']); ?>"/> </p> <br />
<p>Hobbies: <input type="text" size="50" name="hobbies" value="<?php echo htmlentities(@$_POST['hobbies']); ?>"/></p> <br />
<p>Morning: <input name="attendance" type="radio" value="<?php echo htmlentities(@$_POST['attendance'] == ""); ?>"/>
Afternoon: <input name="attendance" type="radio" value="<?php echo htmlentities(@$_POST['attendance']== ""); ?>"/>
Evening: <input name="attendance" type="radio" value="<?php echo htmlentities(@$_POST['attendance'] == ""); ?>"/></p> <br /><br/>
<input type="submit" value="Send">
</form>
<?php else: ?>
<h1>Message sent successfully!</h1>
<p>Thanks for registering!</p>
<?php endif; ?>
<!--I would like to use an API here-->
</body>
</html>
I got these error messages below and noting was in the database though message was said to be sent.
WHEN FILLED WITH THE SUBSCRIPTION BOX TICKED, FOLLOWING ERRORS
Code:
User registration form
Please complete the form below
Notice: Undefined index: age in C:\xampp\htdocs\2012\testwork.php on line 71
Notice: Undefined index: gender in C:\xampp\htdocs\2012\testwork.php on line 73
Message sent successfully!
Thanks for registering!
WHEN SUBMITTED WITHOUT TICKING THE SUBSCRIPTION BOX: ERRORS
Code:
User registration form
Please complete the form below
Notice: Undefined index: age in C:\xampp\htdocs\2012\testwork.php on line 71
Notice: Undefined index: gender in C:\xampp\htdocs\2012\testwork.php on line 73
Notice: Undefined index: subscription in C:\xampp\htdocs\2012\testwork.php on line 74
Message sent successfully!
Thanks for registering!
WITHOUT CHECKING THE TICKBOX AND RADIO BUTTONS:ERRORS
Code:
User registration form
Please complete the form below
Notice: Undefined index: age in C:\xampp\htdocs\2012\testwork.php on line 71
Notice: Undefined index: gender in C:\xampp\htdocs\2012\testwork.php on line 73
Notice: Undefined index: subscription in C:\xampp\htdocs\2012\testwork.php on line 74
Notice: Undefined index: attendance in C:\xampp\htdocs\2012\testwork.php on line 77
Message sent successfully!
Thanks for registering!
WHEN SET TO SOMETHING STATIC AND THE SUBSCRIPTION BOX IS TICKED: THE ERROR
Code:
a subscribed user
User registration form
Please complete the form below
There were errors with your form please:
subscription was empty
Could there be something that I have failed to correct somewhere, please?
Once again, thanks in advance.
-
Jun 25th, 2012, 03:42 AM
#6
Lively Member
Re: Send form to two places to capture data from a user registration form?
You shouldn't do stuff with the form data on the same page as the form. Either you use jQuery ajax, or you just go with the standard way of redirecting the user to a validation page.
Meaning that, move everything except the html from that page to a new page and link the form to that one instead.
-
Jun 26th, 2012, 08:23 AM
#7
Re: Send form to two places to capture data from a user registration form?
 Originally Posted by toxicious
You shouldn't do stuff with the form data on the same page as the form.
Why's that?
-
Jun 26th, 2012, 12:43 PM
#8
Lively Member
Re: Send form to two places to capture data from a user registration form?
 Originally Posted by penagate
Why's that?
I see no reason making it more complex when you have just started with the language. Imho I can't really see why you would want to do it at all. It's like writing all the code in one function when you can split it up in smaller parts so it becomes easier to work with, read and change.
But that is just my opinion
-
Jun 27th, 2012, 03:26 AM
#9
Thread Starter
Addicted Member
Re: Send form to two places to capture data from a user registration form?
Alright, I will split the file later and place the connection details, etc in separate files. I only put everything in one file for now just for you to see where I am going wrong.
I have made some changes to the file so that it look the way the code below is. But when I send the form this way, I do not get any values for age, gender in the database due to two obviouse error messages (age, gender undefined).
The modified code
Code:
<?php
//here we set our database log in details.
$hostname = "localhost";
$username = "root";
$password = "";
//connection to t he database with details set above
//if the connections fail, it will show us errors
$link = mysql_connect($hostname,$username,$password);
if(!$link)
{die("No Database connection" .mysql_error());
}
//here we select a database to use.
//If the link fails, show the message below and tell us why.
$selected = mysql_select_db("members",$link)
or die("I cannot find that database" .mysql_error());
?>
<?php if(isset($_POST['$age,$gender,$subscription,$attendance']) &&
$_POST['$age,$gender,$subscription,$attendance'] == "1")
{echo "All is well";}
?>
<!doctype html>
<html>
<head>
<style type="text/css"> p {margin: 0px;}</style>
<meta charset=utf-8>
<title>Form data entry validation and capturing </title>
</head>
<body>
<h1>User registration form</h1>
<h2>Please complete the form below</h2>
<?php
//we should always show the form unless the data is incomplete
$formdisplay = true;
//initialize the error array
$errors = array();
//has this form been submitted?
if($_SERVER['REQUEST_METHOD'] == "POST"){
//loop through $_POST to check if any values were empty
foreach($_POST as $key => $value){
if(strlen(trim($value)) == 0) $errors[] = "{$key} was empty";
}
//if the $errors array is empty, we can proceed
if(!count($errors)){
//the data was validated, we don't want to show the form now
$formdisplay = false;
//entering data into the database
$fname = mysql_real_escape_string($_POST['fname']);
$lname = mysql_real_escape_string($_POST['lname']);
$email = mysql_real_escape_string($_POST['email']);
$age = mysql_real_escape_string($_POST['age'] == "1");
$city = mysql_real_escape_string($_POST['city']);
$gender = mysql_real_escape_string($_POST['gender'] == "1");
$subscription = mysql_real_escape_string($_POST['subscription'] == "1");
$phone = mysql_real_escape_string($_POST['phone']);
$hobbies = mysql_real_escape_string($_POST['hobbies']);
$attendance = mysql_real_escape_string($_POST['attendance'] == "1");
mysql_query("INSERT INTO `players` VALUES ('$fname', '$lname', '$email', '$age', '$city', '$gender','$subscription','$phone','$hobbies', $attendance)");
}
}
//do we show the form now?
if($formdisplay):
//yes! We can show the form now.
//are there any errors?
if(count($errors)):
?>
<blockquote>
<h3>There were errors with your form please:</h3>
<!---We use a foreach to check for errors and show them--->
<ul>
<?php foreach($errors as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
</blockquote>
<?php endif; ?>
<!--our form goes in here! We can use CSS to style it -->
<form method="post" />
<p>First name: <input type="text" size="50" name="fname" value="<?php echo htmlentities(@$_POST['fname']); ?>"/></p> <br />
<p>Last name: <input type="text" size="50" name="lname" value="<?php echo htmlentities(@$_POST['lname']); ?>"/></p> <br />
<p>Email: <input type="text" size="50" name="email" value="<?php echo htmlentities(@$_POST['email']); ?>"/></p> <br />
<p>Age: <select name="agegroup" value="<?php echo htmlentities(@$_POST['age'] == ""); ?>">
<option value="select">Select</option>
<option value="u18">Under 18</option>
<option value="o18">Over 18</option>
</select></p><br/>
<p>City: <input type="text" size="50" name="city" value="<?php echo htmlentities(@$_POST['city']); ?>"/></p> <br />
<p>Gender: <select name="sex" value="<?php echo htmlentities(@$_POST['gender'] ==""); ?>">
<option value="select">Select</option>
<option value="male">M</option>
<option value="female">F</option>
</select></p><br/>
<p>Tick this box to subscribe to our monthly promos: <input type="checkbox" name="subscription" value="<?php echo htmlentities(@$_POST['subscription'] == ""); ?>"/></p> <br />
<p>Phone: <input type="text" size="50" name="phone" value="<?php echo htmlentities(@$_POST['phone']); ?>"/> </p> <br />
<p>Hobbies: <input type="text" size="50" name="hobbies" value="<?php echo htmlentities(@$_POST['hobbies']); ?>"/></p> <br />
<p>Morning: <input name="attendance" type="radio" value="<?php echo htmlentities(@$_POST['attendance'] == ""); ?>"/>
Afternoon: <input name="attendance" type="radio" value="<?php echo htmlentities(@$_POST['attendance']== ""); ?>"/>
Evening: <input name="attendance" type="radio" value="<?php echo htmlentities(@$_POST['attendance'] == ""); ?>"/></p> <br /><br/>
<input type="submit" value="Send">
</form>
<?php else: ?>
<h1>Message sent successfully!</h1>
<p>Thanks for registering!</p>
<?php endif; ?>
<!--I would like to use an API here-->
</body>
</html>
The error messages
Code:
User registration form
Please complete the form below
Notice: Undefined index: age in C:\xampp\htdocs\2012\testwork.php on line 61
Notice: Undefined index: gender in C:\xampp\htdocs\2012\testwork.php on line 63
Message sent successfully!
Thanks for registering!
Could someone check what I am doing wrong please?
I will really appreciate your help.
-
Jun 27th, 2012, 11:11 PM
#10
Re: Send form to two places to capture data from a user registration form?
You need to take a look at this part:
PHP Code:
<?php if(isset($_POST['$age,$gender,$subscription,$attendance']) && $_POST['$age,$gender,$subscription,$attendance'] == "1") {echo "All is well";} ?>
$_POST is an associative array that holds the submitted data. You can access the value by passing the key(name of the form elements).
For isset() function, you can pass the variables, separated by commas (do not enclose them in quotes).
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 28th, 2012, 02:04 AM
#11
Thread Starter
Addicted Member
Re: Send form to two places to capture data from a user registration form?
I am kind of lost here for two main reasons please. I have had a look at the area you pointed out. I took the quotes around the number "1" out.
Code:
<?php if(isset($_POST['$age,$gender,$subscription,$attendance']) &&
$_POST['$age,$gender,$subscription,$attendance'] == 1)
{echo "All is well";}
?>
When the form is sent the data goes to the database but nothing for 'age' and 'gender' and I still get the rror message below.
Code:
User registration form
Please complete the form below
Notice: Undefined index: age in C:\xampp\htdocs\2012\testwork.php on line 61
Notice: Undefined index: gender in C:\xampp\htdocs\2012\testwork.php on line 63
Message sent successfully!
Thanks for registering!
Our was I doing something wrong?
The other area that I am lost in is in an earlier response,
Code:
//set POST variables
$url = 'http://yourdomain.com/your.php;
$fields = array(
'lname'=>urlencode($last_name),
'fname'=>urlencode($first_name),
);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
I understand the line
Code:
$url = 'http://yourdomain.com/your.php;
would be for a file on my server (or where it is going to?). But I do not know exactly what piece of code to put in that file to do the work.
I am now a bit confused with all these. Could you help me out with that please?
-
Jun 28th, 2012, 06:16 PM
#12
Lively Member
Re: Send form to two places to capture data from a user registration form?
 Originally Posted by menre
I am kind of lost here for two main reasons please. I have had a look at the area you pointed out. I took the quotes around the number "1" out.
Code:
<?php if(isset($_POST['$age,$gender,$subscription,$attendance']) &&
$_POST['$age,$gender,$subscription,$attendance'] == 1)
{echo "All is well";}
?>
What he means with that part is that you can't write $_POST like that.
You will need to check it like this:
Code:
if (isset($_POST['age'], $_POST['gender'], etc))
 Originally Posted by menre
The other area that I am lost in is in an earlier response,
Code:
//set POST variables
$url = 'http://yourdomain.com/your.php;
$fields = array(
'lname'=>urlencode($last_name),
'fname'=>urlencode($first_name),
);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
I understand the line
Code:
$url = 'http://yourdomain.com/your.php;
would be for a file on my server (or where it is going to?). But I do not know exactly what piece of code to put in that file to do the work.
I am now a bit confused with all these. Could you help me out with that please?
First, I made a mistake, change this line:
Code:
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
to this:
Code:
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields);
Second, the $url variable holds the url which curl will post to. You said you wanted to use an API to send form data to, so put the path to the api php file (or if it's in another format).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|