This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 2

Validate Upload Field?


  1. drumaboy46
    Member

    I just wanted to know if there was a way to validate the upload field for example.

    If the file ends in .jpg have a message that says, "Are you sure you want to upload one image."

    Since the upload field does not support multiple files to one field. Currently I have instructed my users to zip the folder in order to send me all there files in one file.

    Posted 14 years ago #
  2. redityo

    It's possible with some customization. But you need to turn on "review page" option for this. To do this, you need to edit "view-functions.php" file, try to follow these steps :

    1. Go to around line 2331 ~ 2445, you'll see these code :

    $toggle = false;
    foreach ($entry_details as $data){
    	if($toggle){
    		$toggle = false;
    		$row_style = 'class="alt"';
    	}else{
    		$toggle = true;
    		$row_style = '';
    	}	
    
    	$entry_data .= "<tr {$row_style}>\n";
    	$entry_data .= "<td width=\"40%\"><strong>{$data['label']}</strong></td>\n";
    	$entry_data .= "<td width=\"60%\">".nl2br($data['value'])."</td>\n";
    	$entry_data .= "</tr>\n";
    }

    then replace the code with these one

    $toggle = false;
    $file_check = false;
    foreach ($entry_details as $data){
    	if($toggle){
    		$toggle = false;
    		$row_style = 'class="alt"';
    	}else{
    		$toggle = true;
    		$row_style = '';
    	}	
    
    	if ($data['element_type'] == 'file') {
    		if (substr(strip_tags($data['value'] ),-3) == 'jpg') {
    			$file_check = true;
    		}
    	}
    
    	$entry_data .= "<tr {$row_style}>\n";
    	$entry_data .= "<td width=\"40%\"><strong>{$data['label']}</strong></td>\n";
    	$entry_data .= "<td width=\"60%\">".nl2br($data['value'])."</td>\n";
    	$entry_data .= "</tr>\n";
    }   	
    
    if ($file_check == true) {
    	$on_confirm =  'onclick = "return confirm(\'Are you sure you want to upload one image? \'); "';
    }

    2. Go to around line 2400 for this code

    <input id="review_submit" class="button_text" type="submit" name="review_submit" value="{$lang['submit_button']}" />

    then change it to

    <input {$on_confirm} id="review_submit" class="button_text" type="submit" name="review_submit" value="{$lang['submit_button']}" />

    That would give a confirmation to "submit" button when one of uploaded file type is "jpg"


    MachForm Support

    Posted 14 years ago #

RSS feed for this topic

Reply