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

Restrict Dates


  1. gilman01
    Member

    Anyone know how I might restrict a user from selecting a date prior to the current date? I have created an appointment form but I do not want to allow someone to select a date prior to the current date they fill out the form.

    Any suggestions would be greatly appreciated.

    Posted 13 years ago #
  2. yuniar

    I'm afraid there no easy way to do this with current version of MachForm.
    However, if you don't mind with some PHP customization, it is possible to restrict the dates.

    Your users will still be able to select any date when filling the form. However, when the form being submitted, it will check the date being entered and display error message if the selected date is a date prior to the current date.

    Is that okay for you? If so, I can provide you with the code for this.


    MachForm Founder

    Posted 13 years ago #
  3. alfonso
    Member

    I'm also interesting to do the same. Thanks

    Posted 13 years ago #
  4. redityo

    You can try to follow these steps for the customization, edit "includes/post-functions.php" file and go to line 720 for these code :

    $validation_result = validate_element($target_input,$rules);
    
    if($validation_result !== true){
    	$error_elements[$element_id] = $validation_result;
    }

    then put these code bellow that line

    if (!empty($target_input['element_date'])) {
    	if($form_id == 16 && $element_id == 1){
    
    		$selected_date = date('Ymd',strtotime($target_input['element_date']));
    		$today_date = date('Ymd');
    
    		if($selected_date <  $today_date){
    			$error_elements[$element_id] = "Can not select previous date";
    		}
    	}
    }

    in there I assume your form id is 16 with date element id 1. Don't forget to change those id's with yours.


    MachForm Support

    Posted 13 years ago #
  5. alfonso
    Member

    Thanks. Don't work. I don't know if may be date format. I have spanish DD/MM/YYYY when create form

    Posted 13 years ago #
  6. redityo

    Are you sure you have put the form and element id correctly ?
    or could you post your form url and code in here ? otherwise, you can send it to this email address

    customer.service [at] appnitro.com

    I will help you to check it


    MachForm Support

    Posted 13 years ago #
  7. petercamburn
    Member

    I would like to do something very similar, except I would like to block dates starting 2 days from the current date.

    So if today is November 10, they can only select dates November 13 and later.

    Can you help?

    Posted 13 years ago #

RSS feed for this topic

Reply