Step 1. Create a new page with this page template
Step 2. Fill the form, to create a post
Step 3. Check Dashboard, post added or not.
Note: You can change post type and status from here
Step 2. Fill the form, to create a post
Step 3. Check Dashboard, post added or not.
Note: You can change post type and status from here
- 'post_type' => 'post',
- 'post_status' => 'publish'
- <?php
- /**
- * Template Name: Front End Submission
- */
- get_header(); ?>
- <div id="primary" class="site-content">
- <div id="content" role="main">
- <?php
- /*
- * If sent, analyze form data and store them in variables
- */
- if (isset($_POST['submit'])) {
- $name = htmlspecialchars($_POST['myname']);
- $email = sanitize_email($_POST['myemail']);
- $message = wp_kses_post($_POST['mymessage']);
- /*
- * Create a post for post type "post"
- */
- $contact_post = array(
- 'post_title' => $name . ' | ' . $email,
- 'post_content' => $message,
- 'post_type' => 'post',
- 'post_status' => 'publish'
- );
- if (wp_insert_post($contact_post)) echo 'Post Added for admin review.<br>';
- else echo 'Try again: fill the fields';
- /*
- * Displaying the basic form
- */
- } else { ?>
- <form action="<?php echo the_permalink(); ?>" method="post">
- <label for="name">Nom complet</label>
- <input type="text" name="myname" id="name" placeholder="Votre nom" />
- <hr>
- <label for="email">Adresse e-mail</label>
- <input type="email" name="myemail" id="email" placeholder="Votre e-mail" />
- <hr>
- <label for="message">Message</label>
- <textarea cols="50" rows="10" name="mymessage" id="message" placeholder="Votre message..."></textarea>
- <br>
- <input type="submit" name="submit" value="Envoyer votre message" />
- </form>
- <?php } ?>
- </div><!-- #content -->
- </div><!-- #primary -->
- <?php get_sidebar(); ?>
- <?php get_footer(); ?>
No comments:
Post a Comment