/** * Creates a new RadioButton * * @param string $s_id * @param string $s_group_name * @param string $s_label * @param string $s_value * @param bool $b_checked * @param bool $page_valid * @return RadioButton */ function RadioButton($s_id, $s_group_name, $s_label, $s_value = '', $b_checked = false, $page_valid = null) { # this element is the label for the radio button parent::XhtmlElement('label'); $this->AddAttribute('for', $s_id); $this->SetCssClass('radioButton'); # create radio button as child control $o_radio = new XhtmlElement('input'); $o_radio->SetEmpty(true); $o_radio->AddAttribute('type', 'radio'); $o_radio->AddAttribute('value', $s_value); $this->a_controls[0] =& $o_radio; $this->SetGroupName($s_group_name); # wait to set id, because it'll set both controls at once $this->SetXhtmlId($s_id); # wait to set label so that it comes after radio button $this->a_controls[1] = htmlentities($s_label, ENT_QUOTES, "UTF-8", false); if ($page_valid === false) { $this->b_checked = (isset($_POST[$s_group_name]) and $_POST[$s_group_name] == $s_value); } else { $this->b_checked = (bool) $b_checked; } }
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())); }
/** * Creates the default action buttons for the repeated group of controls * @return XhtmlElement */ private function CreateDefaultButtons() { $o_buttons = new XhtmlElement('div'); $o_buttons->SetCssClass('buttonGroup'); $o_button = new XhtmlElement('input'); $o_button->SetEmpty(true); $o_button->AddAttribute('type', 'submit'); $o_button->AddAttribute('value', $this->GetButtonText()); $o_buttons->AddControl($o_button); return $o_buttons; }
/** * Creates standard controls used by most data edit forms * */ protected function OnPreRender() { require_once 'xhtml/forms/textbox.class.php'; require_once 'xhtml/forms/checkbox.class.php'; require_once 'xhtml/forms/xhtml-select.class.php'; # add id if (is_object($this->o_data_object) and method_exists($this->o_data_object, 'GetId') and $this->o_data_object->GetId()) { $o_id_box = new TextBox($this->s_naming_prefix . 'item', (string) $this->o_data_object->GetId()); $o_id_box->SetMode(TextBoxMode::Hidden()); $this->AddControl($o_id_box); } # Add save button if building the form # Add at top of form to trap enter key if ($this->b_render_base_element) { $o_buttons = new XhtmlElement('div'); $o_buttons->AddCssClass($this->show_buttons_at_top ? 'buttonGroup buttonGroupTop' : 'buttonGroup aural'); $o_save = new XhtmlElement('input'); $o_save->SetEmpty(true); $o_save->AddAttribute('type', 'submit'); $o_save->SetXhtmlId($this->GetNamingPrefix() . 'DataEditSave'); $o_save->AddAttribute('name', $o_save->GetXhtmlId()); $o_buttons->AddControl($o_save); if ($this->show_buttons_at_top and $this->GetAllowCancel()) { require_once 'xhtml/forms/button.class.php'; $o_buttons->AddControl(new Button($this->GetNamingPrefix() . 'DataEditCancel', 'Cancel')); } $this->AddControl($o_buttons); } # fire event for child class to create its controls $this->CreateControls(); # Add a second save button if ($this->b_render_base_element) { $o_save->AddAttribute('value', $this->GetButtonText()); # Allow button text to be set late $o_save2 = clone $o_save; $o_save2->SetXhtmlId($this->GetNamingPrefix() . 'DataEditSave2'); $o_save2->AddAttribute('name', $o_save2->GetXhtmlId()); $o_save2->AddCssClass('primary'); $o_buttons2 = new XhtmlElement('div'); $o_buttons2->SetCssClass('buttonGroup'); $o_buttons2->AddControl($o_save2); if ($this->GetAllowCancel()) { if (!$this->show_buttons_at_top) { require_once 'xhtml/forms/button.class.php'; } $cancel = new Button($this->GetNamingPrefix() . 'DataEditCancel2', 'Cancel'); $cancel->SetCssClass('cancel'); $o_buttons2->AddControl($cancel); } $this->AddControl($o_buttons2); } # Add page number if it's not the default if ($this->current_page != 1) { $page = new TextBox($this->GetNamingPrefix() . 'Page', $this->GetCurrentPage(), $this->IsValidSubmit()); $page->SetMode(TextBoxMode::Hidden()); $this->AddControl($page); } # to be valid, should all be in a div $o_container = new XhtmlElement('div'); $o_container->SetControls($this->GetControls()); if (!$this->b_render_base_element) { $o_container->SetCssClass($this->GetCssClass()); $o_container->SetXhtmlId($this->GetXhtmlId()); } $a_controls = array(); $a_controls[] = $o_container; $this->SetControls($a_controls); }
/** * Adds populated controls as a new table row * * @param XhtmlElement[] $a_controls * @param bool $b_enabled * @return XhtmlRow */ protected function AddRowToTable($a_controls, $b_enabled = true) { # Add action button to controls for table $button = new XhtmlElement('input'); if (!$b_enabled) { $button->AddAttribute('disabled', 'disabled'); } $last_cell_data = new Placeholder($button); $s_id = ''; if (!is_null($this->current_data_object)) { # Get methods for data objects $s_id_method = $this->s_id_method; $s_date_modified_method = $this->s_date_modified_method; # Update button $button->AddAttribute('value', 'Delete'); $button->SetXhtmlId($this->GetNamingPrefix() . 'DeleteRelated' . $this->i_current_row_identifier); # Hidden - id of related item $s_id = $this->current_data_object->{$s_id_method}(); $s_id = $s_id ? $s_id : $this->i_current_row_identifier; $id_box = new TextBox($this->GetNamingPrefix() . 'RelatedId' . $this->i_current_row_identifier, $s_id); $id_box->SetMode(TextBoxMode::Hidden()); $last_cell_data->AddControl($id_box); # Hidden - when was relationship to item updated? $b_track_modified_date = ($s_date_modified_method and method_exists($this->current_data_object, $s_date_modified_method)); if ($b_track_modified_date) { $updated_box = new TextBox($this->GetNamingPrefix() . 'RelatedUpdated' . $this->i_current_row_identifier, $this->current_data_object->{$s_date_modified_method}()); $updated_box->SetMode(TextBoxMode::Hidden()); $last_cell_data->AddControl($updated_box); } # Hidden - check whether item updated $check_box = new TextBox($this->GetNamingPrefix() . 'Check' . $this->i_current_row_identifier, $this->GetDataObjectHash($this->current_data_object)); $check_box->SetMode(TextBoxMode::Hidden()); $last_cell_data->AddControl($check_box); } else { $button->AddAttribute('value', 'Add'); $button->SetXhtmlId($this->GetNamingPrefix() . 'AddRelated'); } $button->AddAttribute('type', 'submit'); $button->SetEmpty(true); $button->AddAttribute('name', $button->GetXhtmlId()); $this->RegisterInternalButton($button->GetXhtmlId()); # Create table row and add to table $a_controls[] = $last_cell_data; $row = new XhtmlRow($a_controls); if (!$b_enabled) { $row->SetCssClass('unavailable'); } $this->table->AddRow($row); return $row; }