• Resolved ufo4976

    (@ufo4976)


    Hello,
    I’m using the “front-end-pm” wordpress plugin and I would like to get the upload file required. I tried to edit the front-end-pm/includes/class-fep-form.php with the plugin editor and required the “fep_upload” but it’s not working (it displayed “required” but adding a picture is not working). I know thats an option function but I would like to get ‘required’ => true.

    I’m not experimented in coding so i’m asking you.
    Regards.
    Alexandre

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Shamim Hasan

    (@shamim51)

    if your php version 5.3+, add following code in your theme’s (child theme’s if any) functions.php (untested)

    
    add_filter( 'fep_form_fields', function($fields){
    
        $fields['fep_upload']['required'] = true;
        return $fields;
    });
    

    Let me know.

    Thread Starter ufo4976

    (@ufo4976)

    Hello again,

    Thanks for your help but unfortunately it doesn’t work. The “required” message appear when I don’t upload something (which is what I want), but when I upload something the message can’t be send (it keeps asking for “required” even if “Invalid Token. Please try again!” has successfully disappear).

    • This reply was modified 7 years, 10 months ago by ufo4976.
    Plugin Author Shamim Hasan

    (@shamim51)

    Please remove previously given code and add following code in your theme’s (child theme’s if any) functions.php

    
    add_action( 'fep_action_validate_form', function( $where, $errors, $fields ){
    
        if( ! in_array( $where, array( 'newmessage', 'reply' ) ) || ! fep_get_option('allow_attachment', 1) )
    		return;
    	
    	$count = (int) fep_get_option('attachment_no', 4);
    	$empty = true;
    	
    	for ($i = 0; $i < $count; $i++) {
    		
    		if( isset( $_FILES['fep_upload']['error'][$i] ) && empty( $_FILES['fep_upload']['error'][$i] ) ){
    			$empty = false;
    			break;
    		}
    		
    	}
    	
    	if( $empty ){
    		$errors->add( 'fep_upload' , __('Attachment required.', "front-end-pm") );
    	}
    	
    }, 10, 3);
    
    Thread Starter ufo4976

    (@ufo4976)

    Thanks a lot, it worked perfectly. Great support !

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Required upload’ is closed to new replies.