Form Tools
Later than a set date - Printable Version

+- Form Tools (https://forums.formtools.org)
+-- Forum: Modules / Other (https://forums.formtools.org/forumdisplay.php?fid=8)
+--- Forum: Form Validation: JS + PHP (https://forums.formtools.org/forumdisplay.php?fid=18)
+--- Thread: Later than a set date (/showthread.php?tid=355)



Later than a set date - Alexis - Nov 3rd, 2009

Hello

i would like to use the later_date, but checking that the imput date is later than a set date, different than today's date.
eg i would like to verify that inclusion date is later than nov 1st 2009

is there any way to do this ?

thanks

alexis


RE: Later than a set date - Ben - Nov 22nd, 2009

Hi Alexis,

Sure! Is this for the client-side (RSV) validation script or the PHP version?

The built-in date functionality within the RSV script isn't very strong, so what you'd need to do is write a custom function that examines the form field value(s). Let me know which script you're interested in and I'll give you a few further pointers.

- Ben


RE: Later than a set date - Alexis - Dec 2nd, 2009

I am using RSV, but can switch to php if required.

here's what i am trying to do: we use FT to include patients in a medical survey.

rules of inclusion include
- the patient can't be included before the study start date in the hospital (get the date from a database and transform to variable. date of inclusion is not date of today but 3 forms fields in the actual form.
- the patient can only be included if the date of event (3 form fields day,month,year) is 2 days later than the date of admissions (3 form fields day,month,year). both in the actual form that i want to verify

if i can do this, there are other more complicated date validations that i should be able to do

thank you

Alexis


RE: Later than a set date - Ben - Dec 12th, 2009

Hey Alexis,

Thanks for the reminder about this post.

So! Here's some very general pointers on how to do this for the JS RSV script. Since the built-in date validation code is pretty basic, we're going to bypass it altogether and write a custom function to do the validation for us. First, add a new rule to your rule list: this will call your custom function.

Code:
rules.push("function,check_date");

Next, as you described in your post, the check_date() function needs to do a couple of things. I wasn't completely sure about the rules you need to check for, but here's an example of how it would look:

Code:
function check_date() {
  // this bit would be generated server-side. This example assumes you're using PHP and the
  // date is in yyyy-mm-dd format.
  var study_date_start = "<?=$study_date_start?>";

  // 1. find the form fields that contain the dates.

  // 2. do whatever tests you want. You'd no doubt compare it with the value in study_date_start

  // 3. if there are errors, return a variable like this - where problem_field is a reference to
  // the form field that has a problem (e.g. document.getElementById("field1") )
  // return [[problem_field, "your error message"]];

  // if there are no error messages, return true:
  return true;
}

That's the gist of it... the validation logic will be the next bit to sort out. Basically you'd need to extract & compare the various dates and do the math on them.

Sorry I'm being so general, but hopefully this gives you some idea of how to proceed - at least how to plug it into the main validation control flow.

- Ben


RE: Later than a set date - Susan W - Aug 31st, 2020

Thank you for the information about the Linux operating system that would be really wise. The people who need help with fixing the applications they can get the best help. I truly like college paper reviews update and really admire your trusted material here as well.