Running code and form content in ajax….
-
Hey all
I’ve designed my website using wordpress, – On the site I want to show a booking system which is organised by postcode (So I work in the same area on the various days).
I’ve written some php code which allows me to input a postcode, it then removes any whitespace and removes the last 3 characters. Whats left is checked against an array of postcodes and depending on what the postcode is, it displays different forms…
this is the code:
<form id="form" action="" method="post"> <input type="text" id="postcode" name="postcode" value="" /> <input type="submit" name="submit" value="Find Me" /> </form> <div id="return-wrap"></div> <?php $postcode = $_POST['postcode']; $postcode = preg_replace('/\s+/', '', $postcode); $postcode = substr($postcode, 0, -3); if(in_array($postcode, array("NR1", "NR2", "NR3", "NR4", "NR5", "NR6", "NR7", "NR8", "NR9", "NR19", "NR20"))){ echo "1 form"; } elseif(in_array($postcode, array("NR10", "NR11", "NR12", "NR26", "NR27", "NR28"))) { echo "2 form"; } elseif(in_array($postcode, array("NR13", "NR14", "NR15", "NR29", "NR30", "NR31", "NR32", "NR33", "NR34", "NR35", "IP18", "IP19", "IP20", "IP21", "IP22"))) { echo "3 form"; } else { echo "other"; } ?>
Considering this is in wordpress, I can use a php plugin to either call the code etc and add the html form on the page – but how would I get this to run through ajax so that I do not need to submit the page etc… I don’t want the page to refresh – I just want the content to swap.
- The topic ‘Running code and form content in ajax….’ is closed to new replies.