PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Bug: gform_pre_render > isRequired does not work for fileupload fields

  1. dotcom
    Member

    Gravity forms is unable to modify the required status of a fileupload field.

    Test A:
    All fileupload fields were set to required in the form editor. The pre_render was user to set all fileuploads to:
    $field['isRequired'] = 0;

    result > the fields were still required

    Test B:
    All fileupload fields were set to default (un-required) in the form editor. The pre_render was user to set all fileuploads to:
    $field['isRequired'] = 1;

    result > the fields were still not required (Although an asterisk did appear on the form).

    Sample code:

    add_filter( "gform_pre_render", 'gfpr_populate_by_lead' );
    function gfpr_populate_by_lead( $form ) {
    
        foreach ( $form['fields'] as &$field ) {
    
            switch ( $field['type'] ) {
    
            case 'fileupload':
    
    		$field['isRequired'] = 1;
    
                break;
    
            default:
    
        }
    
    return $form;
    }

    Could you confirm this bug? Perhaps there is an alternative function to achieve the same result?

    Posted 13 years ago on Sunday October 23, 2011 | Permalink
  2. Which version of the plugin are you using?

    Posted 13 years ago on Monday October 24, 2011 | Permalink
  3. The problem is that the gform_pre_render fires after the form validation takes place, so you can't use it to change the validation behavior. I wouldn't call it a bug, but I do agree that not being able to mark a field as required in that filter is counter-intuitive. I will be looking at ways to improve this.
    For now, you can use a combination of the gform_pre_render filter and the gform_field_validation filter to accomplish what you need. Following is a code snippet.
    http://pastie.org/2751185

    Note that gform_field_validation is new in 1.6. If you are not using that version and do not want to upgrade, you will need to use the gform_validation filter. Following is it's documentation.
    http://www.gravityhelp.com/documentation/page/Gform_validation

    Posted 13 years ago on Monday October 24, 2011 | Permalink
  4. dotcom
    Member

    Thank you Alex for the superb reply.

    We're using v1.5.2.8 - as we have done extensive customisations the upgrade is in the pipeline but not possible at the minute.

    Have attempted to write the function using Gform_validation but really struggling: http://www.pastie.org/private/lfr5pyunl9acted3bpocw

    Could you help me out with this?

    Posted 13 years ago on Monday October 24, 2011 | Permalink
  5. I will be glad to help. Is this a multi-page or a single-page form? If it is a multi-page form, it would be helpful if you exported the form (Forms->Import/Export->Export form) and pasted a link to the exported XML file.

    Posted 13 years ago on Tuesday October 25, 2011 | Permalink