• Resolved marcorm69

    (@marcorm69)


    Hi all.

    I have add to my donation form a custom field in order to upload a file, but I can’t to validate the field.

    This code not work with input field

    function give_myprefix_validate_custom_fields( $required_fields, $form_id ) {
    	if ( $form_id == 754) {
    		$required_fields['fileUpload'] = array(
    			'error_id'      => 'invalid_give_referral',
    			'error_message' => __( 'Please tell us how you heard about Girl Develop It.', 'give' ),
    		);
    	}
    
    	return $required_fields;
    }
    
    add_filter( 'give_donation_form_required_fields', 'give_myprefix_validate_custom_fields', 10, 2 );
    

    fileUpload is a <input id=”fileToUpload” name=”fileToUpload” type=”file” accept=”.pdf,.jpg”/>

    Suggestion?

    Thanks,
    Marco

    • This topic was modified 4 years, 11 months ago by marcorm69.
Viewing 1 replies (of 1 total)
  • Thread Starter marcorm69

    (@marcorm69)

    Hi all.

    I have found a solution.
    I am using a “fake” hidden input field where I enter the name of the file to upload and validate it.

    <input type="hidden" id="filenamecheck" name="filenamecheck" value="">

    In the js script, where I check the file type and size, I move the filename in this field

    var inputElement = document.getElementById("fileToUpload")
    document.getElementById("filenamecheck").value = inputElement.value; 

    and in filter give_donation_form_required_fields I check the “fake” field.

    $required_fields['filenamecheck'] = array(
       'error_id'      => 'invalid_fileToUpload',
       'error_message' => __( 'Per favore, carica copia del bonifico bancario o del bollettino postale.', 'give' ),
    );
Viewing 1 replies (of 1 total)
  • The topic ‘Check upload file’ is closed to new replies.