Hi,
Apologies for the question if it is a duplicate, but I have not been able to find a solution.
In wordpress, I am capturing the input from a form and grabbing it and sending it to a custom table like so:
add_action('gform_after_submission_1', 'add_entry_to_db', 10, 2);
function add_entry_to_db($entry, $form) {
$first_name = $entry[1]; //a normal text input & varchar field
$topic = $entry[2]; // a checkbox input with 3 options & varchar field
global $wpdb;
// add form data to custom database table
$wpdb->insert(
'zzz_customtable',
array(
'first_name' => $first_name,
topic' => $topic
)
);
}
I canβt get any input to appear in the database from the $topic variable.
Any ideas where I am going wrong?
I can get inputs from all other field types.
I donβt have any idea where you are going wrong. But when doing something custom like this, you should log everything. Be sure that logging is active on the site already for Gravity Forms Core (to log all messages.) Then add some logging statements to your code. Follow the examples here:
I recommend logging every variable or object after you think you have set the value, to be sure it contains what you expect it to. Log the entry right after you enter the function. Log the results from $wpbd->insert. Do something like this:
Hi,
So I figured this out eventually; sorry for not posting sooner.
The issue is accessing the way GF does arrays from checkbox inputs.
I discovered in the documentation that it is done like so:
$topic[β2.3β] // This accesses the third variable in the check box array.
It is important to note that this does not follow the arrays starting at 0 convention; so instead of the third variable being $topic[β2.2β], it is in fact $topic[β2.3β].