Jump to content

mylesrobinson

Members
  • Posts

    6
  • Joined

  • Last visited

mylesrobinson's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I have had my PHP working for a while now, but it has come to the point where i need it altering. Basically, at the minute, the code works only when a user inputs a space in their postcode (eg: WF8 5TD) and will not work if it was entered like this: (eg: WF85TD) I want the code to work so that it picks up on the first 2, 3 or 4 characters without the space in the postcode being an issue- or any other way so that if the user does not enter a space in their postcode, the form will still route to what page i want it to. The code i have is below: <?php //get the postcode $agree = isset($_GET['agree']) ? trim($_GET['agree']) : ''; //convert postcode to uppercase $agree = strtoupper($agree); //find the position of the space in the postcode $pos = strpos($agree, ' '); //split the string so we are only looking at the chars up to the space //we're splitting counting from 0 to $pos $route = substr($agree, 0, $pos); switch ($route) { case "LA10": case "LA11": case "LA12": case "LA13": case "LA14": case "LA15": case "LA16": case "LA17": case "LA18": case "LA19": case "LA20": case "LA21": case "LA22": header("Location: http://www.website.co.uk/abacus"); break; It should be mentioned that i have email routing also which works as i want the above to. A snippet of the email routing code is below: /* add_filter("gform_pre_submission", "before_email"); function before_email($form){ echo "<pre>"; print_r($form); echo "</pre>"; exit; $email["to"] = "xhtmlpoint@gmail.com"; $email["message"] = "This is my new message."; $email["subject"] = "This is a new subject."; return $email; } */ add_filter('gform_notification', 'change_notification_email', 10, 3); function change_notification_email( $notification, $form, $entry ) { // /*echo "<pre>"; // print_r($entry[7]); // echo "</pre>"; exit;*/ $postcode = strtoupper(ereg_replace("[^A-Za-z0-9]", "", trim($entry[7]))); $lenght = strlen($postcode); if($lenght < 5 OR $lenght == 4){ $regex = '/^([A-Z]{1,2})([0-9][0-9A-Z]?)$/'; if (preg_match($regex, $postcode, $part)) { $code = array( 'outer' => $part[1] . $part[2] ); }else{ $code = NULL; } }else{ $regex = '/^([A-Z]{1,2})([0-9][0-9A-Z]?)s*([0-9])([A-Z]{2})$/'; if (preg_match($regex, $postcode, $part)) { $code = array( 'outer' => $part[1] . $part[2] ); }else{ $code = NULL; } } if(is_null($code)) { $notification['toType'] = "email"; $notification['to'] = "enquiries@hansongarages.co.uk"; } else{ //There is no concept of admin notifications anymore, so we will need to target notifications based on other criteria, such as name $abacus = array("LA10", "LA11", "LA12", "LA13", "LA14", "LA15", "LA16", "LA17", "LA18", "LA19", "LA20", "LA21", "LA22"); if(in_array($code['outer'], $abacus)){ // toType can be routing or email $notification['toType'] = "email"; $notification['to'] = "exampleoftheemail@tiscali.co.uk";
  2. Ok thanks. Sorry for the confusion. I am oblivious to where to put the code suggested though. I am very inexperienced with writing code but i know how to upload it and understand the code that i see (mostly!) but unable to figure out where i need to put the substr(), strtolower() and strpos in the code that i put in my original post. I will keep trying to work it out.
  3. HiThanks for that, it works. However a lot of the time they will enter a postcode such as fk1 4eh so I would need it to only pick up on the first 3 and sometimes 4 characters. Another point is that they are not actually case sensitive so would the 'case' bit be applicable? Thanks for your help
  4. Hi Thanks for your reply. I will show you what bits of the postcodes i need for each of the 2 URL redirects: <?php $agree = $_GET['agree']; switch ($agree) { case ("ky1", "ky2", "ky3", "ky12", "ky13", "ky14":) header("Location: http://www.concretegaragesscotland.com"); break; case ("fk1", "fk12", "fk13":) header("Location: http://www.patersons...buildings.co.uk"); break; } ?> So as you see, i have a range of data that someones postcode may start with. If it does start with any of those in the code above then they will route to that specified URL.
  5. Hi Thanks for your reply. I think the $agree bit is wrong. I am basically wanting redirects to one of 2 websites based upon data from the first 3 and 4 characters of the postcode when entered into the form i have set up in gravity forms. It doesn't need to be case sensitive (which i think it is in the above code). I am not very experienced in PHP but i am sure that the code doesn't need altering too much from what i have already?
  6. Hi I am trying to get some code working correctly so that i can route users to a URL redirect when completing a form on our website. There are only 2 URL's to redirect to but there are a range of post codes that i need to add to the code. At the minute the code works only if the letters are the same case (Caps or not caps) and when i enter more than one postcode, the form comes back with a PHP error. I basically need to be able to let the user enter a postcode and the code will work for the first 3 AND 4 (sometimes) characters. For example a post code may be EH2 or EH34 and i would need the form to be able to do this. Sorry for the lack of knowledge on this but i hope someone can help. The code is posted below what i currently have. <?php $agree = $_GET['agree']; switch ($agree) { case "ky1": header("Location: http://www.concretegaragesscotland.com"); break; case "FK", : header("Location: http://www.patersonsgardenbuildings.co.uk"); break; } ?>
×
×
  • Create New...