How do I enforce related dates (e.g. arrival and departure dates)?
Sometimes the correct value oof one field is dependent on the value of another field. For example, if you run a hotel, you way want to confirm that the check out date is after the check in date. You can perform this type of validation using custom rules. See the cf_terrarule tag reference for details on how to implement this form of validation. Here is an example:
The code for this example follows. The related date validation is handled by this boolean expression: "{arrivalDate} lt {departureDate}" (the values for arrivalDate and departureDate will be swapped in before the expression is evaluated). If the expression is found to be true then there will be no error. If it is false then the error will appear at the point where the terraRule tag is inserted. Note that the rule will not be evaluated at all if there is already an error for either arrivalDate or departureDate.
CFML for example <esw:terraForm
name="datesForm"
inlineerrors
alwaysDisplayForm
flagRequiredFields="false"
>
<esw:terrarule
rule = "{arrivalDate} lt {departureDate}"
error = "Please check your dates! Your departure date must be before your arrival date."
/>
<table
class="standardForm"
border="0"
cellspacing="0"
cellpadding="0"
width="100%"
>
<tr>
<th>
<esw:terraLabel for="arrivalDate"/>
</th>
<td>
<esw:terraField
name="arrivalDate"
caption="arrival date"
datatype="date"
format="datePicker"
calendar
min="#now()#"
default="#now()#"
required
/>
</td>
</tr>
<tr>
<th>
<esw:terraLabel for="departureDate"/>
</th>
<td>
<esw:terraField
name="departureDate"
caption="departure date"
datatype="date"
format="datePicker"
calendar
default="#dateAdd("d", 1, now())#"
required
/>
</td>
</tr>
<tr>
<th></th>
<td>
<esw:terraField
name="submitButton"
caption="Submit dates"
format="submit"
/>
</td>
</tr>
</table>
</esw:terraForm>