Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

isDate on {html_select_date}

 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
kabatak
Smarty Rookie


Joined: 06 Mar 2004
Posts: 33

PostPosted: Fri Oct 29, 2004 9:27 pm    Post subject: isDate on {html_select_date} Reply with quote

Hi, I am using SmartyValidate Addon... Would it be possible to validate {html_select_date} using isDate? Thanks.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7366
Location: Lincoln Nebraska, USA

PostPosted: Fri Oct 29, 2004 10:17 pm    Post subject: Reply with quote

Yes, there is an example in the SmartyValidate README, read carefully.
Back to top
View user's profile Send private message Visit poster's website
kabatak
Smarty Rookie


Joined: 06 Mar 2004
Posts: 33

PostPosted: Sat Oct 30, 2004 9:23 am    Post subject: Reply with quote

I kinda got working but I am not sure if its correct. My date value is 2004-02-31 (YYYY-MM-DD) which is obviously invalid, but isDate does not return an error.

Does isDate also check if a date is actually correct or it only checks for a valid date syntax?
Back to top
View user's profile Send private message
kabatak
Smarty Rookie


Joined: 06 Mar 2004
Posts: 33

PostPosted: Sat Oct 30, 2004 6:06 pm    Post subject: Reply with quote

Okay I think that isDate does not check if a date really exist, it only checks for proper syntax.

Anyway, I have another question...
Code:
{html_select_date prefix="date" day_value_format="%02d" time="--" month_empty="--" day_empty="--" year_empty="--"}

{validate field="date" criteria="isDate" transform="makeDate" message="..."}

<input type="hidden" name="date" />


Why does the code above return an error when submitted:
Quote:
Notice: SmartyValidate: [makeDate] form field 'dateYear' is empty. in c:\program files\apache group\Apache\htdocs\site\smarty\libs\plugins\validate_transform.makeDate.php on line 22
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7366
Location: Lincoln Nebraska, USA

PostPosted: Sat Oct 30, 2004 8:13 pm    Post subject: Reply with quote

The form field "dateYear" must be empty?
Back to top
View user's profile Send private message Visit poster's website
kabatak
Smarty Rookie


Joined: 06 Mar 2004
Posts: 33

PostPosted: Sat Oct 30, 2004 8:21 pm    Post subject: Reply with quote

well from what I understood in the README...
"dateYear" along with "dateMonth" "dateDay" is suppose to be generated by using {transform="makeDate"} right?

So, in my example above I intentionally submitted an empty value for date, hence {month_empty="--" day_empty="--" year_empty="--"} generates an empty value. So when I submitted the form it's suppose to validate it, but it didn't and instead returned that error saying dateYear is empty. Is that a bug?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7366
Location: Lincoln Nebraska, USA

PostPosted: Sat Oct 30, 2004 8:47 pm    Post subject: Reply with quote

no, html_select_date creates them, makeDate uses the three values to create a date and populate the field being validated.

look at the HTML source that {html_select_date} generates, maybe that will help clear up the confusion.
Back to top
View user's profile Send private message Visit poster's website
kabatak
Smarty Rookie


Joined: 06 Mar 2004
Posts: 33

PostPosted: Sat Oct 30, 2004 9:08 pm    Post subject: Reply with quote

yeah, I understand that. I believe I am doing right. Here is my exact code:

Code:

<form action="action.php" method="post">
{validate field="date" criteria="isDate" transform="makeDate" message="..."}
{html_select_date prefix="date" day_value_format="%02d" time="--" month_empty="--" day_empty="--" year_empty="--"}
<input type="hidden" name="date" />
<input type="submit" />
</form>


It generated this:
Code:

<form action="action.php" method="post">

<select name="dateMonth">
<option label="--" value="" selected="selected">--</option>
<option label="January" value="01">January</option>
<option label="February" value="02">February</option>
<option label="March" value="03">March</option>
<option label="April" value="04">April</option>
<option label="May" value="05">May</option>
<option label="June" value="06">June</option>
<option label="July" value="07">July</option>
<option label="August" value="08">August</option>
<option label="September" value="09">September</option>
<option label="October" value="10">October</option>
<option label="November" value="11">November</option>
<option label="December" value="12">December</option>
</select>

<select name="dateDay">
<option label="--" value="" selected="selected">--</option>
<option label="01" value="01">01</option>
<option label="02" value="02">02</option>
<option label="03" value="03">03</option>
<option label="04" value="04">04</option>
<option label="05" value="05">05</option>
<option label="06" value="06">06</option>
<option label="07" value="07">07</option>
<option label="08" value="08">08</option>
<option label="09" value="09">09</option>
<option label="10" value="10">10</option>
<option label="11" value="11">11</option>
<option label="12" value="12">12</option>
<option label="13" value="13">13</option>
<option label="14" value="14">14</option>
<option label="15" value="15">15</option>
<option label="16" value="16">16</option>
<option label="17" value="17">17</option>
<option label="18" value="18">18</option>
<option label="19" value="19">19</option>
<option label="20" value="20">20</option>
<option label="21" value="21">21</option>
<option label="22" value="22">22</option>
<option label="23" value="23">23</option>
<option label="24" value="24">24</option>
<option label="25" value="25">25</option>
<option label="26" value="26">26</option>
<option label="27" value="27">27</option>
<option label="28" value="28">28</option>
<option label="29" value="29">29</option>
<option label="30" value="30">30</option>
<option label="31" value="31">31</option>
</select>

<select name="dateYear">
<option label="--" value="" selected="selected">--</option>
<option label="2004" value="2004">2004</option>
</select>

<input type="hidden" name="date" />
<input type="submit" />
</form>



Using that generated form above, I intentionally submitted an empty value by using the default selected="selected" fields. As you can see, they are empty because of value=" ".

I submitted the form and then it retured the error message:
Quote:
Notice: SmartyValidate: [makeDate] form field 'dateYear' is empty. in c:\program files\apache group\Apache\htdocs\site\smarty\libs\plugins\validate_transform.makeDate.php on line 22


But when I select a date with actual values, it works ok.
So what I am thinking. If I am correct, then makeDate is not creating/populating a new date if the values you selected for dateMonth, dateDay, and dateYear are empty. Is that true?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7366
Location: Lincoln Nebraska, USA

PostPosted: Sat Oct 30, 2004 9:33 pm    Post subject: Reply with quote

its expecting a valid date, yes. they can't be empty
Back to top
View user's profile Send private message Visit poster's website
kabatak
Smarty Rookie


Joined: 06 Mar 2004
Posts: 33

PostPosted: Sat Oct 30, 2004 9:46 pm    Post subject: Reply with quote

well, if that's the case then you can't utilize the use of "Please select date" as an initial value in your html_select_date.

I don't like html_select_date to be starting on "Jan 1, 2004" immediately.
I think it's more proper to have the initial selected value to be like "Please select a Month, etc..."

Is there a workaround on this?
Back to top
View user's profile Send private message
kabatak
Smarty Rookie


Joined: 06 Mar 2004
Posts: 33

PostPosted: Sun Oct 31, 2004 5:46 pm    Post subject: Reply with quote

Okay I managed to fixed the problem (through the help from IRC).
I removed trigger_error() in validate_transform.makeDate.php

I think its better without that because you can utilize the use years_empty, days_empty, months_empty in html_select_date
Back to top
View user's profile Send private message
grandma
Smarty n00b


Joined: 24 Nov 2004
Posts: 2

PostPosted: Thu Dec 02, 2004 11:21 am    Post subject: Reply with quote

I have a similar `problem´ with "isDate":
the date fields (generated with {html_select_date}) can be left blank, but if the user enters some values, it should be a valid date (ie not a single month value).
Therefore it would be helpfully, if the empty="yes" directive would work in conjunction with "isDate"...

Or is there another work around (aside from removing "trigger_error()")?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP