简体   繁体   中英

How To get Gravity forms Specific field name

I want to make a forms using gravity form in this form it has a specific field which field value should match another table's field . I use gravity form filter hook to do this but it's not match & it submitted.

I want to make a forms using gravity form in this form it has a specific field which field value should match another table's field . I use gravity form filter hook to do this but it's not match & it submitted.

function my_custom_function($form_id,$field){
    if($form_id == 3 && $field->id == 4)
    {
        $input_data = $_POST['input_4'];
        global $wpdb;
        $table_name = $wpdb->prefix.'voucher_details';
        $all_voucher_lists = $wpdb->get_results( "SELECT * FROM $table_name");
         foreach ($all_voucher_lists as $voucher)
         {
             if($voucher->voucher_code!=$input_data)
             {
              echo "Not Match";
             }
             else
             {
                 echo "proceed";
             }
         }
    }

}
add_filter( 'gform_field_input_3_4', 'my_custom_function', 10, 5 )`

If you want to compare field value before form submission please check below code example.

//here _5 is form id
add_action( 'gform_pre_submission_5','ji_check_field_on_pre_submition',10,1);
function ji_check_field_on_pre_submition( $form ) {
    $input_data = rgpost( 'input_5' );
    global $wpdb;
         $table_name = $wpdb->prefix.'voucher_details';
         $all_voucher_lists = $wpdb->get_results( "SELECT * FROM $table_name");
         foreach ($all_voucher_lists as $voucher) {
             if($voucher->voucher_code!=$input_data){
              echo "Not Match";
             }
             else{
                 echo "proceed";
             }
         }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM