hi Ingo,
custom form code below:
class BookingForm extends Form {
function __construct($controller, $name, $eventdata) {
// Build up event data for emailing
if($eventdata) {
foreach($eventdata as $key => $value)
{
$this->Event = $value->Event;
$this->EventDate = $value->EventDate;
$this->Contact = $value->Contact;
$this->ContactEmail = $value->Email;
}
}
$fields = new FieldSet(
new TextField('Firstname'),
new TextField('Surname'),
new EmailField('Email'),
new TextField('Telephone'),
new HiddenField('Event', '',$this->Event),
new HiddenField('EventDate', '',$this->EventDate),
new HiddenField('Contact', '',$this->Contact),
new HiddenField('ContactEmail', '',$this->ContactEmail)
);
// A hidden form field has been added to ss to stop CRSF attacks. If you want to disable this feature, use the method below
$this->disableSecurityToken();
// Create validator
$validator = new RequiredFields('Firstname', 'Surname', 'Email');
// Create actions for form (individual buttons what are passed to specific functions)
$actions = new FieldSet(
new FormAction('submit', '')
//new FormAction('doPublicationForm', 'Reset')
);
parent::__construct($controller, $name, $fields, $actions, $validator);
}
function submit($data, $form) {
$email = new Email_Template();
$email->ss_template = "EventBookingEmail";
$templateData = array(
'Contact' => $data['Contact'],
'Event' => $data['Event'],
'EventDate' => $data['EventDate'],
'UserName' => $data['Firstname']. ' '. $data['Surname'],
'Email' => $data['Email'],
'Telephone' => $data['Telephone']
);
$email->populateTemplate($templateData);
$email->subject = 'Event Booking: '.$data['Event'];
$email->from = $email->getAdminEmail();
$email->to = $data['ContactEmail'];
$email->send();
Director::redirect('event-booking-thankyou/');
}
}
I use $BookingForm to insert my custom form into the page.
The form validation half works in that it doesn't submit if any required fields are missing. The problem is though, it doesn't display any error messages.
any ideas?