How to create a POST request to replicate a form

7 replies
Hi,

Just wondering if any programmers out there might have some knowledge on how to create a post request to replicate a form (or can tell me where I might find such information online).

For example the company I use for e-commerce allows me to send a HTTP POST notification after a sale. I'd like to use that to add an email address to an autoresponder. So I'd need that post request to replicate the standard POST message that my sign up form would create.

Is that possible and how would I do it?

Cheers

Max
#create #form #post #replicate #request
  • Profile picture of the author Manfred Ekblad
    This is one way to do a POST request using PHP, the code is from PHP: HTTP context options - Manual

    <?php

    $postdata = http_build_query(
    array(
    'var1' => 'some content',
    'var2' => 'doh'
    )
    );

    $opts = array('http' =>
    array(
    'method' => 'POST',
    'header' => 'Content-type: application/x-www-form-urlencoded',
    'content' => $postdata
    )
    );

    $context = stream_context_create($opts);

    $result = file_get_contents('http://example.com/submit.php', false, $context);

    ?>

    The code you need to change is the part where it says:

    'var1' => 'some content'

    Simply set all the form variables there.

    Hope it helps!
    {{ DiscussionBoard.errors[2195589].message }}
  • Profile picture of the author senderbot
    Hi,

    Thanks for that but I dont think that's what I need. I dont think I'm explaining myself very well. I'll try again.

    Lets say you are using Paypals Instant Payment Notification. You get to enter a URL that the parameters will be sent to...

    Is there a way that I can use that IPN service to send the email address atribute to my autoresponders registration page.

    My autoresponder form sends the POST information to a URL like this -
    http://www.example.com/resp/register.php?list_id=1

    Is it possible to add any parameters to the end of that that URL so that when it is triggered by the payment company it will contain the email address?

    Cheers

    Max
    Signature
    PornStarStamina is for sale! - Buy the book rights and website! or Just Download the Book For FREE! - Check it out!
    {{ DiscussionBoard.errors[2197300].message }}
    • Profile picture of the author Mr. Enthusiastic
      Originally Posted by senderbot View Post


      My autoresponder form sends the POST information to a URL like this -
      http://www.example.com/resp/register.php?list_id=1

      Is it possible to add any parameters to the end of that that URL so that when it is triggered by the payment company it will contain the email address?
      Max, there are two ways to add parameters to an URL.

      One is by adding the parameters to the end of the URL itself, as you showed above list_id is set to the value 1 for this particular call to register.php.

      The other way is with POST. In a POST, all you have for the URL is register.php. All of the individual variables are set programmatically, as Manfred demonstrated. PHP will then package up all the variables into the data transfer with the HTTP POST. When you see the URL in your browser, you won't see all the parameters listed. However, they will be included in the POST.

      If you are designing the API, you can choose whether to use POST or GET (the ordinary type of URL with the parameters at the end of the URL). If you are using someone else's API, you have to use whichever method they decided to use.

      One of the most useful theories about how to organize this choice is called "RESTful" (for Representational State Transfer). But if you aren't designing API's, just using them, you probably don't need to get into the details.

      Here's a more detailed discussion of the trade-off:
      When do you use POST and when do you use GET? - Stack Overflow

      Does this make sense?

      Chris
      {{ DiscussionBoard.errors[2200300].message }}
  • Profile picture of the author Manfred Ekblad
    Hmm... let me think...

    So, is this how you mean?

    1. Visitor visits your site and add some items to her cart
    2. She checks out and goes to the payment-page at Paypal
    3. She pays and returns to your site
    4. Just as she paid, the IPN-service made a callback to your site to notify about the payment
    5. ...and what you want is that when the IPN makes it's callback, the script that receives the notification makes a request to the autoresponder-service and signs her up.

    Something like that? Just want to make sure that we help you with the right problem in mind...
    {{ DiscussionBoard.errors[2200247].message }}
    • Profile picture of the author Manfred Ekblad
      quoting myself... lol

      Originally Posted by Manfred Ekblad View Post

      1. Visitor visits your site and add some items to her cart
      2. She checks out and goes to the payment-page at Paypal
      3. She pays and returns to your site
      4. Just as she paid, the IPN-service made a callback to your site to notify about the payment
      5. ...and what you want is that when the IPN makes it's callback, the script that receives the notification makes a request to the autoresponder-service and signs her up.
      You need a couple of things... the email from the buyer, it's in the IPN variable: payer_email

      So in step 4 above, Paypal makes a request to a script that you created. In your script you can access the payer_email in $_POST['payer_email'] (pls do some input validation :p ).

      And in step 5, you simply make a request to the autoresponders signup-script.

      Example (starting from step 4 above) :

      4. The buyer has paid and the IPN now makes a call to www.mydomain.com/myscript.php. The myscript.php will receive the variable payer_email in the POST data.

      5. The myscript.php now has the payer_email in the $_POST['payer_email']. Some input validation and then store it in $payeremail. Now myscript.php will sign up the payer by making an outgoing request to the autoresponder using the code I showed previously. Let's say the autoresponder only need one variable, "email". Then the top most part of the code should be modified to:

      $postdata = http_build_query(
      array(
      'email' => $payeremail
      )
      );

      ...and then do the request. So if the autoresponder has something like www.theautoresponder.com/signup.php you would send the request to that URL.

      --------------

      Now, if you want to make a request directly from the IPN to the autoresponder, then you need to configure the autoresponder to accept POSTs and then map payer_email to the subscribers email. There is also a variable "custom" which you can set with the buyers email before they hit the Pay Now-button. So you can map either the "payer_email" or the "custom" variable, if your autoresponder has that kind of feature.

      I recommend that you follow the guidelines in Paypal's Instant Payment
      Notification Guide
      {{ DiscussionBoard.errors[2202299].message }}
  • Profile picture of the author senderbot
    Hi

    Manfred - That's exactly what I am wanting to do. Although now I'm wondering if it might be just as easy to write another php script that receives the call back from paypal and then formats the email just like my sign-up form would and then passes it as a POST to my register.php?list_id=1

    Mr Enthusiastic and he others thanks for your responses.

    Mr Enthusiastic: I would be using POST as I'm simply trying to replicate what my normal autoresponder sign-up form does.

    I was just wondering (hoping) that if the e-commerce system allowed me to send a thank you email and allowed me to use masks such as <name> and <email> to insert the name and email automatically into the thank you response.... I just wondered if it may be possible to create a URL for the IPN that included something like &email=<email>

    Not sure if I'm making sense here...

    What would be easiest - a new php page that handles this - or trying to get my head around setting up a POST request.

    Cheers

    Max
    Signature
    PornStarStamina is for sale! - Buy the book rights and website! or Just Download the Book For FREE! - Check it out!
    {{ DiscussionBoard.errors[2201577].message }}
    • Profile picture of the author Mr. Enthusiastic
      Originally Posted by senderbot View Post

      Mr Enthusiastic and he others thanks for your responses.
      You're welcome!

      I was just wondering (hoping) that if the e-commerce system allowed me to send a thank you email and allowed me to use masks such as <name> and <email> to insert the name and email automatically into the thank you response
      That's up to whoever programmed the e-commerce system you're using, Max. If they provide the ability for you to pass variables into their code, then you have to use whatever mechanism they built into the system.

      If there's a support forum for that particular system, you could ask for sample code that is custom tailored to inserting names and email addresses. Since there are several technical options they might have chosen, we can continue guessing here but I'm not sure how useful that will be for you.
      {{ DiscussionBoard.errors[2203018].message }}

Trending Topics