0

I've created a form (using WS FORM RUN WORDPRESS HOOK) than when submitted triggers a php script that grabs all the submitted data written on the fields and save them into $variables and everything goes as follows :

  1. Form is sent
  2. PHP grab everything and put it into an array
  3. PHP JSON everything
  4. PHP send to an endpoint
  5. The endpoint return something

To be able to debug everything i would like to be able to READ what the endpoint is returning.

After lot of research (new to PHP) i've found that i could put the return into an $response and use file_put_contents($file_path, $response).

Problem is that it's not working ...

I've went at the top of my script to test the function on a simple variable to make sure that the problem was not coming from a syntax error or something like that.

Here is what i've written so far :

  • $file_path = '/wp-content/custom-scripts/sortie.txt';
  • file_put_contents($file_path, $regionaler_zusatz, FILE_APPEND);

$regionaler_zusatz is just a field of the form.

'sortie.txt' is a file i've created using Filezilla.

Does anybody knows what's wrong ? Maybe should i try another approach ?


Regarding the returned output on each steps of the PHP script

Basically the project is linking a form to a CRM.

The CRM is gathering leads, and as it's a CRM for Real estate, buyers are able to register some searching criteria saying "i'm looking for a flat between $100K and $500K, in this neighborhood, etc..." and when the real estate agency register a flat that match those criterias the CRM automatically send an email to those who have registered criterias that match the new flat.

It goes as follows :

  1. People submit the form
  2. PHP grabs everything to FIRST check if the email already exist inside the CRM database, so the first return is supposed to either be "email exist" or "email does not exist" (i'll put an example below)
  3. If it exists, inside the return it will give me a unique ID that is attributed to anybody that exists inside the CRM, I put this ID inside a variable to create a second JSON to send a second request using this ID
  4. If it does not exists it simply says it and i'll send firstly a request to create the address first then grab the returned ID that is linked to this email and continue the script
  5. It send the last request grabbing the ID
  6. The last return is either "success" or "error" following with error code

Here are two example of returns : (If the way i'm giving details is not a good way to do so the best think i can do is providing the link to the API documentation : The following linke point to how the CRM is responding to the point 3. of the above explanation : https://apidoc.onoffice.de/actions/datensatz-anlegen/adressen/)

1 - For address creation :

"response":{
"results":[
    {
        "actionid":"urn:onoffice-de-ns:smart:2.5:smartml:action:create",
        "resourceid":"",
        "resourcetype":"address",
        "identifier":"",
        "data":{
            "meta":{
                "cntabsolute":null
            },
            "records":[
                {
                    "id":181,
                    "type":"address",
                    "elements":[
                    ]
                }
            ]
        },
        "status":{
            "errorcode":0,
            "message":"OK"
        }
    }
]

}

And regarding the return of when the address ID is known and i send the last request which is basically saying "attribute the form content to $ID", unfortunately i have no example but i can only provide you a link of the documentation here because they don't give an example for this specific case but just talk about the structure of the API response (the following link point to the structure of responses in general) : https://apidoc.onoffice.de/onoffice-api-response/aufbau/

2
  • It's not possible to know anything about the endpoint. What is this endpoint that you're sending the form data to? What does it return? Jan 11 at 17:21
  • Hey @JacobPeattie, i'm new to this platform too so i firstly answered inside the comment before understanding it's not the way to do it, so i've edited my main message and added all the info you requested
    – WinterCold
    Jan 14 at 11:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.