Hi!
Does anyone know of any example code to demonstrate filling in and submitting forms from PHP, I assume using Formidable_API addon, unless there are other more direct function calls that could be used from same-site ?
Example would hopefully demonstrate some or all of these:
The backstory is that a script would iterate over a folder full of text files on the server, grabbing name and age details, and submitting them to the form automatically. A one-time task to save manually re-typing 1000's of existing details into a new Formidable based server application.
Might be horribly wrong (and not yet working), but sharing what I've been playing with so far:
$api_key = '1111-2222-3333-4444';
$url = 'https://mysite.com/wp-json/frm/v2/forms/1/entries/'; // change your url
$api_parameters = [
'form_id' => 1, // entry form id
'name' => 'Bob',
'age' => '42'
];
$response = wp_remote_post( $url, array(
'method' => 'POST',
'timeout' => 45,
'headers' => array( 'Authorization' => 'Basic ' . base64_encode( $api_key .':x' ) ),
'body' => json_encode($api_parameters),
)
);
When I have a requirement to upload data like yours, I create a PHP function using the low level PHP file functions and process each line in the CSV in order. I execute the function at the bottom of functions.php. Doing this, I loaded 480 records in less than 1 second. It took about 30-minutes to write the function. You can also just do a CSV import. It seems to me the API route is overkill.
Thanks, and I agree that the API route is overkill for what I wanted. I just hadn't found the PHP instructions linked above when asking the question. Since then, having found the PHP public functions, I've written the importer function already and it was indeed simple and fabulous!
Anyone finding this later should definitely consider the PHP guide linked above!
Please login or Register to submit your answer
Ah... I might have found a path to solve this more simply...
https://formidableforms.com/knowledgebase/php-examples/#kb-create-an-entry-with-php
Somehow I couldn't find that article initially, but it does seem to be more like what I need.
Experimentation in progress!