Hey guys,
I've been a php developer for a few years (mostly simple stuff) and only recently started to comprehend OOP code (generally I'm coping well, spending less time hunting down bugs). This may be a trivial question, but I would appreciate any and all assistance.
I've got a general design issue I've gotta deal with, I'd like some advice from those more experienced in this than I.
I've built a fairly large form using PEAR::HTML_QuickForm, for registering events (conferences, birthdays, weddings etc.). So I have fields for location, event type, and all that kinda stuff which is fine. I have the logic separate from the presentation (handled by Smarty).
In a previous incarnation of this site I had set up an array of warnings & errors for client status display (see below), but I now have all validation going through QuickForm, then handed out to Smarty. Sample of oldskool method follows:
// oldskool
if(empty($_POST['postcode'])) {
$errors['postcode'] = "Please enter your postcode";
} elseif (!Validate_UK::postcode($_POST['postcode'])) {
$warnings['postcode'] = 'Please enter a valid UK postcode';
} else {
$postcode = $_POST['postcode'];
}
Where I'm having a design issue is that an event can have multiple dates, at the moment I have it set up that you fill in the form completely with "date", "start time", "end time" (all info regarding each event is held in the same MySQL table).
Ideally what I want happening is a user fills in the form including a date for their event and clicks a button to "add another date", the form would then be refreshed (preserving all data entered which QuickForm should handle) with the set of date elements replicated to allow for another date. I could easily duplicate this set of date elements on the client side with some DOM scripting, but then QuickForm wouldn't know of these new elements.
// simple Quickform date elements
$dateOpts = array('language' => 'en',
'format' => 'dMY',
'minYear' => date('Y'),
'maxYear' => date('Y')+1,
'addEmptyOption' => 'true',
'emptyOptionText' => array('d'=>'Day','M'=>'Month','Y'=>'Year'));
$form->addElement('date', 'eventdates', 'If not, please choose the dates of your event below:', $dateOpts);
$form->addGroupRule('eventdates','Please choose the dates of your event','required');
// The start time field
$StartTimeOpts = array('language' => 'en',
'format' => 'hia',
'optionIncrement' => array('i' => 15),
'addEmptyOption' => 'true',
'emptyOptionText' => array('h'=>'Hour','i'=>'Min','a'=>'am/pm'));
$form->addElement('date', 'StartTime', 'Start time:', $StartTimeOpts);
$form->addGroupRule('StartTime','Please choose your event start time','required');
// The end time field
$EndTimeOpts = array('language' => 'en',
'format' => 'hia',
'optionIncrement' => array('i' => 15),
'addEmptyOption' => 'true',
'emptyOptionText' => array('h'=>'Hour','i'=>'Min','a'=>'am/pm'));
$form->addElement('date', 'EndTime', 'End time:', $EndTimeOpts);
$form->addGroupRule('EndTime','Please choose your event end time','required');
Once the user is happy with their choices the form would be submitted and each date would be inserted into a new row (Each event date will be editable (for different descriptions/attendees etc.), I realise I should probably separate events and event dates into different tables).
I have looked into QuickForm_Controller briefly, but I'd like some advice on how best to do this (I think my brain has taken an early holiday 🙁). My question is, how would you tackle this?
Again, If your can help, I would really appreciate it.
Thanks in advance.