Using trigger fields in PHP code

Answered
0
0

Hello, all. I’m trying to create an email using data from a Participants Database database triggered from a Caldera Form. I’m almost there but can’t seem to use the trigger values in the php code:
global $wpdb;

global $wpdb;

$email = $wpdb->get_var(“SELECT email FROM jtparticipants_database WHERE id=$trigger.fields.postid”);
return $email;

What is the appropriate way to do this? postid is the slug for a hidden field in the Caldera Form. Thanks

  • You must to post comments
Best Answer
0
0

First of all, in the Execute PHP block you may use only PHP code. You may not use $trigger.fields.postid because it’s not a valid PHP syntax. That’s why your first version didn’t work the way you expected.

The correct syntax is $trigger['fields']['postid']

  • John
    Thank you. Yes, that I figured out eventually. However, I still have the strange behavior I mention below. But it is working now that I moved the field.
  • You must to post comments
0
0

This is very strange. The problem seemed to be because the hidden field was after the submit button on the form. When I moved it above the button, it worked (with the correct syntax):

global $wpdb;

$postid = $trigger[‘fields’][‘postid’];
$email = $wpdb->get_var(“SELECT email FROM jtparticipants_database WHERE id=$postid”);
return $email;

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.