Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Template Name: Testing Submission Form
- */
- ?>
- <?php
- // Check if the form was submitted
- if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {
- // Do some minor form validation to make sure there is content
- if (isset ($_POST['title'])) {
- $title = $_POST['title'];
- } else {
- echo 'Please enter a title';
- }
- if (isset ($_POST['description'])) {
- $description = htmlentities(trim(stripcslashes($_POST['description'])));
- } else {
- echo 'Please enter the content';
- }
- $tags = $_POST['post_tags'];
- $listingemail = $_POST['listingemail'];
- $listingphone = $_POST['listingphone'];
- $dogwalking = $_POST['dogwalking'];
- $onedogwalks = $_POST['onedogwalks'];
- $groupwalks = $_POST['groupwalks'];
- $boardingsitting = $_POST['boardingsitting'];
- $doggydaycare = $_POST['doggydaycare'];
- $otheranimals = $_POST['otheranimals'];
- // Add the content of the form to $post as an array
- $type = trim($_POST['Type']);
- $post = array(
- 'post_title' => $title,
- 'post_content' => $description,
- 'post_category' => array($_POST['cat']), // Usable for custom taxonomies too
- 'post_status' => 'pending', // Choose: publish, preview, future, etc.
- 'tags_input' => array($tags),
- 'tax_input' => array( $type),
- 'comment_status' => 'closed',
- 'post_author' => '2',
- 'listingemail' => $listingemail,
- 'listingphone' => $listingphone,
- 'dogwalking' => $dogwalking,
- 'onedogwalks' => $onedogwalks,
- 'groupwalks' => $groupwalks,
- 'boardingsitting' => $boardingsitting,
- 'doggydaycare' => $doggydaycare,
- 'otheranimals' => $otheranimals
- );
- $post_id = wp_insert_post($post);
- wp_set_post_terms($post_id,$type,'Type',true);
- add_post_meta($post_id, 'metatestemail', $listingemail, false);
- add_post_meta($post_id, 'metatestphone', $listingphone, false);
- add_post_meta($post_id, 'metadogwalking', $dogwalking, false);
- add_post_meta($post_id, 'metaonedogwalks', $onedogwalks, false);
- add_post_meta($post_id, 'metagroupwalks', $groupwalks, false);
- add_post_meta($post_id, 'metaboardingsitting', $boardingsitting, false);
- add_post_meta($post_id, 'metadoggdaycare', $doggydaycare, false);
- add_post_meta($post_id, 'metaotheranimals', $otheranimals, false);
- wp_redirect( home_url('/listing-submitted/') ); // redirect to home page after submit
- exit();
- if ($_FILES) {
- foreach ($_FILES as $file => $array) {
- $newupload = insert_attachment($file,$post_id);
- // $newupload returns the attachment id of the file that
- // was just uploaded. Do whatever you want with that now.
- }
- }
- }
- // end IF
- ?>
- <?php get_header() ?>
- <div id="container">
- <div id="content" role="main">
- <h1 class="page-title">Submit your listing</h1>
- <!--SUBMIT POST-->
- <form id="new_post" name="new_post" class="post_work" method="post" enctype="multipart/form-data">
- <p><label for="title">Title</label><br />
- <input type="text" id="title" class="required" value="" tabindex="1" size="20" name="title" />
- </p>
- <p><label for="description">Description</label><br />
- <textarea id="description" type="text" class="required" tabindex="3" name="description" cols="50" rows="6"></textarea>
- </p>
- <fieldset class="category">
- <label for="cat">Type:</label>
- <?php wp_dropdown_categories( 'tab_index=10&taxonomy=category&hide_empty=0' ); ?>
- </fieldset>
- <!-- Listing Email -->
- <fieldset class="listingemail">
- <label for="listingemail">Your Email</label>
- <input type="text" value="" id="listingemail" tabindex="20" name="listingemail" />
- </fieldset>
- <!-- Listing Phone -->
- <fieldset class="listingphone">
- <label for="listingphone">Your Phone</label>
- <input type="text" value="" id="listingphone" tabindex="20" name="listingphone" />
- </fieldset>
- <!-- Listing Services -->
- <fieldset class="dogwalking">
- <label for="dogwalking">Dog walking: </label>
- <input type="radio" value="yes" name="dogwalking" id="dogwalking"> YES
- <input type="radio" value="no" name="dogwalking" id="dogwalking"> NO<br />
- </fieldset>
- <fieldset class="onedogwalks">
- <label for="onedogwalks">One dog walks: </label>
- <input type="radio" value="yes" name="onedogwalks" id="onedogwalks"> YES
- <input type="radio" value="no" name="onedogwalks" id="onedogwalks"> NO<br />
- </fieldset>
- <fieldset class="groupwalks">
- <label for="groupwalks">Group walks: </label>
- <input type="radio" value="yes" name="groupwalks" id="groupwalks"> YES
- <input type="radio" value="no" name="groupwalks" id="groupwalks"> NO<br />
- </fieldset>
- <fieldset class="boardingsitting">
- <label for="boardingsitting">Dog boarding/sitting: </label>
- <input type="radio" value="yes" name="boardingsitting" id="boardingsitting"> YES
- <input type="radio" value="no" name="boardingsitting" id="boardingsitting"> NO<br />
- </fieldset>
- <fieldset class="doggydaycare">
- <label for="doggydaycare">Doggy daycare: </label>
- <input type="radio" value="yes" name="doggydaycare" id="doggydaycare"> YES
- <input type="radio" value="no" name="doggydaycare" id="doggydaycare"> NO<br />
- </fieldset>
- <fieldset class="otheranimals">
- <label for="otheranimals">Other animals: </label>
- <input type="radio" value="yes" name="otheranimals" id="otheranimals"> YES
- <input type="radio" value="no" name="otheranimals" id="otheranimals"> NO<br />
- </fieldset>
- <!-- <p><label for="attachment">Photos: </label>
- <input type="file" id="attachment">
- <div id="attachment_list"></div></p>
- -->
- <p>Tags: <input type="text" value="" tabindex="35" name="post_tags" id="post_tags" /></p>
- <input type="hidden" name="post_type" id="post_type" value="domande" />
- <input type="hidden" name="action" value="post" />
- <p align="right"><input type="submit" value="Submit" tabindex="6" id="submit" name="submit" /></p>
- <?php wp_nonce_field( 'new-post' ); ?>
- </form>
- <script>
- var multi_selector = new MultiSelector( document.getElementById( 'attachment_list' ), 8 );
- multi_selector.addElement( document.getElementById( 'attachment' ) );
- </script>
- <!--SUBMIT POST END-->
- </div><!-- .content -->
- </div><!-- #container -->
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement