Skip to content
Advertisement

Get php input values

My goal is to have a WordPress form that when posting, send the input to an API into an ERP.

Right now it seems that the values are empty when sending the way I do.

In CURLOPT_POSTFIELDS if instead of “$inputname” I enter something like “Martin” it works perfectly.

How can I get the value of the 4 fields I want to send? I tried $POST[‘inputname’] but same, doesn’t work.

I’m not an expert at all in php, so any tips would be appreciated! Thanks!

JavaScript

Advertisement

Answer

You should not create json manually, it would create errors if some special character are there in user inputs.

Create an array and then use json_encode to pass data in your curl. Also for POST request don’t use CUSTOMREQUEST options instead use CURLOPT_POST.

JavaScript

You can also pass data in array if api supports it. Here are options that you can use.

CURLOPT_POSTFIELDS

The full data to post in a HTTP “POST” operation. To post a file, prepend a filename with @ and use the full path. The filetype can be explicitly specified by following the filename with the type in the format ‘;type=mimetype’. This parameter can either be passed as a urlencoded string like ‘para1=val1&para2=val2&…’ or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data. As of PHP 5.2.0, value must be an array if files are passed to this option with the @ prefix. As of PHP 5.5.0, the @ prefix is deprecated and files can be sent using CURLFile. The @ prefix can be disabled for safe passing of values beginning with @ by setting the CURLOPT_SAFE_UPLOAD option to TRUE.

Finally strongly suggest you to use error check for curl so you can know what’s going wrong.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement