What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    Webhook: Unable to Fetch POST Data from Form Fields

    Asked by urgentcarekids on December 29, 2014 at 05:05 PM

    I'm using the webhooks plugin as well as using a simple php script set up at the webhook endpoint to email some of the form data but the form data is not coming through, here is the script I am using 

     

    <?php

    //Sample Webhook Instant Notification

     

    //json to php

    $result = $_REQUEST['rawRequest'];

    $obj = json_decode($result, true);

     

     

    //**Note, the following code will use your default smtp host for sending emails

    //So make sure your host support this, otherwise this may not work.

     

    //Change the emails 

    $emailfrom = "noreply@jotforms.com"; //Sender, replace with your email

    $emailto = "jesse@reapmarketing.com"; //Recipient, replace with receivers email

    $subject = "JotForm Test Webhook"; //Email Subject

     

    //Prepare email body text, you can change anything from here

    $body = "Contact Form Submissions"; //Title

    $body .= "\n";  //Nothing but new line

    //$body .= "Name: ". var_dump($result); //Replace with your Name field name

    $body .= "\n";

    $body .= "Email: ". $obj['q5_primaryPhone5[full]']; //Replace with your Email field name

    $body .= "\n";

    //$body .= "Message: ". $obj['q4_message'];

    $body .= "n";

    $body .= "Submissions ID: ". $_POST['submissionID']; //If you'd like to catch submissionsID

     

    //Send email

    mail($emailto, $subject, $body, "From: <$emailfrom>");

    ?>

     

     

    Please advise.

    Page URL:
    http://form.jotform.us/form/42575046802151

    form data Emails contact form Submissions webhooks
  • Profile Image

    Answered by Ben on December 29, 2014 at 06:03 PM

    Hi,

    It is most likely this line:

    $emailfrom = "noreply@jotforms.com"; //Sender, replace with your email

    What you are currently doing is trying to send an email from your server as if it was sent from our servers. For this reason the email will get bounced back or just deleted by all better email providers and email setups.

    What you should do is replace that part with your own email address, preferably one that is on the same domain from which you are sending an email from.

    example:

    if your domain was mydomain.com the email would be best to be someaccount@mydomain.com in order to be sent and properly received by the people you send it to.

    Do let us know if you have any further questions.

    Best Regards,
    Ben

  • Profile Image

    Answered by urgentcarekids on December 29, 2014 at 06:07 PM

    I have changed that email to my email, it still does not give me any data back. Let me be clear, the Webhook is sending to the script however it is simply not including any of the form data. Please advise.

  • Profile Image
    JotForm Support

    Answered by Charlie on December 29, 2014 at 10:06 PM

    Hi,

    Upon checking your account and tested in my end using a cloned form, I was able to replicate the problem.

    1. First, I followed the guide that we have here: http://www.jotform.com/help/245-How-to-Setup-Webhook-with-JotForm

    2. I then used the instant email notification PHP script on the example given, http://pastiebin.com/53cc7a94be25f

    3. I changed the necessary fields and get the correct form field names and ID using http://requestb.in/

    4. Unfortunately, after submitting sample submissions, I'm unable to fetch the data in my form fields.

    Here's a part of my PHP script:

    $subject = "JotForm Test Webhook".$obj["q5_primaryPhone5"]; //Email Subject

    $body = "Contact Form Submissions".$obj['q247_fullName247']; //Title

    $body .= "\n";

    $body .= "Email: ".$obj['q250_emailAddress']; //Replace with your Email field name

    POST data should show in the body of my email, but only shows blank.

    I will escalate this to our developers so that they can take a closer look on this bug. For the meantime, you can try a direct method of sending POST data using this guide that we have: Send POST Data Using PHP in Custom Thank You Page.

    Apologies for the inconvenience, we will update you immediately when a fix has been made.

    Thank you.

  • Profile Image

    Answered by John on January 02, 2015 at 07:26 PM

    Hi,

    I looked at $_REQUEST['rawRequest'] data and  i noticed that it contains slashes before double quote.

    So json_decode function does not work properly. To prevent that you can add green line to your script. Script should looks like below

     

    $result = $_REQUEST['rawRequest'];

    $result = stripslashes($result);

    $obj = json_decode($result, true);

     

    Do let us know if you have any further questions.

    Thank you.

     

  • Profile Image

    Answered by urgentcarekids on January 05, 2015 at 11:12 AM

    I added this line

    $result = stripslashes($result);

    And it did not fix the issue. Please advise.

  • Profile Image
    JotForm Support

    Answered by Charlie on January 05, 2015 at 12:26 PM

    Thank you for updating us. Our developers and the back end team looking at this issue are being updated with the information you are sharing. This will help us further in finding the culprit to this problem.

  • Profile Image

    Answered by John on January 05, 2015 at 04:24 PM

    Hi,

    1. First , i cloned your Cedar Park - Online Check-In Form and add webhook integration like below.

    2. Then, i fill webhook.php script on the example given, http://pastiebin.com/54aaf55159642

    3. After testing clone form, i recived email like this: 

    Note:

    1. You can use http://requestb.in/ to get the correct form field names.

    2. Do not use var_dump or print. You can not assign variable with them. Maybe your script didnt work because of it.

    3. if all of these wont help you. Please send me last version of your script.

     

    Thank You.

  • Profile Image

    Answered by urgentcarekids on January 06, 2015 at 01:39 PM

    Using the form data is crucial, it is the whole reason that I want to use this web hook. Is there a way to assign the form values to variables in a script?

  • Profile Image

    Answered by Ben on January 06, 2015 at 02:18 PM

    Hi,

    Using the form data is crucial, it is the whole reason that I want to use this web hook.

    I am sorry, but I am not quite sure if I understand what you mean.

    If you take a look at the code given by my colleague John above: http://pastiebin.com/54aaf55159642 you will see as per his email that you will collect the data using that code.

    Now I presume that you have said that because John mentioned that you should not use var_dump?

    If so please note that var_dump and its alternatives are only good for showing you the data when you are on the page - it prints it out.

    When you are using webhooks that is not needed since it will only output it to the console, but never use to send an email or anything like that.

    I would also like to point out that the position where you place $result = stripslashes($result); is very important as well. It must be placed before the actual json_decode function.

    Is there a way to assign the form values to variables in a script?

    I will copy part of the script my colleague has given, which shows you how you can assign submitted values to variables:

    $result = $_REQUEST['rawRequest'];
    $body .= "Name: ". implode(' ', $obj['q247_fullName247']);
    $body .= "Email: ". $obj['q250_emailAddress'];
    $body .= "Reason for Visit: ". $obj['q277_reasonFor'];

    You can always break it up and add something like:

    $reasonForVisit = $obj['q277_reasonFor'];
    $email = $obj['q250_emailAddress'];

    which would then be used as:

    $body .= "Email: ". $email;
    $body .= "Reason for Visit: ". $reasonForVisit;

    If you are finding it difficult setting up the webhook, you could set different email templates to be sent to different people by following these steps:

    Setting Up Email Notifications

    How to send to a specific email address based on a selection?

    Send Notifications to Multiple Recipients

    Best Regards,
    Ben

  • Profile Image

    Answered by urgentcarekids on January 06, 2015 at 06:38 PM

    OK, thank you for clarifying. And may I ask, on my current form named "Cedar Park Check In Form" how would I access the primary phone number field, I tried to use $obj['q281_primaryPhone'] but it returns a null value?

  • Profile Image
    JotForm Support

    Answered by Charlie on January 06, 2015 at 09:08 PM

    Hi,

    You could try using the implode function same with the full name field:

    $body .= "Phone Number: ".implode('', $obj["q281_primaryPhone"]);

    It's an array so the implode function will convert it to a single string line.

    Let us know if this works.

    Thank you.

  • Profile Image

    Answered by urgentcarekids on January 07, 2015 at 11:36 AM

    Thanks for the suggestion,

    I tried using the implode function and it is still coming up with a null value, it is almost as if the form value q281_primaryPhone is empty?

  • Profile Image
    JotForm Support

    Answered by Charlie on January 07, 2015 at 12:56 PM

    Hi,

    I'm not sure where the problem though, here's my screenshot of my code using my own form.

    And this is the email that I get:

     

    You might have misplaced a ";" in your code or if you added a space in your implode function that might be causing the problem. Can you share us a screenshot or a copy of your edited code?

    We'll wait for your response.

    Thank you.

  • Profile Image

    Answered by urgentcarekids on January 07, 2015 at 01:01 PM

    This is the line I am using to get the value

     $customerPhone = implode('', $obj["q281_primaryPhone"]);

    When I try to use that variable it is empty.

  • Profile Image
    JotForm Support

    Answered by david on January 07, 2015 at 02:51 PM

    Hi,

    Could you please provide us with your full current modified script?  It will be much easier to see what the problem is on a whole since it appears your code is now different from the original post.

  • Profile Image

    Answered by urgentcarekids on January 07, 2015 at 04:29 PM

    Here is the code as it stands

     

    $customerPhone = implode('', $obj["q281_primaryPhone"]);

        $customerName = implode('', $obj['q241_fullName']);

     

        

        $token = "?token=V5E6dEyuv4nw3HFD98fUF6N8rQWhX3";

     

        

        $parameters = $token . "&name=" . $customerName . "&phone=" . $customerPhone . "&size=1";

     

        

        $emailfrom = "admin@urgentcarekids.com"; //Sender, replace with your email

        $emailto = "jesse@reapmarketing.com"; //Recipient, replace with receivers email

        $subject = "JotForm Test Webhook"; //Email Subject

     

     

    //Send email

    mail($emailto, $subject, $parameters, "From: <$emailfrom>");

  • Profile Image

    Answered by Ben on January 07, 2015 at 06:01 PM

    Hi,

    From the code that you have given it seems that you are using the webhook to create some kind of parameters?

    I am not quite sure what you are looking to achieve, but the issue might be caused by the ? at the start of the parameters.

    To answer you I have created this pastebin: http://pastebin.com/rqSgfmJM

    Please take a look at it.

    I have added your part to the first segment, then the working code in the middle and at the end your modified code with the required pieces of code.

    For future reference, it might be best to upload the code to pastebin or some other similar thread so that no code is lost when you post it on our forum and makes it easier to follow up.

    Best Regards,
    Ben

  • Profile Image

    Answered by urgentcarekids on January 07, 2015 at 06:24 PM

    Eventually those parameters will be used in a cURL of another web service, I am simply emailing that string to myself to ensure it's accuracy. 

    This is my full code http://pastebin.com/0AxXPkLi

  • Profile Image

    Answered by urgentcarekids on January 07, 2015 at 11:10 PM

    But again, that code in the paste bin, identical to yours that you posted, does not work. It returns no value for the phone number.

  • Profile Image

    Answered by John on January 08, 2015 at 01:58 AM

    Hi,

    In my cloned form, there are 2 phone field. and their field names are q5_primaryPhone5 and q237_alternatePhone237. Probably this is the reason why you get null phone number.

    I think, If you use green line instead of yellow, your problem will be solved.

    $customerPhone = implode('', $obj["q281_primaryPhone"]);   

    $customerPhone = implode('', $obj["q5_primaryPhone5"]);

    We'll wait for your response.

     

    Thank you.

  • Profile Image

    Answered by urgentcarekids on January 08, 2015 at 11:07 AM

    Nope, still comes through as a null value. Are you able to test any of these scripts you are writing with my form "Cedar Park - Online check in form" successfully?

  • Profile Image
    JotForm Support

    Answered by Charlie on January 08, 2015 at 11:48 AM

    Hi,

    Upon checking your form and my form. It seems that we have a different field type, have you edited yours?

    Below is the earlier cloned form that I have, it seems that the Primary Phone field is a plain text box with an input mask enabled on it.

    While this is the new cloned form that I have with yours, I cloned it just now. And it seems that it is now a number field? Because the upper menu shows "max size", validation, etc... Is this correct?

    I've also checked the forms via inspecting their element. Below is the first cloned form that I have, the form field name is q5_primaryPhone5[full], you'll noticed that this is the same form field that I have in my code in my earlier post in this thread, you'll noticed the [full] at the end, it is an indication that my field value will be in an array format, this might be because of the input masked on it and being in a plain text box.

    Below is your form http://form.jotform.us/form/42575046802151, I've inspected its element. You'll notice that the form field name is q281_primaryPhone, it also has a masked setting on it but doesn't have the word [full] at the end, this is an indication that the value will be in one string only and not an array. With this we DO NOT need an implode function, because the values are not separated by anything, unlike the plain Text Box in my first cloned form, I believe it became an array because of the Input Mask On and it is not a Number Field.

     

    I've cloned your form and this is the new form that I set up: http://www.jotform.com/form/50073997884976. You can inspect the element by just right clicking on them and see their field name.

    Below is my new code, I've created a variable named $customerPhone and assigned it's value by using $obj["q281_primaryPhone281"], you'll see that we don't need to use implode here because based from our inspected element it doesn't have a [full] on it, so we're guessing it's not an array but a one line of string only.

    I've tested my form and I got this notification:

     

    Can you please check again and inspect the elements that you have and see if we might have missed something.

    We'll wait for your response.

    Thank you.

     

  • Profile Image

    Answered by urgentcarekids on January 08, 2015 at 12:11 PM

    Thanks so much! That was it, no implode function needed as the field was a text field. You guys have been awesome, thank you so much for being so patient! 

  • Profile Image
    JotForm Support

    Answered by Charlie on January 08, 2015 at 12:48 PM

    You're most welcome. And thank you also for your cooperation and patience, I know it might be frustrating when we're trying to look for the cause of the problem and we can't find it immediately. Nevertheless, everything is now working as expected.

    If you need an assistance again or have any other concerns, feel free to open up a new thread here in the forum, we'll be more than happy to help you.

    Kind regards.