Created
September 23, 2024 15:53
-
-
Save vfontjr/e45218e949070a4c9409d96d7c96d060 to your computer and use it in GitHub Desktop.
Source code for https://formidable-masterminds.com/easily-create-php-variables-for-every-form-field/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function create_init_field_vars_array( $form_key ) { | |
global $wpdb; | |
/* initialize the variables for the formidable tables */ | |
$wpdb_prefix = $wpdb->prefix; | |
$frm_fields = $wpdb_prefix . 'frm_fields'; | |
$form_id = FrmForm::get_id_by_key( $form_key ); | |
$new_key = str_replace('-', '_', $form_key); | |
$init_form_vars_array[$new_key] = $form_id; | |
$sql = "SELECT field_key, id FROM `{$frm_fields}` where form_id='{$form_id}' order by field_order;"; | |
$results = $wpdb->get_results( $sql ); | |
if( $results ) { | |
foreach( $results AS $field_entry ) { | |
$init_form_vars_array[$field_entry->field_key] = $field_entry->id; | |
} | |
} | |
return $init_form_vars_array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment