function buildWriteForm($options) { global $fyr_values, $stash; global $fyr_voting_area; global $cobrand, $cocode; $form_action = cobrand_url($cobrand, '/write', $cocode); $form = new HTML_QuickForm('writeForm', 'post', $form_action); if ($fyr_voting_area['name'] == 'United Kingdom') { $fyr_voting_area['name'] = 'House of Lords'; } $write_header = ''; $form->addElement('textarea', 'body', null, array('class' => 'message')); $form->addRule('body', 'Please enter your message', 'required', null, null); $form->addRule('body', 'Please enter your message', new RuleAlteredBodyText(), null, null); $form->addRule('body', 'Please sign at the bottom with your name, or alter the "Yours sincerely" signature', new RuleSigned(), null, null); $form->addRule('body', 'Your message is a bit too long for us to send', 'maxlength', OPTION_MAX_BODY_LENGTH); $form->addElement('html', '<div class="row">'); $form->addElement('html', '<fieldset class="large-6 columns">'); $form->addElement('html', '<legend>About You</legend>'); $form->addElement('text', 'name', "Your name", array('required' => 'required', 'maxlength' => 255)); $form->addRule('name', 'Please enter your name', 'required', null, null); $form->applyFilter('name', 'trim'); $form->addElement('text', 'writer_email', "Your email", array('required' => 'required', 'maxlength' => 255)); $form->addRule('writer_email', 'Please enter your email address', 'required', null, null); $invalid_email_message = cobrand_invalid_email_message($cobrand); if (!$invalid_email_message) { $invalid_email_message = 'Choose a valid email address'; } $form->addRule('writer_email', $invalid_email_message, 'email', null, null); $form->applyFilter('writer_email', 'trim'); $form->addElement('text', 'writer_email2', "Confirm email", array('required' => 'required', 'maxlength' => 255)); $form->addRule('writer_email2', 'Please re-enter your email address', 'required', null, null); $form->applyFilter('writer_email2', 'trim'); $form->addFormRule('compare_email_addrs'); $form->updateElementAttr(array('writer_email', 'writer_email2'), array('type' => 'email')); $form->addElement('text', 'writer_phone', 'Phone <span class="optional-text">optional</span>', array('maxlength' => 255)); $form->applyFilter('writer_phone', 'trim'); $form->addElement("html", "</fieldset>"); $form->addElement("html", '<fieldset class="large-6 columns">'); $form->addElement("html", '<legend>Your Address</legend>'); $form->addElement('text', 'writer_address1', "Address Line 1", array('required' => 'required', 'maxlength' => 255)); $form->addRule('writer_address1', 'Please enter your address', 'required', null, null); $form->applyFilter('writer_address1', 'trim'); $form->addElement('text', 'writer_address2', 'Address Line 2 <span class="optional-text">optional</span>', array('maxlength' => 255)); $form->applyFilter('writer_address2', 'trim'); $form->addElement('text', 'writer_town', "Town/City", array('required' => 'required', 'maxlength' => 255)); $form->addRule('writer_town', 'Please enter your town/city', 'required', null, null); $form->applyFilter('writer_town', 'trim'); $form->addElement('html', '<div class="row">'); $form->addElement('html', '<div class="small-8 columns">'); # Call it state so that Google Toolbar (and presumably others) can auto-fill. $form->addElement('text', 'state', 'County <span class="optional-text">optional</span>', array('maxlength' => 255)); $form->applyFilter('state', 'trim'); $form->addElement('html', '</div>'); $form->addElement('html', '<div class="small-4 columns">'); if (is_postcode_editable($fyr_voting_area['type'])) { // House of Lords $form->addElement('text', 'pc', "UK postcode", array('required' => 'required', 'maxlength' => 8)); $form->addRule('pc', 'Please enter a UK postcode (<a href="/about-lords#ukpostcode" target="_blank">why?</a>)', 'required', null, null); $form->addRule('pc', 'Please enter a valid UK postcode (<a href="/about-lords#ukpostcode" target="_blank">why?</a>)', new RulePostcode(), null, null); $form->applyFilter('pc', 'trim'); } else { // All other representatives (postcode fixed as must be in constituency) $form->addElement('text', 'staticpc', "UK postcode", array('disabled' => 'disabled', 'value' => htmlentities($fyr_values['pc']))); } $form->addElement('html', '</div>'); $form->addElement('html', '</div>'); $form->addElement("html", "</fieldset>"); $form->addElement('html', '</div>'); # close div.row $form->addElement("html", '<fieldset class="last"><legend>Ready?</legend>'); add_all_variables_hidden($form, $fyr_values, $options); $preview_text = cobrand_preview_text($cobrand); if (!$preview_text) { $preview_text = "When you’re ready to send your message click the button below. You’ll get a chance to read through it again to check for problems before we send it."; } $preview_button_text = cobrand_preview_button_text($cobrand); if (!$preview_button_text) { $preview_button_text = 'Preview and send'; } $form->addElement('html', "<p class=\"action\" id=\"preview-submit\">{$preview_text}</p>"); $form->addElement('submit', 'submitPreview', $preview_button_text, array('class' => 'button radius success')); $form->addElement("html", "</fieldset>"); return $form; }
function display_form() { // //////////////////////////////////////// // Instantiate the HTML_QuickForm object $form = new HTML_QuickForm( 'firstForm', 'get' ); $languages_suggs = array( "eng" => "eng", "deu" => "deu", "fra" => "fra", "ita" => "ita", "nld" => "nld" ); $collections = array( '376317' => 'One laptop per child basic vocabulary', '376322' => 'Destinazione Italia' ); // Set defaults for the form elements $form->setDefaults( array( 'name' => 'From' ) ); // Add some elements to the form $form->addElement( 'header', null, '' ); $form->addElement( 'hidden', 'ow', '1' ); $form->addElement( 'select', 'mode', 'voc browser mode:', array( 'browser' => 'lookup dictionary', 'trainer' => 'vocabulary training' ) ); if ( $_REQUEST['mode'] == 'trainer' ) { $form->addElement( 'select', 'wdcollection', 'Collection to choose vocabulary from:', $collections ); $form->addElement( 'select', 'wdlanguages_1', 'target language you want to train:', $languages_suggs ); } else { $form->addElement( 'select', 'wdlanguages_1', 'first output language:', $languages_suggs ); } if ( $_REQUEST['settings'] == 1 ) { $form->addElement( 'text', 'wdlanguages_2', 'second output language:', array( 'value' => '', 'size' => 6, 'maxlength' => 6 ) ); $form->addElement( 'text', 'wdlanguages_3', 'third output language:', array( 'size' => 6, 'maxlength' => 6 ) ); $form->addElement( 'text', 'wdlanguages_4', 'fourth output language:', array( 'size' => 6, 'maxlength' => 6 ) ); $link = build_get_uri_2( 'settings', '0', '' ); echo '<a href="' . $link . '">hide settings and languages</a>'; } elseif ( $_REQUEST['mode'] == 'trainer' && ( $_REQUEST['trainer_step'] == 0 ) ) { $form->addElement( 'text', 'wdlanguages_2', 'first language you can understand:', array( 'size' => 6, 'maxlength' => 6 ) ); $form->addElement( 'text', 'wdlanguages_3', 'second language you can understand:', array( 'size' => 6, 'maxlength' => 6 ) ); $form->addElement( 'text', 'wdlanguages_4', 'third language you can understand:', array( 'size' => 6, 'maxlength' => 6 ) ); } else { $form->addElement( 'hidden', 'wdlanguages_2', '', array( 'size' => 6, 'maxlength' => 6 ) ); $form->addElement( 'hidden', 'wdlanguages_3', '', array( 'size' => 6, 'maxlength' => 6 ) ); $form->addElement( 'hidden', 'wdlanguages_4', '', array( 'size' => 6, 'maxlength' => 6 ) ); $link = build_get_uri_2( 'settings', '1', '' ); echo '<a href="' . $link . '">edit settings and languages</a>'; } if ( $_REQUEST['definedmeaning'] ) { $expression_group[] = &HTML_QuickForm::createElement( 'text', 'expression', 'search expression:', array( 'value' => '' , 'size' => 20, 'maxlength' => 256 ) ); $form->updateElementAttr( 'expression', array( 'value' => '' ) ); $expression_group[] = &HTML_QuickForm::createElement( 'text', 'wdexplanguage', 'source language of an expression <br />(leave blank to search all languages)', array( 'size' => 20, 'maxlength' => 256 ) ); } else { $expression_group[] = &HTML_QuickForm::createElement( 'text', 'expression', 'search expression:', array( 'size' => 20, 'maxlength' => 256 ) ); $expression_group[] = &HTML_QuickForm::createElement( 'text', 'wdexplanguage', 'source language of an expression <br />(leave blank to search all languages)', array( 'size' => 4, 'maxlength' => 256 ) ); } $form->addGroup( $expression_group, 'Expression', 'Search Expression:', '  only in this language:', 0 ); if ( $_REQUEST['settings'] == 1 ) { $form->addElement( 'text', 'definedmeaning', 'definedmeaning (word-id):', array( 'value' => '', 'size' => 15 ) ); } $form->addElement( 'submit', null, 'set / update' ); // Output the form $form->display(); // // //////////////////////////////////////// }