I am using WordPress and Gravity Forms plugin and I am trying to pass a parameter from a third party provider to a Gravity Form with Dynamic Population from another page, using the below code
<form method="post" name="goToForm" action="http://www.example.com/?page_id=123">
<input type="hidden" name="param" value="Hello">
<input type="submit" name="fromSubmit" value="Submit">
</form>
Note that the above http://www.example.com/?page_id=123 is the Gravity Form URL.
the closest solution I found is using the HOOK method, but still I want to know how can I call the custom function that is created in functions.php using the HOOK approach from post and pass the parameter.
Any suggestions will be appreciated
If I'm understanding you correctly you want to pass the parameters on the form url?
You can accomplish this in 2 ways:
URL: http://www.example.com/?page_id=123
You can add a hidden field in the form. In the advanced section of the field, select Allow field to be populated dynamically and add the parameter name. So example I want to get the page_id:
After saving your form, inspect the hidden field and you should see it's value as 123
You can add a hook function:
add_filter('gform_field_value_page_id', 'my_custom_population_function');
function my_custom_population_function($value){
return $value'; //or do what ever you want with it
}
If you want to add the page title or id automatically to the form:
Add a hidden field, in the advanced section of the field, add this {embed_post:ID} (Post ID) to the default value. OR
Add a hidden field, in the advanced section of the field, add this {embed_post:post_title} (Post Title) to the default value.
Edit
The user is looking for http://www.gravityhelp.com/documentation/page/Gform_after_submission
You can get your fields/parameters from your form and then save it to your database, update a Wordpress page/post or send it to a third party service provider.
I'm not too sure what user would like to do with the parameter, so I'll show an example of sending it to a third party provider:
We want our entry field numbers so we can get the correct fields:
/* Getting correct field numbers */
add_action("gform_after_submission", "post_to_third_party", 10, 2);
function post_to_third_party($entry, $form){
// Lets get the IDs of the relevant fields and prepare an email message
$message = print_r($entry, true);
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);
// Send
mail('you#domain.com', 'Getting the Gravity Form Field IDs', $message);
}
You should get something like this in your mail:
Array
(
[id] => 64
[form_id] => 5
[date_created] => 2014-07-02 13:27:00
[is_starred] => 0
[is_read] => 0
[ip] => ::1
[source_url] => http://localhost/
[post_id] =>
[currency] => USD
[payment_status] =>
[payment_date] =>
[transaction_id] =>
[payment_amount] =>
[payment_method] =>
[is_fulfilled] =>
[created_by] => 1
[transaction_type] =>
[user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153
Safari/537.36
[status] => active
[1] => Name
[4] => Parameter
)
Where [1] => Name is a Name field and I entered Name for testing and [4] => Parameter is the parameter field with a default value of Parameter.
After we have our correct field numbers, we can then submit it to the third party provider, I'm using curl in this example:
/* Submitting to thirdparty.com */
add_action("gform_after_submission", "post_to_third_party", 10, 2);
function post_to_third_party($entry, $form){
//Submitting to thirdparty.com using curl
function post_to_url($url, $data) {
$fields = '';
foreach($data as $key => $value) {
$fields .= $key . '=' . $value . '&';
}
rtrim($fields, '&');
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($post, CURLOPT_HEADER, 1); //if you want headers
curl_setopt($post, CURLOPT_HEADER, "Content-Type:application/xml");
$result = curl_exec($post);
//If there's an error
if($result === false)
{
echo "Error Number:".curl_errno($ch)."<br>";
echo "Error String:".curl_error($ch);
}
curl_close($post);
}
if($form["id"] == 1){//Form ID
//Lets get the fields to match submission to thirdparty.com
$data = array(
"FirstName" => $entry["1"],
"ParameterName" => $entry["4"]
);
post_to_url("http://thirdparty.com", $data);
}
}
If you want the hook to work for a specific form gform_after_submission_1 will work for form id 1 only.
Related
QUESTION
I get an ERROR 3370 from Sage Pay when trying to repeat transactions of type AUTHORISE (but not PAYMENT). I am using Server Integration with PHP/cURL.
ANSWER
This is most likely because you need to send CoF values during your initial AUTHENTICATE transaction. This establishes the initial record as a valid "Credentital on File" and allows you to carry out REPEAT transactions later.
In a nutshell, the initial AUTHENTICATE record must be created with:
COFUsage = FIRST
InitiatedType = CIT
MITType = UNSCHEDULED
HERE IS THE FULL PHP/CURL CODE THAT IS NOW WORKING FOR ME:
STEP 1: AUTHENTICATE
Assuming you are using Server Integration and the customer is "in session" your initial cURL code will look something like this:
// Initialise cURL
$curl = curl_init();
// Set the Sage Pay server URL
$serverLive="https://live.sagepay.com/gateway/service/authorise.vsp";
// Connect to the Sage Pay server
curl_setopt($curl, CURLOPT_URL, $serverLive);
// Set cURL to post variables
curl_setopt($curl, CURLOPT_POST, 1);
// Declare account variables for posting to the Sage Pay server
$VPSProtocol="4.0"; // Must be 4.0 for CoF usage
$Vendor="......."; // Your Sage Pay Vendor Name
// Declare product variables for posting to the Sage Pay server
$Amount=0.01; // This transaction will be for 1 pence
$Currency="GBP";
$Description="......."; // Product description
// Declare URL of your callback page for posting to the Sage Pay server
$NotificationURL="https://www.......";
// Create a unique 16-character VendorTxCode for posting to the Sage Pay server
$UserID=9999; // Unique user ID
$salt="d5s63ffd6s7fgdhs55377yrwesr24553"; // Encryption key
$VendorTxCode=substr(strtoupper(md5(date("U").$UserID.$salt)), 0, 16);
// Declare other variables to pass to Sage Pay (ie. customer name, email, billing address etc)
// These will have been entered via a form on your website
$CustomerName=".......";
$CustomerEmail=".......";
$BillingFirstnames=".......";
$BillingSurname=".......";
$BillingAddress1=".......";
$BillingCity=".......";
$BillingPostCode=".......";
$BillingCountry="GB";
$BillingPhone=".......";
$DeliveryFirstnames=".......";
$DeliverySurname=".......";
$DeliveryAddress1=".......";
$DeliveryCity=".......";
$DeliveryPostCode=".......";
$DeliveryCountry="GB";
$DeliveryPhone=".......";
Now is probably a good time to INSERT these variables into your MySQL database. Create a table called "sagepay" with field/values as follows:
userID = $UserID
VendorTxCode = $VendorTxCode
TxType = AUTHENTICATE
Amount = $Amount
Description = $Description
You should also have the following fields in your sagepay database table. These will start off empty and will be UPDATE(d) later:
SecurityKey
VPSTxId
TxAuthNo
RelatedVendorTxCode
RelatedSecurityKey
RelatedVPSTxId
RelatedTxAuthNo
SchemeTraceID
ACSTransID
DSTransID
Status
Now post your variables to the Sage Pay server via cURL. Your cURL post should send a $COFUsage value of FIRST to correspond with this being an initial AUTHENTICATE transaction and $InitiatedType must be set to CIT to indicate the customer is "in session" (ie. they are going to enter their payment details on your website in a moment):
// Post the variables to the Sage Pay server
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array('Profile' => 'LOW', 'VPSProtocol' => $VPSProtocol, 'Vendor' => $Vendor, 'TxType' => 'AUTHENTICATE', 'VendorTxCode' => $VendorTxCode, **'Apply3DSecure' => '1', 'COFUsage' => 'FIRST', 'InitiatedType' => 'CIT',** 'Amount' => $Amount, 'Currency' => $Currency, 'Description' => $Description, 'CustomerName' => $CustomerName, 'CustomerEMail' => $CustomerEmail, 'BillingFirstnames' => $BillingFirstnames, 'BillingSurname' => $BillingSurname, 'BillingAddress1' => $BillingAddress1, 'BillingCity' => $BillingCity, 'BillingPostCode' => $BillingPostCode, 'BillingCountry' => $BillingCountry, 'BillingPhone' => $BillingPhone, 'DeliveryFirstnames' => $DeliveryFirstnames, 'DeliverySurname' => $DeliverySurname, 'DeliveryAddress1' => $DeliveryAddress1, 'DeliveryCity' => $DeliveryCity, 'DeliveryPostCode' => $DeliveryPostCode, 'DeliveryCountry' => $DeliveryCountry, 'DeliveryPhone' => $DeliveryPhone, 'NotificationURL' => $NotificationURL', 'Status' => 'OK'
)));
// This is supposed to speed things up (not sure if it does!)
curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
// Request a response from cURL
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
The above code will create an AUTHENTICATE record on the Sage Pay server and return a cURL string containing values that you will use to UPDATE your previously created database record. These variables will be reused when you create the AUTHORISE transaction (see Step 2):
// Get server response
$response = curl_exec($curl);
// Close cURL
curl_close ($curl);
Convert the $response string into an array called $results[]:
// Convert $response string into an array called $results[]
$results = [];
foreach (explode("\n", $response) as $line)
{
list ($key, $value) = explode('=', $line, 2);
$results[$key] = trim($value); // Trim to remove white space
}
The following variables are contained in the $results[] array. Make sure you UPDATE your initial AUTHENTICATE database record with these values. You will need to recall them when you come to AUTHORISE the transaction and take the first payment:
$SecurityKey=$results['SecurityKey']; // Save this to your database
$VPSTxId=$results['VPSTxId']; // Save this to your database
$results[] will also contain the following variable:
$NextURL=$results['NextURL'];
Once an AUTHENTICATE record is created on the Sage Pay server, you can display a card payment page to your customer using an iFrame with the source URL set to $NextURL
<iframe name="my_iframe" src="<?= $NextURL ?>" width='100%' height='520'></iframe>
At this point the customer will enter their card details and, if everything is in order, the transaction will be completed and the iFrame will update with your $NotificationURL
Sage Pay will pass the following variables to your $NotificationURL in the $_REQUEST[] array. It is a good idea to "trim" these values to ensure no white space creeps in:
$Status=trim($_REQUEST['Status']); // This should be "OK"
$TxAuthNo=trim($_REQUEST['TxAuthNo']);
$ACSTransID=trim($_REQUEST['ACSTransID']);
$DSTransID=trim($_REQUEST['DSTransID']);
UPDATE your "sagepay" database table with these values and then display your "Thank You" message.
STEP 2: AUTHORISE
Now you have an AUTHENTICATE record on the Sage Pay server, and a corresponding record in your MySQL database table, you must AUTHORISE the transaction to take the initial payment. This involves creating a new AUTHORISE record on the Sage Pay server and in your MySQL database.
First, create a new 16-character $VendorTxCode for the AUTHORISE record.
Then, SELECT and transfer the values from the original AUTHENTICATE record into "related" variables for resubmission to Sage Pay:
// Declare "related" variables
$RelatedVendorTxCode = $VendorTxCode; // The original VendorTxCode you created
$RelatedVPSTxId = $VPSTxId; // The $VPSTxId returned in $results[] array
$RelatedSecurityKey = $SecurityKey; // The $SecurityKey returned in $results[] array
Now is a good time to INSERT the $VendorTxCode and these "related" variables as a new record in your MySQL database. Set the TxType field for this new record to AUTHORISE.
Next, pass your variables to Sage Pay via cURL to create an AUTHORISE record on the Sage Pay server. Note, the $InitiatedType is now MIT to indicate the customer is no longer "in session", but the $COFUsage value still needs to be FIRST:
// Create an AUTHORISE record
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array('VPSProtocol' => $VPSProtocol, 'VendorTxCode' => $VendorTxCode, 'Vendor' => $Vendor, 'TxType' => 'AUTHORISE', **'Apply3DSecure' => '1', 'COFUsage' => 'FIRST', 'InitiatedType' => 'MIT', 'MITType' => 'UNSCHEDULED',** 'Amount' => $Amount, 'Description' => $Description, 'RelatedVPSTxId' => $RelatedVPSTxId, 'RelatedVendorTxCode' => $RelatedVendorTxCode, 'RelatedSecurityKey' => $RelatedSecurityKey, 'RelatedTxAuthNo' => $RelatedTxAuthNo)));
Sage Pay will respond again with a string ($response). Convert $response into a $results[] array as before. These are some of the variables you will end up with:
$TxAuthNo
$VPSTxId
$SecurityKey
$SchemeTraceID
$ACSTransID
$DSTransID
$Status
UPDATE the AUTHORISE record in your MySQL database table with these variables. You will need these variables for when you come to REPEAT the transaction.
$TxAuthNo is an authorisation code which is only returned if the AUTHORISE record is successfully created on the Sage Pay server (ie. if $Status is "OK").
$SchemeTraceID is your CoF "token" for repeating successful AUTHORISE transactions.
STEP 3: REPEAT
You can REPEAT against AUTHORISE transactions using the following cURL code. Note, the $COFUsage value now changes from FIRST to SUBSEQUENT and you must send the $SchemeTraceID (token) to verify the transaction as a valid "Credential on File". The "related" variables are those of the original AUTHORISE record (ie. $VendorTxCode, $TxAuthNo, $VPSTxId, and $SecurityKey):
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array('VPSProtocol' => $VPSProtocol, 'Vendor' => $Vendor, 'TxType' => 'REPEAT', 'VendorTxCode' => $VendorTxCode, **'Apply3DSecure' => '1', 'COFUsage' => 'SUBSEQUENT', 'InitiatedType' => 'MIT', 'MITType' => 'UNSCHEDULED', 'SchemeTraceID'=> $SchemeTraceID,** 'Amount' => $Amount, 'Currency' => $Currency, 'Description' => $Description, 'RelatedVPSTxId' => $RelatedVPSTxId, 'RelatedVendorTxCode' => $RelatedVendorTxCode, 'RelatedSecurityKey' => $RelatedSecurityKey, 'RelatedTxAuthNo' => $RelatedTxAuthNo )));
I was also facing same issue. But I have used this library and reason behind this issue is in the first transaction request they(Sagepay server) are getting blank COFUsage, InitiatedType, MITType params
https://github.com/thephpleague/omnipay-sagepay
I installed 4.0 version of omnipay-sagepay library rather then 3.0
{
"require": {
"omnipay/sagepay": "~4.0"
}
}
and in the first transaction, I have passed these extra parameters.
$gateway->setCOFUsage("FIRST");
$gateway->setInitiatedType("CIT");
$gateway->setMITType("UNSCHEDULED");
And for repeat transactions, I have passed these params
$gateway->setCOFUsage('SUBSEQUENT');
$gateway->setInitiatedType('MIT');
$gateway->setMITType('UNSCHEDULED');
$gateway->setSchemeTraceID($TransactionReference['scheme_trace_Id']);
and it's working fine for me. Response from sagepay team
I need to insert the following code into POST using CURL:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.bmby.com/shared/AddClient/index.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_REFERER, 'http://xxxxxxxx/');
$data = [
'ProjectID' => xxxx
'Password' => 'xxxxxx',
'Fname' => $_POST['your-name'],
'Email' => $_POST['email'],
'Phone' => $_POST['your-tel'],
#'Esse' => $_POST['msg'],
'Referal' => 'http://xxxxxxxx/',
'MediaTitle' => 'אתר אינטרנט ראשי',
'AllowedMail' => 2, # 0 = allow, 2 = don't allow
'IP' => $_SERVER['REMOTE_ADDR'],
];
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
Any guidance on how to implement this and have the form that we created to relate to the above code so that the service we are using to gather all the leads from the form could get the required info.
Depending on what kind of a form you have (it could be a .php file or a WP plugin), the above code needs to be in a function or a php file that will be executed when your form is submitted, either using the action attribute in the HTML form tag or in a function that's called using a form submit action/filter (which is common if you're using a plugin).
The code you posted, when correctly substituted with the correct variables (for example all the URLs and whatever you pass in $data) is the code for performing a cURL session using POST. Since CURLOPT_RETURNTRANSFER is set, $output will contain the result of the cURL session on success and FALSE on failure. Make sure that the POST variables like $_POST['your-name'] correspond to the name attributes in your form fields. It is also recommended to validate the form fields instead of directly passing the $_POST['your-name']. Once you've edited the code with the correct variable names and URLs, the code should run and the result would be in your $output. You can check the result to see if it was a success or do something with the result as required. If you wish to get the HTTP code you should look into curl_getinfo().
I've got two different remote forms which I need to submit data to. The first one is an http form, and it works just fine. Submit > redirect to result page > return response as variable.
The second one lives on an https page, and it just doesn't work, no matter what I try. So here's what I'm working with:
First form's form tag
<form method="post" name="entry_form" action="a_relative_page.asp?start=1">
Second form's form tag
<form method="post" novalidate enctype="multipart/form-data" action="https://asubdomain.formstack.com/forms/index.php" class="stuff" id="stuff1234567890">
Both buttons are completely unremarkable, with no fancy javascript, and look essentially like
<input type="submit">
And here's the PHP cURL request
$post_data = http_build_query(
array(
'lots_of' => 'values_here'
)
);
$url = 'https://asubdomain.formstack.com/forms/a_page_with_form';
$ch = curl_init($url);
$opts = array(
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_UNRESTRICTED_AUTH => TRUE,
CURLOPT_VERBOSE => TRUE,
// Above options for debugging because I'm desperate
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $post_data
);
curl_setopt_array($ch, $opts);
//Capture result and close connection
$result = curl_exec($ch);
$debug = curl_getinfo($ch);
curl_close($ch);
There's nothing out of the ordinary in curl_getinfo except the expected ["ssl_verify_result"]=> int(0), which I'm ignoring for debugging.
HTTP code is 200. If I echo $result, I can see that all form values are filled out, but the form never submitted and thus never redirected. If I then CLICK on submit, the form submits without issue and redirects as expected.
Again, this is not a problem with the first form, only the second. I'm guessing there's something about the underlying code on formstack that prevents cURL POST from submitting the form, but I can't seem to find it.
EDIT: I found the problem. There are two invisible elements on formstack forms. One of them is an input field called _submit which must be set to 1. The other is the form identifier, which is an integer.
I am currently working on a submit order API for OpenCart. The purpose of this API is not for the webpage part of OpenCart, but for our mobile app to interact with OpenCart.
From my research, there appears to be two ways to submit an order:
Method One:
On the OpenCart webpage, when you want to physically want to submit an order, you go through the workflow of:
add product to shopping cart through checkout/cart/add
input payment_address through checkout/payment_address/validate
input shipping_address through checkout/shipping_address/validate
input shipping method through checkout/shipping_method/validate
input payment method through checkout/payment_method/validate
Confirm/submit the order through (I don't know what URL is actually requested to submit an order).
It appears the benefit of this method is that, given the condition that the customer is logged in, AND you have an API to add items to cart, you don't need to go through the step of manually adding products to cart in the URL. You can also use a string such as existing in payment_address and shipping_address to denote an existing address (so you don't need to manually input anything at all in the URL).
Method Two:
Using checkout/manual. This method, however, requires fully manually setting the inputs for everything:
store_id
customer_id
customer_group_id
payment_country_id
payment_zone_id
payment_country_id
order_product[]
order_voucher
shipping_method[]
order_total[contains keys such as code, title, text, value, and sort_order]
payment[]
May have missed something..
The use of checkout/manual seems to be the API that is for our needs, and I especially like that it would return warning/error messages if the request is not successful - however, the first method allows the the customer to have an interface to add products to cart and access existing variables such as shipping_address, payment_address, and more, given the condition that they're logged in (I'm aware that there is code that does cart->clear() and customer->logout() if the user is logged in).
My question is - has anyone ever implemented manually checking out before? How did you implement it?
Update:
Currently writing a script that would POST some dummy inputs to checkout/manual:
public function submit()
{
# Our new data
$data = array(
"store_id" => 0,
"customer" => "My Name",
"customer_id" => 1,
"customer_group_id" => 1,
"payment_country_id" => 223,
"payment_zone_id" => 3663,
"order_product[0][product_id]" => 1791,
"order_product[0][quantity]" => 1,
"order_product[0][price]" => 5.01,
"order_total[0][code]" => "sub_total",
"order_total[0][title]" => "Sub-Total",
"order_total[0][text]" => "$5.01",
"order_total[0][value]" => 5.01,
"order_total[0][sort_order]" => 1,
"order_total[1][code]" => "total",
"order_total[1][title]" => "Total",
"order_total[1][text]" => "$5.01",
"order_total[1][value]" => 5.01,
"order_total[1][sort_order]" => 9,
"payment_firstname" => "My",
"payment_lastname" => "Name",
"payment_company" => "SomeCompany",
"payment_address_1" => "#123 1234 NameOf street",
"payment_address_2" => "",
"payment_postcode" => "12345",
"payment_city" => "New York",
"shipping_firstname" => "My",
"shipping_lastname" => "Name",
"shipping_company" => "SomeCompany",
"shipping_address_1" => "#123 1234 NameOf street",
"shipping_address_2" => "",
"shipping_postcode" => "12345",
"shipping_city" => "New York",
"shipping" => "free.free",
"shipping_method" => "Free Shipping",
"shipping_code" => "free.free",
"shipping_country_id" => 223,
"shipping_zone_id" => 3663,
"payment" => "cod",
"payment_method" => "Cash On Delivery",
"payment_code" => "cod",
"order_status_id" => 1
);
# Create a connection
$url = HTTP_SERVER . 'index.php?route=checkout/manual';
$ch = curl_init($url);
# Form data string
$postString = http_build_query($data, '', '&');
# Setting our options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# Get the response
$response = curl_exec($ch);
echo $response;
curl_close($ch);
}
However, the return data is this:
{"error":{"warning":"You do not have permission to access this page, please refer to your system administrator."}}
Update 2:
The error was thrown since I could not satisfy either of these conditions when callling checkout/manual: $this->user->isLogged() && $this->user->hasPermission('modify', 'sale/order')
I temporarily removed it by replace it with true so I can always manually add an order.
Using my input params, I do get this JSON:
"success":"Order totals has been successfully re-calculated!", however, checking the administrative orders list, it does not appear a new order gets added.
Update 3:
Despite the ability to create the order, I don't know how to submit the order.
First of all, it is dangerous to comment out the code $this->user->isLogged() && $this->user->hasPermission('modify', 'sale/order'). Instead add some kind of override to the parts that reference $this->request->post['customer_id'] so that you set the post data based on actual customer id. If not, it would be possible for regular customers to spoof log in and checkout data as another customer simply by sending whatever POST data they want.
In regards to the actual order creation, you'll note that checkout/manual returns a json with all necessary order data. All you need to do is add something like this after if (!isset($json['error'])) {
$this->load->model('checkout/order');
$json['order_id'] = $this->model_checkout_order->addOrder($json);
Then return the json to your mobile app and show a confirmation or do whatever you want with the order data. It might also be helpful to send a unique mobile app key along the validate whether or not the request is allowed and/or link to the appropriate customer account.
I have a project where I need to do the following: retrieve some data from a form, fill the database, create a response for the user and post the data to a third party. To give an example, it's like booking a ticket to a concert.The ajax call: You buy the ticket, you receive a response (whether the purchase was successful), a php script sends data to the database, and someone may be announced that a new ticket was bought. Now, I need to pass data to that "someone". Which is what I don't know how to do.
Or, like when someone posts a comment to my question on stackoverflow, I get a notification.
In my particular case, the user creates an event, receives a response and I will need to have certain parameters posted by the user on a calendar. It is important that I could hardly integrate the calendar with the script retrieving the data. I would rather need to "forward" the data to the calendar- quite like pushing notifications.
Can anyone please give me a clue what should I use, or what should I need in order to do the above?
The process will go like this:
AJAX
user----> php script->database
|_ calendar
So if i get you right, you could post your data to the calendar via curl:
$url = "http://www.your-url-to-the-calendar.com";
$postData = array(
"prop1" => "value1",
"prop2" => "value2",
"prop3" => "value3"
);
//urlify the data for the post
$data_string = "";
foreach ($postData as $key => $value)
$data_string .= urlencode($key) . '=' . urlencode($value) . '&';
$data_string = rtrim($data_string, '&');
//will output --> prop1=value1&prop2=value2=prop3=value3
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_POST => count($postData),
CURLOPT_POSTFIELDS => $data_string
));
$result = curl_exec($ch);
If your third party calendar does not require authentication than this would be the best way to post it, if you can not write to the database yourself.
When it requires authentication you would have to first login via curl (send credentials via curl-post, receive cookies, send cookies with your data)
Hope this helps.