|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Noraz Smarty Rookie
Joined: 12 Aug 2004 Posts: 13 Location: Raleigh, NC
|
Posted: Thu Aug 12, 2004 2:20 am Post subject: SmartyValidate with html_select_date |
|
|
This is my first post in a forum, ever, so hopefully this isn't too stupid. I did my best to read through all of the documentation I could find, but I'm still stumped.
Goal: Display start and end dates using html_select_date and validate end date to ensure it is on or after the start date. If end date is before start date, redisplay the form; retaining the incorrect values and supplying an error message.
Background: In the SmartyValidate Readme, I found the following code, which I tried to emmulate
Code: |
{* generate the EndDate value from EndDateYear, EndDateMonth, EndDateDay *}
{validate field="EndDate" criteria="dummyValid" transform="makeDate"}
{* generate StarDate, then compare to EndDate *}
{validate field="StartDate" criteria="isDateOnOrBefore" field2="EndDate" transform="makeDate" message="..."}
{html_select_date name="StartDate"}
{html_select_date name="EndDate"}
{* we need these two hidden form fields to hold the values generated by makeDate *}
<input type="hidden" name="StartDate">
<input type="hidden" name="EndDate">
|
So I created the following files
filter.php
[php:1:1f01df4349]<?php
$start_date = mktime(date("h"),date("i"),date("s"),date("m")-1, date("d"), date("Y"));
$end_date = mktime(date("h"),date("i"),date("s"),date("m"), date("d"), date("Y"));
$smarty->assign('startDate', $start_date);
$smarty->assign('endDate', $end_date);
if(empty($_POST)) {
SmartyValidate::register_form('filterForm', true);
$smarty->display('filter.tpl');
} else {
// validate after a POST
if(SmartyValidate::is_valid($_POST,'filterForm')) {
// no errors, done with SmartyValidate
SmartyValidate::disconnect();
$smarty->display('success.tpl');
} else {
// error, redraw the form
$smarty->assign($_POST);
$smarty->display('filter.tpl');
}
}
?>[/php:1:1f01df4349]
filter.tpl
Code: |
<form name="filterForm" method="POST" action="filter.php">
<table border=0>
{* Start Date Validations *}
{* generate the startDate value from startDateYear, startDateMonth, startDateDay *}
{validate field="startDate" criteria="dummyValid" transform="makeDate"}
<tr>
<td>{html_select_date prefix="startDate" time=$startDate}</td>
</tr>
{* End Date Validations *}
{validate form="filterForm" field="endDate" criteria="isDateOnOrAfter" field2="startDate" transform="makeDate" message="error" assign=endDateError}
{if !empty($endDateError)}
<tr>
<td>{$endDateError}</td>
</tr>
{/if}
<tr>
<td>{html_select_date prefix="endDate" time=$endDate}</td>
</tr>
<tr>
<td><input type="submit" class="formButton" value="Submit"></td>
</tr>
</table>
{* we need these two hidden form fields to hold the values generated by makeDate *}
<input type="hidden" name="startDate">
<input type="hidden" name="endDate">
</form>
|
So, everything displays just fine. However, if I do the following...
1) Select end date prior to start date
2) Submit
The page is correctly redisplayed, but I receive this Notice
Quote: |
Notice: strtotime() [function.strtotime]: Called with empty time parameter in c:\php\smarty\libs\plugins\validate_criteria.isDateOnOrAfter.php on line 22
|
and sure enough, if I do a {debug}, I see that the {$startDate} variable is empty. I'm not sure that is the cause of the notice, but I'm equally certain that it's bad.
Any suggestions as to what I'm doing wrong or a better way to go about this? All help and insight is appreciated!!
addendum: I did wonder if I needed to somehow reassign the $_POST data to the "filterForm", but I wasn't sure if that was possible or necessary. The values appear to be retained correctly, so I thought that I did it right (surely a bad assumption). |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Aug 12, 2004 2:07 pm Post subject: |
|
|
make sure you put:
form="filterForm"
on all your validation tags. |
|
Back to top |
|
Noraz Smarty Rookie
Joined: 12 Aug 2004 Posts: 13 Location: Raleigh, NC
|
Posted: Thu Aug 12, 2004 2:27 pm Post subject: |
|
|
Oh, good grief. I was scared it was something simple, well relieved actually.
Thank you so much! I see tons of answers by you in the forums. Your time and help are greatly appreciated. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|