Advertisement
Guest User

Untitled

a guest
Aug 27th, 2012
3,977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.07 KB | None | 0 0
  1. <?php
  2.     /*
  3.     Template Name: Testing Submission Form
  4.     */
  5. ?>
  6. <?php
  7. // Check if the form was submitted
  8. if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {
  9.  
  10.         // Do some minor form validation to make sure there is content
  11.         if (isset ($_POST['title'])) {
  12.                 $title =  $_POST['title'];
  13.         } else {
  14.                 echo 'Please enter a title';
  15.         }
  16.         if (isset ($_POST['description'])) {
  17.                 $description = htmlentities(trim(stripcslashes($_POST['description'])));
  18.     } else {
  19.         echo 'Please enter the content';
  20.         }
  21.  
  22.         $tags = $_POST['post_tags'];
  23.         $listingemail = $_POST['listingemail'];
  24.         $listingphone = $_POST['listingphone'];
  25.         $dogwalking = $_POST['dogwalking'];
  26.         $onedogwalks = $_POST['onedogwalks'];
  27.         $groupwalks = $_POST['groupwalks'];
  28.         $boardingsitting = $_POST['boardingsitting'];
  29.         $doggydaycare = $_POST['doggydaycare'];
  30.         $otheranimals = $_POST['otheranimals'];
  31.  
  32.         // Add the content of the form to $post as an array
  33.         $type = trim($_POST['Type']);
  34.         $post = array(
  35.                 'post_title'    => $title,
  36.                 'post_content'  => $description,
  37.                 'post_category' =>   array($_POST['cat']),  // Usable for custom taxonomies too
  38.                 'post_status'   => 'pending',                     // Choose: publish, preview, future, etc.
  39.                 'tags_input'    => array($tags),
  40.                 'tax_input'    => array( $type),
  41.                 'comment_status' => 'closed',
  42.                 'post_author' => '2',
  43.                 'listingemail'    =>   $listingemail,
  44.                 'listingphone'    =>   $listingphone,
  45.                 'dogwalking'    =>   $dogwalking,
  46.                 'onedogwalks'    =>   $onedogwalks,
  47.                 'groupwalks'    =>   $groupwalks,
  48.                 'boardingsitting'    =>   $boardingsitting,
  49.                 'doggydaycare'    =>   $doggydaycare,
  50.                 'otheranimals'    =>   $otheranimals
  51.         );
  52.         $post_id = wp_insert_post($post);
  53.         wp_set_post_terms($post_id,$type,'Type',true);
  54.     add_post_meta($post_id, 'metatestemail', $listingemail, false);
  55.     add_post_meta($post_id, 'metatestphone', $listingphone, false);
  56.     add_post_meta($post_id, 'metadogwalking', $dogwalking, false);
  57.     add_post_meta($post_id, 'metaonedogwalks', $onedogwalks, false);
  58.     add_post_meta($post_id, 'metagroupwalks', $groupwalks, false);
  59.     add_post_meta($post_id, 'metaboardingsitting', $boardingsitting, false);
  60.     add_post_meta($post_id, 'metadoggdaycare', $doggydaycare, false);
  61.     add_post_meta($post_id, 'metaotheranimals', $otheranimals, false);
  62.         wp_redirect( home_url('/listing-submitted/') ); // redirect to home page after submit
  63.         exit();
  64.  
  65.             if ($_FILES) {
  66.                 foreach ($_FILES as $file => $array) {
  67.                     $newupload = insert_attachment($file,$post_id);
  68.                     // $newupload returns the attachment id of the file that
  69.                     // was just uploaded. Do whatever you want with that now.
  70.                 }
  71.         }
  72. }
  73.  // end IF
  74.  
  75. ?>
  76. <?php get_header() ?>
  77.  
  78.             <div id="container">
  79.                 <div id="content" role="main">
  80.  
  81.                 <h1 class="page-title">Submit your listing</h1>
  82.  
  83. <!--SUBMIT POST-->
  84.                 <form id="new_post" name="new_post" class="post_work" method="post" enctype="multipart/form-data">
  85.                         <p><label for="title">Title</label><br />
  86.                             <input type="text" id="title" class="required" value="" tabindex="1" size="20" name="title" />
  87.                         </p>
  88.                         <p><label for="description">Description</label><br />
  89.                             <textarea id="description" type="text" class="required" tabindex="3" name="description" cols="50" rows="6"></textarea>
  90.                         </p>
  91.  
  92.                     <fieldset class="category">
  93.                             <label for="cat">Type:</label>
  94.                             <?php wp_dropdown_categories( 'tab_index=10&taxonomy=category&hide_empty=0' ); ?>
  95.                 </fieldset>
  96.  
  97. <!-- Listing Email -->
  98.                 <fieldset class="listingemail">
  99.                     <label for="listingemail">Your Email</label>
  100.                             <input type="text" value="" id="listingemail" tabindex="20" name="listingemail" />
  101.                 </fieldset>
  102.  
  103. <!-- Listing Phone -->
  104.                 <fieldset class="listingphone">
  105.                     <label for="listingphone">Your Phone</label>
  106.                     <input type="text" value="" id="listingphone" tabindex="20" name="listingphone" />
  107.                 </fieldset>
  108.  
  109. <!-- Listing Services -->
  110.                 <fieldset class="dogwalking">
  111.                             <label for="dogwalking">Dog walking: </label>
  112.                     <input type="radio" value="yes" name="dogwalking" id="dogwalking"> YES
  113.                     <input type="radio" value="no" name="dogwalking" id="dogwalking"> NO<br />
  114.                 </fieldset>
  115.  
  116.                 <fieldset class="onedogwalks">
  117.                     <label for="onedogwalks">One dog walks: </label>
  118.                     <input type="radio" value="yes" name="onedogwalks" id="onedogwalks"> YES
  119.                     <input type="radio" value="no" name="onedogwalks" id="onedogwalks"> NO<br />
  120.                 </fieldset>
  121.  
  122.                 <fieldset class="groupwalks">
  123.                     <label for="groupwalks">Group walks: </label>
  124.                     <input type="radio" value="yes" name="groupwalks" id="groupwalks"> YES
  125.                     <input type="radio" value="no" name="groupwalks" id="groupwalks"> NO<br />
  126.                 </fieldset>
  127.  
  128.                 <fieldset class="boardingsitting">
  129.                     <label for="boardingsitting">Dog boarding/sitting: </label>
  130.                     <input type="radio" value="yes" name="boardingsitting" id="boardingsitting"> YES
  131.                     <input type="radio" value="no" name="boardingsitting" id="boardingsitting"> NO<br />
  132.                 </fieldset>
  133.  
  134.                 <fieldset class="doggydaycare">
  135.                     <label for="doggydaycare">Doggy daycare: </label>
  136.                     <input type="radio" value="yes" name="doggydaycare" id="doggydaycare"> YES
  137.                     <input type="radio" value="no" name="doggydaycare" id="doggydaycare"> NO<br />
  138.                 </fieldset>
  139.  
  140.                 <fieldset class="otheranimals">
  141.                     <label for="otheranimals">Other animals: </label>
  142.                     <input type="radio" value="yes" name="otheranimals" id="otheranimals"> YES
  143.                     <input type="radio" value="no" name="otheranimals" id="otheranimals"> NO<br />
  144.                 </fieldset>
  145.  
  146. <!--                <p><label for="attachment">Photos: </label>
  147.                     <input type="file" id="attachment">
  148.                     <div id="attachment_list"></div></p>
  149. -->
  150.  
  151.                 <p>Tags: <input type="text" value="" tabindex="35" name="post_tags" id="post_tags" /></p>
  152.                 <input type="hidden" name="post_type" id="post_type" value="domande" />
  153.                 <input type="hidden" name="action" value="post" />
  154.  
  155.                 <p align="right"><input type="submit" value="Submit" tabindex="6" id="submit" name="submit" /></p>
  156.  
  157.                         <?php wp_nonce_field( 'new-post' ); ?>
  158.             </form>
  159.  
  160.             <script>
  161.                 var multi_selector = new MultiSelector( document.getElementById( 'attachment_list' ), 8 );
  162.                 multi_selector.addElement( document.getElementById( 'attachment' ) );
  163.             </script>
  164.  
  165. <!--SUBMIT POST END-->
  166.  
  167.             </div><!-- .content -->
  168.         </div><!-- #container -->
  169.  
  170. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement