Advertisement
Guest User

Front-end post submission redirect

a guest
Jan 26th, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.61 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Submit Work
  4. */
  5. ?>
  6.  
  7. <?php get_header() ?>
  8.  
  9.     <div id="content" class="two_column">
  10.         <div class="padder">
  11.   <h1 class="page_title">Works<span class="work_logo"></span></h1>      
  12.  
  13.         <?php do_action( 'bp_before_blog_page' ) ?>
  14.  
  15.         <div class="page" id="blog-page" role="main">
  16.         <h2 class="posttitle">Submit Work</h2>
  17.  
  18. <!--SUBMIT POST-->
  19. <div id="postBox">
  20. <?php
  21.  
  22. // Check if the form was submitted
  23. if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {
  24.        
  25.         // Do some minor form validation to make sure there is content
  26.         if (isset ($_POST['title'])) {
  27.                 $title =  $_POST['title'];
  28.         } else {
  29.                 echo 'Please enter a title';
  30.         }
  31.         if (isset ($_POST['description'])) {
  32.                 $description = htmlentities(trim(stripcslashes($_POST['description'])));
  33.     } else {
  34.         echo 'Please enter the content';
  35.         }
  36.  
  37.         // Add the content of the form to $post as an array
  38.         $type = trim($_POST['Type']);
  39.         $post = array(
  40.                 'post_title'    => $title,
  41.                 'post_content'  => $description,
  42.  
  43.                 'post_status'   => 'pending',                     // Choose: publish, preview, future, etc.
  44.                 'post_type'     => 'work',  // Use a custom post type if you want to
  45.                 'tax_input'    => array( $type)
  46.         );
  47.         $post_id = wp_insert_post($post);
  48.         wp_redirect( 'http://localhost/buddypress/thank-you' );
  49.             wp_set_post_terms($post_id,$type,'Type',true);
  50.             if ($_FILES) {
  51.     foreach ($_FILES as $file => $array) {
  52.     $newupload = insert_attachment($file,$post_id);
  53.     // $newupload returns the attachment id of the file that
  54.     // was just uploaded. Do whatever you want with that now.
  55.     }
  56. }
  57.                
  58.  
  59. } // end IF
  60. // Do the wp_insert_post action to insert it
  61. do_action('wp_insert_post', 'wp_insert_post');
  62. ?>
  63.  
  64.         <form id="new_post" name="new_post" class="post_work" method="post" enctype="multipart/form-data">
  65.                 <p><label for="title">Title</label><br />
  66.                 <input type="text" id="title" class="required" value="" tabindex="1" size="20" name="title" />
  67.                 </p>
  68.                 <p><label for="description">Description</label><br />
  69.                 <textarea id="description" type="text" class="required" tabindex="3" name="description" cols="50" rows="6"></textarea>
  70.                 </p>
  71.                 <p align="right"><input type="submit" value="Submit" tabindex="6" id="submit" name="submit" /></p>
  72.                 <p class="post_category"><label for="category">Category</label>
  73.                 <?php wp_dropdown_categories('taxonomy=Type&hide_empty=0&orderby=name&order=asc&name=Type') ?></p>
  74.                
  75.                 <div style="clear:both;"></div>
  76. <p><label for="attachment">Photos: </label><input type="file" id="attachment">
  77. <div id="attachment_list"></div></p>
  78.  
  79.                
  80.                
  81.                 <input type="hidden" name="post_type" id="post_type" value="domande" />
  82.                 <input type="hidden" name="action" value="post" />
  83.  
  84.                 <?php wp_nonce_field( 'new-post' ); ?>
  85.         </form>
  86.  
  87. </div>
  88. <script>
  89.     var multi_selector = new MultiSelector( document.getElementById( 'attachment_list' ), 8 );
  90.     multi_selector.addElement( document.getElementById( 'attachment' ) );
  91. </script>
  92.  
  93. <!--SUBMIT POST END-->
  94.  
  95.         </div><!-- .page -->
  96.  
  97.         <?php do_action( 'bp_after_blog_page' ) ?>
  98.  
  99.         </div><!-- .padder -->
  100.     </div><!-- #content -->
  101.  
  102.     <?php locate_template( array( 'sidebar-work.php' ), true ) ?>
  103.  
  104. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement