Search code examples
phpwordpressgravity-forms-plugin

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 )`

Solution

  • 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";
                 }
             }
    }