PHP Classes

Form_Date_Class usage

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  Upcoming Visual HTML ...  >  All threads  >  Form_Date_Class usage  >  (Un) Subscribe thread alerts  
Subject:Form_Date_Class usage
Summary:Getting errors or a blank page with Smarty
Messages:8
Author:Form Class
Date:2007-03-23 22:23:42
Update:2007-03-27 01:37:56
 

  1. Form_Date_Class usage   Reply   Report abuse  
Picture of Form Class Form Class - 2007-03-23 22:23:42
Manuel,

I'm trying to use the form_date_class for the first time along with Smarty but facing some issues. I get invalid input 'p_date_year', 'p_date_month' etc errors and the input would not render in the page except for the ' / / ' separators. I've also tried adding the code from test_date_input.php to the test_smarty_form.php as under but the page comes out blank:

require("form_date.php");
$day_seconds=60*60*24;
$start_date=strftime("%Y-%m-%d",time()+1*$day_seconds);
$end_date=strftime("%Y-%m-%d",time()+7*$day_seconds);
$form->AddInput(array(
"TYPE"=>"custom",
"ID"=>"date",
"LABEL"=>"<u>D</u>ate",
"ACCESSKEY"=>"D",
"CustomClass"=>"form_date_class",
"VALUE"=>strftime("%Y-%m-%d"),
"Format"=>"{day}/{month}/{year}",
"Months"=>array(
"01"=>"January",
"02"=>"February",
"03"=>"March",
"04"=>"April",
"05"=>"May",
"06"=>"June",
"07"=>"July",
"08"=>"August",
"09"=>"September",
"10"=>"October",
"11"=>"November",
"12"=>"December"
),
"Optional"=>1,
"ValidationStartDate"=>$start_date,
"ValidationStartDateErrorMessage"=>"It was specified a schedule date before the start date.",
"ValidationEndDate"=>$end_date,
"ValidationEndDateErrorMessage"=>"It was specified a schedule date after the end date.",
));


FORM.TPL
--------
<tr>
<th align="right">{label for="date"}:</th>
<td>{input name="date"}</td>
<td>{$mark}</td>
{/if}
</tr>


I've also tried using inputs names such as p_date_year, p_date_month, etc. but in vain :(

Please help...

TIA

  2. Re: Form_Date_Class usage   Reply   Report abuse  
Picture of Tarak Blah Tarak Blah - 2007-03-23 23:43:43 - In reply to message 1 from Form Class
I'm using this to ask for user's birthdays. Users need to be 18 years old at least.

//user_registration_form.php
require("forms.php");
require("form_date.php");
...
$months = array(
"01"=>"January",
"02"=>"February",
"03"=>"March",
"04"=>"April",
"05"=>"May",
"06"=>"June",
"07"=>"July",
"08"=>"August",
"09"=>"September",
"10"=>"October",
"11"=>"November",
"12"=>"December"
);
$dateStart = mktime(0, 0, 0, date("m"), date("d"), date("Y")-99);
$dateStop = mktime(0, 0, 0, date("m"), date("d"), date("Y")-18);
$start_date = strftime("%Y-%m-%d",$dateStart);
$end_date = strftime("%Y-%m-%d",$dateStop);
$form->AddInput(array(
"TYPE" => "custom",
"ID" => "Birthday",
"LABEL" => "Birthday",
"LabelCLASS" => "Labels",
"LabelID" => "LabelBirthday",
"LabelTITLE" => "Please tell us when you were born.",
"CustomClass" => "form_date_class",
"VALUE" => strftime("%Y-%m-%d",$dateStop+(60*60*24)),
"Format" => "{day}{month}{year}",
"Months" => $months,
"Optional" => false,
"SelectYears" => 100,
"TABINDEX" => 3,
"TITLE" => "Please tell us when you were born.",
"ValidationStartDate" => $start_date,
"ValidationStartDateErrorMessage" => "Sorry, you are way too old!",
"ValidationEndDate" => $end_date,
"ValidationEndDateErrorMessage" => "Sorry, you are too young!",
));
...

//user_registration_template.php
...
<tr>
<td class="LabelsTD">
<?php $form->AddLabelPart(array("FOR"=>"Birthday")); echo "\n"; ?>
</td>
<td class="InputsTD">
<?php $form->AddInputPart("Birthday"); echo "\n"; ?>
</td>
</tr>
...

The VALUE-string is set to the birthday of people who are getting 18 tomorrow. Meaning that if today would be the 12.03.2007, the 3 select-fields would show "13" "March" "1989". This way people need to set a specific date which validate their age. What I miss in your code is the "SelectYears"-string. And in my example all of this is not optional, as in your example. Note the opposite of the ValidationStart- and ValidationEndDateErrorMessage!!! And the ValidationStartDate can be ommited in my code, but I found it funny to keep. This works perfectly. I'm just not working with Smarty... But looking over your code, {/if} seems to be an ending tag for something, there surely need to be something like a start-tag? As said, I haven't used Smarty yet... And if this is a stupid and unqualified answer, blame me... but not too hard! :-)

Tarak

P.S.: I'm not using this for adult-content-things, so please...

  3. Re: Form_Date_Class usage   Reply   Report abuse  
Picture of Tarak Blah Tarak Blah - 2007-03-23 23:57:20 - In reply to message 2 from Tarak Blah
Another thing I'm thinking about: You have addressed your question to Mr. Lemos himself... I don't want to criticise you, but I think that Manuel should not be the only one answering questions here. This seems like a huge community to me. So others should answer too, if they can. I think that Manuel is as busy as all of us. As said, I don't want to criticise anyone...

Tarak

  4. Re: Form_Date_Class usage   Reply   Report abuse  
Picture of Form Class Form Class - 2007-03-24 08:16:17 - In reply to message 2 from Tarak Blah
Hi,

Thanks for the reply. That did not help. Here is my input:

$months = array(
"01"=>"January",
"02"=>"February",
"03"=>"March",
"04"=>"April",
"05"=>"May",
"06"=>"June",
"07"=>"July",
"08"=>"August",
"09"=>"September",
"10"=>"October",
"11"=>"November",
"12"=>"December"
);

$input = array(
'ID' => 'Date',
'TYPE' => 'custom',
'CustomClass' => 'form_date_class',
'VALUE' => strftime("%Y-%m-%d"),
'SelectYears' => 100,
'Optional'=> 1,
'Months' = $months,
"Format" => "{day}{month}{year}");


And here are the errors I'm getting on submitting the form:

p_Date_year_year: it was not specified a valid input
p_Date_year_month: it was not specified a valid input
p_Date_year_day: it was not specified a valid input
p_Date_year_hour: it was not specified a valid input
p_Date_year_minute: it was not specified a valid input
p_Date_year_second: it was not specified a valid input
p_Date_month_year: it was not specified a valid input
p_Date_month_month: it was not specified a valid input
p_Date_month_day: it was not specified a valid input
p_Date_month_hour: it was not specified a valid input
p_Date_month_minute: it was not specified a valid input
p_Date_month_second: it was not specified a valid input
p_Date_day_year: it was not specified a valid input
p_Date_day_month: it was not specified a valid input
p_Date_day_day: it was not specified a valid input
p_Date_day_hour: it was not specified a valid input
p_Date_day_minute: it was not specified a valid input
p_Date_day_second: it was not specified a valid input

Strangely, on inspecting the HTML source, I found the inputs are actually generated but but with HIDDEN visibility for some reason! On submitting the form, the GET url reads like so:

p_Date_day=&p_Date_month=&p_Date_year=&p_Date_year=&p_Date_month=&p_Date_day=

Are the inputs supposed to generate with a suffix and also a prefix? I don't understand what those year_year, year_month, year_day, month_year, month_month, month_day, etc. are.

Regards,

  5. Re: Form_Date_Class usage   Reply   Report abuse  
Picture of Form Class Form Class - 2007-03-24 10:18:52 - In reply to message 4 from Form Class
I added an:

'ExtraAttributes' => array( 'visibility' => 'visible' )

to the input and now I get the custom input rendered on the form. I apologize I had duplicated inputs in my template that rendered two sets of inputs earlier. But I'm still trying to figure out why the inputs are rendered as hidden.

Thanks,

  6. Re: Form_Date_Class usage   Reply   Report abuse  
Picture of Form Class Form Class - 2007-03-26 00:08:38 - In reply to message 5 from Form Class
Never mind! I nailed down the bug in my code. I knew it was a glitch with my code.

Regards,

  7. Re: Form_Date_Class usage   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-03-26 22:06:59 - In reply to message 1 from Form Class
I could not reproduce that problem. Maybe if you can provide a complete script I can see what is going on.

  8. Re: Form_Date_Class usage   Reply   Report abuse  
Picture of Form Class Form Class - 2007-03-27 01:37:56 - In reply to message 7 from Manuel Lemos
Manuel,

It was a glitch in my form_class extension that was setting the invisible attribute on another input-type that was also getting applied to date class custom input. I just posted this message desparately.