form validation, integrating into WordPress
-
I’ve created a template page to enable an admin user to enter some fields into a custom table I’ve created as part of the wordpress d/b. The page displays as it should but when the form is submitted, the index.php page with all the posts is displayed. How do I get the form to be submitted back to the template page to perform the validation and then display an error message or do the table insert. I would be grateful for some advice / pointers. Thanks! code below
<?php /* Template Name: Postcode Form */ get_header(); if ($_SERVER['REQUEST_METHOD']=='post') { //validate form $em=$pc=false; $pc = (isset($_POST['pc']) && strlen($_POST['pc']) == 2) ? filter_var($_POST['pc'],FILTER_SANITIZE_STRING) : false; $em = (isset($_POST['email']) ) ? filter_var($_POST['email'],FILTER_SANITIZE_EMAIL) : false; if (!$em && !$pc) { //insert to d/b //$wpdb echo '<div>No errors</div>'; } else { echo '<div>Please enter a valid postcode prefix and a valid email address</div>'; } } ?> <form id="emails" action="postcode_form.php" method="post"> <div>Enter postcode prefix(first 2 characters) <input type="text" name="pc"/></div> <div>Enter email address <input type="text" name="email" /></div> <div><input type="submit" name="submit" value="Submit" /> </form> <?php get_footer(); ?>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘form validation, integrating into WordPress’ is closed to new replies.