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

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 3

Thought I'd share: if a user needs to pick a Start Date and an End Date . . .


  1. Petermgr
    Member

    Hi,

    I sent an email to support asking the question of how I can alert a user who fills out a Start Date and an End Date, when entering an End Date that falls before the Start Date.

    One of my clients wanted to make sure that their staff could not have a form submitted if they made an error on the End Date entry. They wanted to make sure the End Date was later than the Start Date.

    While waiting for my answer from support, I thought I'd experiment and I modified my post-functions.php (in the include folder) and added the following:

    if($form_id == 13688){
        if($input['element_9_datepick'] > $input['element_42_datepick']){
        $process_result['status'] = false;
        $process_result['custom_error'] = 'Your End date must be AFTER your start date!';
        }
        }

    I placed this directly over the following:

    $element_child_lookup['address'] 	 = 5;
    		$element_child_lookup['simple_name'] = 1;

    The "element_9_datepick" is my Start Date

    The "element_42_datepick" is my End Date

    The element number was retrieved by viewing the source of my form.

    Can't be sure if my code is as clean as it could be, but so far it works.

    Peter

    Posted 11 years ago #
  2. DaveVoss
    Member

    Thanks so much for sharing a solution to a problem or a need!! I like that communal support.

    Posted 11 years ago #
  3. Saghalie
    Pro Member

    Petermgr,

    Awesome! Thanks for your input. As DaveVoss stated: "I like that communal support"

    Regards,

    Saghalie
    http://www.kcmhosting.com

    Posted 11 years ago #
  4. Petermgr
    Member

    Glad to contribute Dave and Saghalie,

    I heard back from Andar in support (their great btw!) and he suggested this code as well:

    " . . . .Or you can try with these custom code. You can add it around line 1515 above line :

    $process_result['form_redirect'] = $form_redirect;"

    Put these code :

    if($form_id == 13688){
    
                if(date('Ymd',strtotime(trim($table_data['element_9']))) > date('Ymd',strtotime(trim($table_data['element_42'])))){
                $error_elements['9'] = "Your End date must be AFTER your start date!";
                $error_elements['42'] = "Your End date must be AFTER your start date!";
                }
                }

    "That would show the highlight color on date field."

    So I tried it, and it works great! Here is a screen shot I took of the code and the warning a user receives if the Start Date is later than the End Date:

    http://img.photobucket.com/albums/v209/Peterout/MachForm/DateCompare.jpg

    Peter

    Posted 11 years ago #
  5. williamansley
    Member

    This is a great example of the value of this forum. Petermgr, I join with Dave and Saghalie in thanking you for posting your original code and the followup you received from Andar. I also agreed that Appnitro provides exceptional support.

    However, I have to state for the record that this functionality should be built into Machform; we should not have to customize the base code to have this feature, especially since we need to provide separate customization in the base code for every form in which we want this feature to work. Yuniar, I request that you please add this feature to your to-do list if it isn't there already.

    Posted 11 years ago #

RSS feed for this topic

Reply