|
Web Contractors Web Developer Jobs Join Us / Log in Discussion |
HTML_Quickform adding a date
I've been mucking with html_quickform, to get dates nicely.
I hope this helps others.
Create the usual group of input fields then rules to validate them.
$dateform = array();
$dateform[] = &HTML_QuickForm::createElement('text', 'date_purchase_day', '', array('size' => 2, 'maxlength' => 2));
$dateform[] = &HTML_QuickForm::createElement('text', 'date_purchase_month', '', array('size' => 2, 'maxlength' => 2));
$dateform[] = &HTML_QuickForm::createElement('text', 'date_purchase_year', '', array('size' => 4, 'maxlength' => 4));
$form->addGroup($dateform,'date_purchase','Purchase Date:<div style="font-weight: normal; font-size: .8em;">DD/MM/YYYY</div>', '', false);
// adding the rules for the date fields
$form->addGroupRule('date_purchase', array(
'date_purchase_day' => array(
array('Date must be numeric, in the form DDMMYYYY', 'numeric'),
array('Date must be numeric, in the form DDMMYYYY', 'rangelength', array(2, 2))
),
'date_purchase_month' => array(
array('Date must be numeric, in the form DDMMYYYY', 'numeric'),
array('Date must be numeric, in the form DDMMYYYY', 'rangelength', array(2, 2))
),
'date_purchase_year' => array(
array('Date must be numeric, in the form DDMMYYYY', 'numeric'),
array('Date must be numeric, in the form DDMMYYYY', 'rangelength', array(4, 4))
)
));
// then we need to register a rule to check all the values
// so we know it is a valid date
$form->registerRule('local_checkdate', 'callback', 'local_checkdate');
$form->addRule('date_purchase', 'Must be a valid date, in for DDMMYYYY', 'local_checkdate');
function local_checkdate ( $date_array ) {
// bool checkdate ( int month, int day, int year )
return checkdate ( $date_array['date_purchase_month'], $date_array['date_purchase_day'], $date_array['date_purchase_year']);
}
New forum topics
- Freelance Web developer wanted
- Ringtone fatigue
- web developer looking for more project
- PHP website maintenance
- Desk available for hire - Rushcutters Bay location
- ZAMP?
- Don't hack the Drupal Core. Make a patch!
- What to charge for site updates
- Start New Website or CMS business. Business Partner / designer
- Code snippets in Google Search Results
- [syd] Freelance developer - .NET/ PHP/ Actionsctipt / DHTML
- Tester needed
- Freelance SharePoint 2003 / 2007 Consultant
- Joomla and Community Builder Module
- PHP export to CSV


Nice.
Post new comment