0

In my ninja form , I have required field . But I want to change that required attribute if the user is not logged in . I have seen ninja form documentaion and tried as they say . Here is what I have tried .

function my_filter_function( $data, $field_id ){

  if(!is_user_logged_in()){  
    if( $field_id == 135){
      $data['req'] =0;
    }
  return $data;
  }
}
add_filter( 'ninja_forms_field', 'my_filter_function', 10, 2 );

But it doesn't work . When I submit the form it says that field is required .

1 Answer 1

0

Finally I have found a way to accomplish this , The solution to problem is to call update the field setting function

function ninja_forms_change_required_field(){
  add_action( 'ninja_forms_before_pre_process', 'ninja_forms_code' );
}
add_action( 'init', 'ninja_forms_change_required_field' );
function ninja_forms_code(){
  global $ninja_forms_processing;
  if(!is_user_logged_in()){
        $data['req'] = '0';
        $ninja_forms_processing->update_field_settings(135, $data);
  }
}

If a field is required then then $data['req'] = '1'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.