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

I need a 'Birth Date' control


  1. jvandenbussche
    Member

    I need a way to have three drop downs (month, date, year) so that someone enters their birthdate. This is for a contest entry form. In addition, I need to prevent someone under a certain age from submitting the form (i.e. 13 years of age). To that end, I would like to populate the year drop down with options that disallow anyone under 13 from entering (meaning 2008, 2007, 2006, etc. would not appear). Any ideas? My boss uses this application, so I don't have the option of telling him to use something else.

    Posted 15 years ago #
  2. redityo

    Hi,

    I think you can add a calendar (date) field instead, with new validation to give error if someone under 13 years old submit the form.
    To do so, let say you have a date field with element id = 1 in form 1, then try to follow these steps :

    1. Edit "common-validator.php" file and go around line 28, you will see this code :

    define('VAL_FILETYPE',$lang['val_filetype']);

    exactly bellow that line, you can add this

    function validate_difference_date($value){
    	$value = $value[0];
    
    	if(!empty($value)){
    		$temp_date = explode('-',$value);
    
    		$date1 = time();  // get today time
    		$date2 = mktime(0,0,0,$temp_date[1],$temp_date[2],$temp_date[0]);
    		$date_diff = $date1 - $date2;
    		$full_days = floor($date_diff/(60*60*24) );
    		$diff_year = round($full_days / 356); 
    
    		//change the condition to set another minimum age
    		if ($diff_year < 13)
    			return 'This form only for 13+ years old';
    		else
    			return true;
    	}else{
    		return VAL_REQUIRED;
    	}
    }

    2. Edit 'includes/post-functions.php" and go around line 692, you will see this :

    $validation_result = validate_element($target_input,$rules);

    put these code exactly above that line

    if ($element_id == '1' && $form_id == '1') {
    	$rules['element_date']['difference_date'] = $target_input['element_date'] ;
    }

    MachForm Support

    Posted 15 years ago #
  3. caseybecking
    Member

    as much as i can see this should be working it isnt. Any ideas?

    Posted 15 years ago #
  4. caseybecking
    Member

    yeah looking at it closer you have an error in your math somewhere diff_year becomes 1 . Ill dig deeper

    Posted 15 years ago #
  5. caseybecking
    Member

    if ($diff_year < 18)
    needs to go like that. Correct?

    Posted 15 years ago #
  6. yuniar

    Ah, yes .. you got it correct. I've fixed the above code.
    Thanks for letting us know!


    MachForm Founder

    Posted 15 years ago #

RSS feed for this topic

Reply