Get a value from field

By: Thompson Fiuzzi | Asked: 11/11/2023
ForumsCategory: Code SnippetsGet a value from field
Thompson Fiuzzi asked 6 months ago

Hi everyone, I have a problem that seems simple but I can't solve it.
When I submit my form, a php script starts that sends data via API, the script works and starts for the indicated form.
Now in my php script I have to intercept the values of some fields of my form and print them in a precise point of my php script.

This is the script now and it works with plain text:

 

$smsSent = sendSMS($auth, array(
"message" => '$email' ,
"message_type" => MESSAGE_LOW_QUALITY,
"returnCredits" => false,
"recipient" => array("+393456840678"),
"sender" => null, // Place here a custom sender if desired

)); if ($smsSent->result == "OK") {
echo 'SMS sent!';
}
}}

 

Now I need to intercept the fields in my form and print
"message" => MY FORMIDABLE FIELD VALUE
"recipient" => MY FORMIDABLE FIELD VALUE Thanks to anyone who can help me

Victor Font replied 6 months ago

How are you executing the script? Which Formidable Hook are you using?

Thompson Fiuzzi replied 6 months ago

Hello and thanks for your reply.
the hook I use is

add_action('frm_after_create_entry', 'yourfunctionname', 30, 2);
function yourfunctionname($entry_id, $form_id){
if($form_id == 78){

and it works perfectly, my code is executed after the creation of my entry and only on form 78.

The code that sends data via API generates an SMS and this works fine too.

The problem is to recover the data present in the form and pass it via API to the SMS sending system.
I tried with the $_POST method and immediately after echo but it doesn't work.

This is where you should enter the value of my fields:

if (isset($_POST['submit'])) {
$your_name = $_POST [item_meta[1350]];
}

$smsSent = sendSMS($auth, array(

"message" => my formidable form value
"message_type" => MESSAGE_LOW_QUALITY,
"returnCredits" => false,
"recipient" => array(my formidable form value),
"sender" => null, // Place here a custom sender if desired
/** "scheduled_delivery_time" => date('YmdHi', strtotime("+1 minutes")), // postpone by 1 minutes */
));

if ($smsSent->result == "OK") {
echo 'SMS sent!';
}
}}

Rob LeVineRob LeVine replied 6 months ago

The information you need is accessed using the $entry_id parameter: $entry = FrmEntry::getOne($entry_id, true);

Victor Font replied 6 months ago

You’re using $_POST incorrectly. Your call to the variable should be $_POST['item_meta'][1350]. In your code you are nesting the brackets.

Thompson Fiuzzi replied 6 months ago

Thanks, you were fantastic, the problem was just how I wrote the formidable field, I had never seen fields enclosed in multiple brackets, now everything works.
THANK YOU.

Victor Font replied 6 months ago

$_POST is not a Formidable field. $_POST is a PHP associative array. That's why the multiple brackets. An associative array in PHP represents an ordered map. A map is a data form that associates keys with values.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right