function CreateControls() { /* @var $o_email Zend_Mail */ $this->AddCssClass('legacy-form'); $o_email = $this->GetDataObject(); if (!is_object($o_email)) { $o_email = new Zend_Mail('UTF-8'); } # Who to send to $i_address_count = count($this->a_addresses); if ($i_address_count > 1) { $o_who = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Why are you contacting us?')); $o_who->SetCssClass('radioButtonList'); $i = 0; foreach ($this->a_addresses as $s_addr => $s_reason) { $o_radio = new XhtmlElement('input'); $o_radio->SetEmpty(true); $o_radio->AddAttribute('type', 'radio'); $o_radio->AddAttribute('name', 'to'); $o_radio->AddAttribute('value', md5($s_addr)); $o_radio->SetXhtmlId('to' . $i); if ($this->IsPostback()) { if (isset($_POST['to']) and $_POST['to'] == md5($s_addr)) { $o_radio->AddAttribute('checked', 'checked'); } } else { if (!$i) { $o_radio->AddAttribute('checked', 'checked'); } } $o_label = new XhtmlElement('label', $o_radio); $o_label->AddAttribute('for', $o_radio->GetXhtmlId()); $o_label->AddControl($s_reason); $o_who->AddControl($o_label); $i++; } $this->AddControl($o_who); } # Your details $o_details = new XhtmlElement('fieldset'); $o_details->AddControl(new XhtmlElement('legend', 'Your details')); $this->AddControl($o_details); $o_name = new TextBox('fromName', '', $this->IsValidSubmit()); $o_name->SetMaxLength(100); $o_name_part = new FormPart('Name', $o_name); $o_details->AddControl($o_name_part); $o_from = new TextBox('from', '', $this->IsValidSubmit()); $o_from->AddAttribute("type", "email"); $o_from->SetMaxLength(250); $o_from_part = new FormPart('Email address', $o_from); $o_from_part->SetIsRequired(true); $o_details->AddControl($o_from_part); # Your email $o_message = new XhtmlElement('fieldset'); $o_message->AddControl(new XhtmlElement('legend', 'Your email')); $this->AddControl($o_message); $o_subj = new TextBox('subject', '', $this->IsValidSubmit()); $o_subj->SetMaxLength(250); $o_subj_part = new FormPart('Subject', $o_subj); $o_message->AddControl($o_subj_part); $o_body = new TextBox('body', '', $this->IsValidSubmit()); $o_body->SetMode(TextBoxMode::MultiLine()); $o_body_part = new FormPart('Your message', $o_body); $o_body_part->SetIsRequired(true); $o_message->AddControl($o_body_part); # Options $o_opt = new XhtmlElement('fieldset', null, "radioButtonList"); $o_opt->AddControl(new XhtmlElement('legend', 'Options', "aural")); $this->AddControl($o_opt); $o_opt->AddControl(new CheckBox('cc', 'Send me a copy', 1, false, $this->IsValidSubmit())); $o_opt->AddControl(new CheckBox('reply', "I'd like a reply", 1, true, $this->IsValidSubmit())); }
function OnPageInit() { parent::OnPageInit(); # Set up form, which must exist to be validated $this->form = new XhtmlForm(); $fs1 = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Your team name')); $this->form->AddControl($fs1); $o_team = new TextBox('team', isset($_POST['team']) ? $_POST['team'] : ''); $o_team->SetMaxLength(200); $o_team_part = new FormPart('Team name', $o_team); $o_team_part->SetIsRequired(true); $fs1->AddControl($o_team_part); $o_club = new TextBox('club', isset($_POST['club']) ? $_POST['club'] : ''); $o_club->SetMaxLength(200); $o_club_part = new FormPart('Club (if different)', $o_club); $fs1->AddControl($o_club_part); $fs2 = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Where and when you play')); $this->form->AddControl($fs2); $o_ground = new TextBox('ground', isset($_POST['ground']) ? $_POST['ground'] : ''); $o_ground->SetMode(TextBoxMode::MultiLine()); $o_ground_part = new FormPart('Address of playing field', $o_ground); $o_ground_part->SetIsRequired(true); $fs2->AddControl($o_ground_part); $o_prac = new TextBox('pracNight', isset($_POST['pracNight']) ? $_POST['pracNight'] : ''); $o_prac->SetMaxLength(50); $o_prac_part = new FormPart('Practice night', $o_prac); $fs2->AddControl($o_prac_part); $o_match = new TextBox('matchNight', isset($_POST['matchNight']) ? $_POST['matchNight'] : ''); $o_match->SetMaxLength(100); $o_match_part = new FormPart('Match nights', $o_match); $fs2->AddControl($o_match_part); $o_league = new TextBox('leagues', isset($_POST['leagues']) ? $_POST['leagues'] : ''); $o_league->SetMode(TextBoxMode::MultiLine()); $o_league_part = new FormPart('League(s) or friendlies you play in', $o_league); $fs2->AddControl($o_league_part); $fs3 = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Contact details for Stoolball England to use')); $this->form->AddControl($fs3); $o_contact = new TextBox('contact', isset($_POST['contact']) ? $_POST['contact'] : ''); $o_contact->SetMaxLength(150); $o_contact_part = new FormPart('Contact name', $o_contact); $o_contact_part->SetIsRequired(true); $fs3->AddControl($o_contact_part); $o_contact_addr = new TextBox('address', isset($_POST['address']) ? $_POST['address'] : ''); $o_contact_addr->SetMode(TextBoxMode::MultiLine()); $o_contact_addr_part = new FormPart('Contact address', $o_contact_addr); $fs3->AddControl($o_contact_addr_part); $o_contact_phone = new TextBox('contactPhone', isset($_POST['contactPhone']) ? $_POST['contactPhone'] : ''); $o_contact_phone->SetMaxLength(50); $o_contact_phone_part = new FormPart('Contact phone number', $o_contact_phone); $fs3->AddControl($o_contact_phone_part); $o_contact_e = new TextBox('email', isset($_POST['email']) ? $_POST['email'] : ''); $o_contact_e_part = new FormPart('Contact email', $o_contact_e); $o_contact_e_part->SetIsRequired(true); $fs3->AddControl($o_contact_e_part); $fs4 = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Contact details for the website'), '#publicContact'); $fs4->SetCssClass("radioButtonList"); $this->form->AddControl($fs4); $public1 = new RadioButton('publicAbove', 'public', 'Same as above', 'Same', $this->IsPostback() ? isset($_POST['public']) and $_POST['public'] == 'Same' : true); $public3 = new RadioButton('publicDiff', 'public', 'Display different contact details on the website', 'Different', $this->IsPostback() ? isset($_POST['public']) and $_POST['public'] == 'Different' : false); $public2 = new RadioButton('publicNone', 'public', 'Don\'t display any contact details (not recommended)', 'None', $this->IsPostback() ? isset($_POST['public']) and $_POST['public'] == 'None' : false); $fs4->AddControl($public1); $fs4->AddControl($public3); $fs4->AddControl($public2); $public_contact = new TextBox('publicContact', isset($_POST['publicContact']) ? $_POST['publicContact'] : ''); $public_contact->SetMode(TextBoxMode::MultiLine()); $public_contact_part = new FormPart('Contact details for the website', $public_contact); $public_contact_part->SetXhtmlId('publicContactPart'); $fs4->AddControl($public_contact_part); $fs5 = new XhtmlElement('fieldset', new XhtmlElement('legend', 'Anything else you\'d like on your team\'s page')); $this->form->AddControl($fs5); $o_notes = new TextBox('notes', isset($_POST['notes']) ? $_POST['notes'] : ''); $o_notes->SetMode(TextBoxMode::MultiLine()); $o_notes_part = new FormPart('Other details', $o_notes); $fs5->AddControl($o_notes_part); $o_buttons = new XhtmlElement('div'); $o_buttons->SetCssClass('buttonGroup'); $o_submit = new Button('send', 'Send email'); $o_buttons->AddControl($o_submit); $this->form->AddControl($o_buttons); # Set up validation require_once 'data/validation/required-field-validator.class.php'; require_once 'data/validation/length-validator.class.php'; require_once 'data/validation/email-validator.class.php'; $a_validators = array(); $a_validators[] = new RequiredFieldValidator(array('team'), 'A team name is required'); $a_validators[] = new LengthValidator(array('team'), 'Your team name is too long', 0, 200); $a_validators[] = new LengthValidator(array('club'), 'Your club name is too long', 0, 200); $a_validators[] = new RequiredFieldValidator(array('ground'), 'A playing field address is required'); $a_validators[] = new LengthValidator(array('ground'), 'The playing field address is too long', 0, 2000); $a_validators[] = new RequiredFieldValidator(array('contact'), 'A contact name for the team is required'); $a_validators[] = new LengthValidator(array('pracNight'), 'Practice night must be 50 characters or less', 0, 50); $a_validators[] = new LengthValidator(array('matchNight'), 'Match nights must be 100 characters or less', 0, 100); $a_validators[] = new LengthValidator(array('leagues'), 'Your league or friendly group(s) must be 2000 characters or less', 0, 2000); $a_validators[] = new LengthValidator(array('contact'), 'Your contact name is too long', 0, 150); $a_validators[] = new LengthValidator(array('address'), 'The contact address is too long', 0, 2000); $a_validators[] = new LengthValidator(array('contactPhone'), 'The contact phone number is too long', 0, 50); $a_validators[] = new RequiredFieldValidator(array('email'), 'A contact email for the team is required'); $a_validators[] = new EmailValidator('email', 'Please enter a valid email address'); $a_validators[] = new LengthValidator('publicContact', 'You\'ve put too much in the "website contact details" box. Please make the text shorter.', 0, 10000); $a_validators[] = new LengthValidator('notes', 'You\'ve put too much in the "other details" box. Please make the text shorter.', 0, 10000); foreach ($a_validators as $o_v) { $this->form->AddValidator($o_v); unset($o_v); } $this->RegisterControlForValidation($this->form); }