function test_enter_postcode_message() { $message = cobrand_enter_postcode_message('mysite', 'cocode'); $this->assertEqual('My message', $message, 'Should return the message returned by the cobrand if the cobrand defines an enter_postcode_message function'); $message = cobrand_enter_postcode_message('nosite', 'cocode'); $this->assertEqual(false, $message, 'Should return false if there is no cobrand enter_postcode_message function'); }
function postcode_form($pc, $cobrand, $cocode, $a_forward, $error_message, $options) { $form = '<form action="/" method="get" name="postcodeForm" id="postcodeForm" onsubmit="trackFormSubmit(this, \'PostcodeSearch\', \'Submit\'); return false;">'; if ($options['inner_div']) { $form .= '<div id="postcodebox">'; } $form .= '<label for="pc">'; if ($options['bold_labels']) { $form .= '<b>'; } $message = cobrand_enter_postcode_message($cobrand, $cocode); if (!$message) { $message = 'First, enter your UK postcode'; } $form .= $message; if ($options['bold_labels']) { $form .= '</b>'; } $form .= '</label>'; if ($options['extra_space']) { $form .= ' '; } if ($options['show_errors'] && $error_message) { $form .= '<div class="alert-box alert">' . $error_message . '</div>'; } if ($options['extra_space']) { $form .= ' '; } $form .= '<div class="row collapse"> <div class="small-10 columns"> <input type="text" id="pc" name="pc" value="' . htmlspecialchars($pc) . '" placeholder="SW1H 9NB"> </div> <div class="small-2 columns"> <input type="submit" class="button success prefix" value="Go"> </div> </div>'; /* Record referer. We want to pass this onto the queue later, as an anti-abuse * measure, so it should be propagated through all the later pages. Obviously * this only has value against a naive attacker; also, there is no point in * trying to obscure this data. */ $ref = fyr_external_referrer(); if (isset($ref)) { $form .= '<input type="hidden" name="fyr_extref" value="' . htmlentities($ref) . '">'; } if ($cocode) { $form .= '<input type="hidden" name="cocode" value="' . htmlentities($cocode) . '">'; } if ($a_forward) { $form .= '<input type="hidden" name="a" value="' . htmlentities($a_forward) . '">'; } if ($options['extra_space']) { $form .= ' '; } $form .= '<a href="/about-constituency" class="help-text">What postcode should I use?</a>'; // End the form if ($options['inner_div']) { $form .= '</div>'; } $form .= '</form>'; return $form; }