|
![Picture of Nick L Picture of Nick L](/graphics/unknown.gif) Nick L - 2009-05-21 16:53:57
I need to dynamically set the date field for a form_date_class input field. I have tried various methods, but believe the correct way of setting the date assuming the date input name is 'expiry_date' is $form->SetInputProperty("expiry_date", "VALUE", "2009-06-09");
However this does not set the date and generates the message:
"p_expiry_date_month: it was not defined a valid input value". This message occurs even if there is no start and end date validation set for 'expiry_date'.
Is there a way to set the date and avoid this error message?
Thanks for your help on this excellent class.
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2009-05-22 03:41:18 - In reply to message 1 from Nick L
What do you mean by setting the date dynamically? Do you meant set the value in PHP or in Javascript?
Can you show a minimal script that causes that problem so I can reproduce it here?
![Picture of Nick L Picture of Nick L](/graphics/unknown.gif) Nick L - 2009-05-22 22:44:23 - In reply to message 2 from Manuel Lemos
Hi Manuel,
I have the input defined as follows:
$day_seconds=60*60*24;
$today='now';
$trade_max_date_before_today=30; // date is validated as not being more than one month ago
$trade_start_date=strftime("%Y-%m-%d",time()-($trade_max_date_before_today*$day_seconds));
$trade_end_date=strftime("%Y-%m-%d",time());
$form->AddInput(array(
"TYPE"=>"custom",
"ID"=>"entry_signal_date",
"LABEL"=>"Entry Signal Date",
"CustomClass"=>"form_date_class",
"VALUE"=>"",
"Format"=>"{day}/{month}/{year}",
"Months"=>array(
"01"=>"Jan",
"02"=>"Feb",
"03"=>"Mar",
"04"=>"Apr",
"05"=>"May",
"06"=>"Jun",
"07"=>"Jul",
"08"=>"Aug",
"09"=>"Sep",
"10"=>"Oct",
"11"=>"Nov",
"12"=>"Dec"
),
"Optional"=>1,
"ValidationStartDate"=>$trade_start_date,
"ValidationStartDateErrorMessage"=>"Date of Entry Signal cannot be more than ".$trade_max_date_before_today." days ago.",
"ValidationEndDate"=>$trade_end_date,
"ValidationEndDateErrorMessage"=>"Date of Entry Signal cannot be in the future."
));
I then try to set the value later from a database using the following:
$form->SetInputProperty("entry_signal_date", "VALUE", "2009-05-10" );
and I get the following two errors:
"Notice: p_entry_signal_date_year: it was not defined a valid input value in C:\Program Files\xampp\htdocs\Trading Controller\forms.php on line 730"
"Notice: entry_signal_date: p_entry_signal_date_year: it was not defined a valid input value in C:\Program Files\xampp\htdocs\Trading Controller\forms.php on line 730"
Thanks for any help you can give me here.
Nick
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2009-05-23 07:15:08 - In reply to message 3 from Nick L
There is nothing wrong with this code. I tried it and it worked without problems.
Whatever is causing the problems is not in this code. Therefore I need your to provide a more complete example that reproduces exactly what is causing the problem.
![Picture of Nick L Picture of Nick L](/graphics/unknown.gif) Nick L - 2009-05-25 15:35:37 - In reply to message 4 from Manuel Lemos
Hi Manuel,
I continue to appreciate your swiftness in responding.
My code is split across a fairly complicated Model-View-Controller so it is difficult to post here. However I think I have found the problem in form_date class and fixed it.
In form_date.php I have commented out the 'else' statement at line 488 as follows:
/*
else
{
$year = $this->year;
$month = $this->month;
$day = $this->day;
}
*/
$this->value = sprintf("%04d-%02d-%02d", $year, $month, $day);
This fixes the problem... I may be misunderstanding your code, but why would you want to set $year (which contains the year value, e.g. '2009') with $this->year (which contains the string name of the input 'p_entry_signal_date_year')?
If there is a reason why these three lines of code are given in the 'else' statement, and you think it may cause problems commenting it out, please let me know.
Thanks again. Your class is excellent.
Best Wishes,
Nick
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2009-05-26 05:23:02 - In reply to message 5 from Nick L
Good catch. That should have been $this_year instead of $this->year and so on.
Still it was not quite right. I fixed the problems and added a couple of test cases to make sure it works as expected.
The fixed version was uploaded. Thank you for reporting.
|