Skip to main content
Answered

How to get others informations with webhook?


Forum|alt.badge.img+1
  • Sharing wisdom
  • 10 replies

Hi

I know how to get in PHP the array Answers but now I want to get some informations from this:


  "event_id": "01G0GWTNMQ5DXGX6BPPPG0DDD2",

  "event_type": "form_response",

  "form_response": {

    "form_id": "FvKcTWd8",

    "token": "v2iue2ulp9c4lvv2ic8a9wbjc3l6v59s",

    "landed_at": "2022-04-13T07:21:15Z",

    "submitted_at": "2022-04-13T07:22:26Z",

    "definition": {

      "id": "FvKcTWd8",

      "title": "Replay Webinar (TEST PBS)",

 

I tried:

 

$data = json_decode(file_get_contents('php://input'));

$infos = $data->form_response;

echo $infos->event_id;

echo $infos->form_response->definition->title;

without sucess…

Thanks

Best answer by Pako69

Hi

(excuse my bad englishn I’m French)
I solved my issue ;)

I voluntarily separate the results from the other informations to make it easier for me, so the first one is of course:

$data = json_decode(file_get_contents('php://input'));

 

But then I put my datas in two different array :

Global informations into $infos:

$infos = $data->form_response;

And the Answers into $answers:

$answers = $data->form_response->answers;

 

So to access to the data of the array global informations, I now do this:

$submitted_at = $infos->submitted_at;

$token           = $infos->token;

$autres          = 'Titre du formulaire TypeForm : '.utf8_decode($infos->definition->title).' | ';

$bu                = utf8_decode($infos->hidden->bu);

$formulaire      = utf8_decode($infos->hidden->formulaire);

 

And it works like a charm ;)

Thanks for you help!

 

View original

5 replies

Liz
Community Team
Forum|alt.badge.img+5
  • Tech Community Advocate
  • 14521 replies
  • April 13, 2022

@picsoung or @mathio do either of you happen to know? I’m not familiar with PHP. 😪


mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • 888 replies
  • April 13, 2022

Hi @Pako69 

I used to work with PHP some time ago. Can you please share your full script (how you load the data) so I can run it locally?


Forum|alt.badge.img+1
  • Author
  • Sharing wisdom
  • 10 replies
  • April 14, 2022

Here is

 

$data = json_decode(file_get_contents('php://input'));

$infos = $data->form_response;

$answers = $data->form_response->answers;

 

// THIS BELOW DO NOT RETURN ANYTHING -------------------

echo $infos->event_id.' XXX';

echo $infos->form_response->definition->title.' XXX';

// -----------------------------------------------------

 

// THE REST BELOW OF THE SCRIPT IS OK ______________


$expfile = 'testtypeform.txt';

$myfile = fopen($expfile, 'r') or die("Unable to open file!");;

$line = fgets($myfile);

if ($line = 'id Date Formulaire Raison_Sociale Civilite Nom Prenom Email Telephone Pays Objet Commentaire BU Origine') {

    $headers_set = TRUE;

}

fclose($myfile);


$myfile = fopen($expfile, "a") or die("Unable to open file!");

if (!$headers_set) {

    $headers = 'id'."\t".'Date'."\t".'Formulaire'."\t".'Raison_Sociale'."\t".'Civilite'."\t".'Nom'."\t".'Prenom'."\t".'Email'."\t".'Telephone'."\t".'Pays'."\t".'Objet'."\t".'Commentaire'."\t".'BU'."\t".'Origine'."\n\n";

    fwrite($myfile, $headers);

}

foreach ($answers as $answer) {

    switch ($answer->type) {

        case 'text':

            if ($answer->field->ref == 'prenom'):

                //echo $answer->text.' ';

                $prenom .= utf8_decode($answer->text);

            elseif ($answer->field->ref == 'nom'):

                //echo $answer->text.' ';

                $nom .= utf8_decode($answer->text);

            elseif ($answer->field->ref == 'societe'):

                //echo $answer->text.' ';

                $societe .= utf8_decode($answer->text);  

            else:

                //echo $answer->field->ref.' : ';

                //echo $answer->text.' - ';

                $autre .= utf8_decode($answer->text);    

            endif;

        break;


        case 'email':

            //echo $answer->email.' ';

            $email = $answer->email;

        break;


        case 'phone_number':

            //echo $answer->phone_number.' ';

            $telephone = $answer->phone_number;

        break;

        default:

            if ($answer->type == 'boolean'):

                //echo $answer->field->ref.' : ';

                $autres .= utf8_decode($answer->field->ref);

                switch ($answer->boolean) {

                    case TRUE:

                        //echo 'Oui ';

                        $autres .= ' Oui ';

                    break;

                    case FALSE:

                        //echo 'Non ';

                        $autres .= ' Non ';

                    break;

                }

            elseif ($answer->type == 'choice'):

                $autres .= utf8_decode(' '.$answer->field->ref).' ';

                $autres .= utf8_decode(' '.$answer->choice->label).' ';

                //echo $answer->field->ref.' : ';

                //echo $answer->choice->label.' ';

            else:

                echo $answer->text.' INCONNU ';

            endif;

    }

    $data = $prenom."\t".$nom."\t".$societe."\t".$email."\t".$telephone."\t".$autres."\r\n";

}

fwrite($myfile, $data);

fclose($myfile);


mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • 888 replies
  • April 14, 2022

Hello @Pako69 

I am looking at your code. I can see you have most likely a typo there. Given code like this:

$data = json_decode(file_get_contents('php://input'));

$infos = $data->form_response;

And you are trying to access this:

  • $infos->event_id
  • $infos->form_response->definition->title

However you should access it on $data variable like this:

  • $data->event_id
  • $data->form_response->definition->title

 

 


Forum|alt.badge.img+1
  • Author
  • Sharing wisdom
  • 10 replies
  • Answer
  • April 14, 2022

Hi

(excuse my bad englishn I’m French)
I solved my issue ;)

I voluntarily separate the results from the other informations to make it easier for me, so the first one is of course:

$data = json_decode(file_get_contents('php://input'));

 

But then I put my datas in two different array :

Global informations into $infos:

$infos = $data->form_response;

And the Answers into $answers:

$answers = $data->form_response->answers;

 

So to access to the data of the array global informations, I now do this:

$submitted_at = $infos->submitted_at;

$token           = $infos->token;

$autres          = 'Titre du formulaire TypeForm : '.utf8_decode($infos->definition->title).' | ';

$bu                = utf8_decode($infos->hidden->bu);

$formulaire      = utf8_decode($infos->hidden->formulaire);

 

And it works like a charm ;)

Thanks for you help!

 


Reply