Advertisement
marjwyatt

form called by guide portal snippet

May 21st, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.85 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: sherpa edit guide
  4. */
  5. ?>
  6. <?php /* http://pastebin.com/m73LXuuG */ ?>
  7. <?php
  8. //$debug = print_r($_POST, true);
  9.   if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "edit_post" && isset($_POST['postid'])) {
  10. //    echo '1. Got here!';
  11.     $post_to_edit = array();
  12.     $post_to_edit = get_post($_POST['postid']); /* these are the fields that we are editing in the form below. you have to change them to your fields and you can add as many as you need. */
  13.     $title = $_POST['title']; // Guide Profile Name
  14.     $description = $_POST['description']; // Guide Bio
  15.     $latitude = $_POST['woo_maps_lat']; // Latitude custom field for updating map
  16.     $longitude = $_POST['woo-maps_long']; // Longitude custom field for updating map
  17.     $experience = $_POST['guide_experience_level']; // Update experience level
  18.     $training = $_POST['training_certification']; // Update certifications
  19.     $languages = $_POST['languages'];       // Update languages
  20.     $successurl = home_url('/guide-portal/');
  21.  
  22. /* this code will save the title and description into the post_to_edit array */
  23.  
  24.     $post_to_edit->post_title = $title;
  25.     $post_to_edit->post_content = $description;
  26.  
  27. /* honestly i can't really remember why i added this code but it is a must */
  28.  
  29.     $pid = wp_update_post($post_to_edit);
  30.  
  31. /* save taxonomies: post ID, form name, taxonomy name, if it appends(true) or rewrite(false) */
  32. /* here you have to change the "coupon_categories" and "coupon_tags" to the name of your taxonomies */
  33.  
  34. //  wp_set_post_terms($pid, array($_POST['cat']),'coupons_categories',false);
  35. //  wp_set_post_terms($pid, array($_POST['post_tags']),'coupons_tags',false);
  36.  
  37. //UPDATE CUSTOM FIELDS WITH THE NEW INFO
  38. //CHANGE TO YOUR CUSTOM FIELDS AND ADD AS MANY AS YOU NEED
  39.  
  40.     update_post_meta($pid, 'woo_maps_lat', $latitude); // Map latitude
  41.     update_post_meta($pid, 'woo-maps_long', $longitude); // Map longitude
  42.     update_post_meta($pid, 'guide_experience_level', $experience); // Guide Experience
  43.     update_post_meta($pid, 'training_certification', $training); // Guide Training & Certifications
  44.     update_post_meta($pid, 'languages', $languages); // Guide Languages
  45.  
  46. //REDIRECT USER WHERE EVER YOU WANT AFTER DONE EDITING
  47. // echo '2. Got here!';
  48. //  wp_redirect( 'http://sherpademo.co.cc/guide-portal/' );
  49. // header("Location: http://sherpademo.co.cc/guide-portal/");
  50.     wp_redirect( $successurl );
  51.  
  52.   } // end check for errors
  53.  
  54. ?>
  55.  
  56. <?php get_header(); ?>
  57. <?php include ( TEMPLATEPATH . '/search-form.php' ); ?>
  58. <?php $post_to_edit = get_post($_POST['postid']); ?>
  59. <div id="content" class="col-full">
  60.     <div id="main-single" class="col-left">
  61.     <div class="post">
  62. <!-- EDIT GUIDE PROFILE -->
  63.  
  64. <form id="edit_post" name="edit_post" method="post" action="" enctype="multipart/form-data">
  65.  
  66.     <!-- post name -->
  67.     <fieldset name="name">
  68.         <label for="title">Update Guide Profile Name:</label><br />
  69.         <input type="text" id="title" value="<?php echo $post_to_edit->post_title; ?>" tabindex="5" name="title" /> <!-- TITLE FIELD. NOTHING TO CHANGE -->
  70.     </fieldset>
  71.  
  72.     <!-- post Content -->
  73.     <fieldset class="content">
  74.         <label for="description">Update Bio:</label><br />
  75.         <div class="ginput_container"><textarea id="description" cols="50" rows="10" tabindex="15" name="description"><?php echo $post_to_edit->post_content; ?></textarea></div> <!-- TEXT AREA OF CONTENT. NOTHING TO CHANGE -->
  76.     </fieldset>
  77.  
  78.     <h3>Update Map Coordinates</h3>
  79.  
  80.     <!-- BELOW ARE THE CUSTOM FIELDS. CHANGE THEM ADD OR REMOVE -->
  81.  
  82.     <fieldset class="woo_maps_lat">
  83.         <label for="woo_maps_lat">Latitude:</label><br />
  84.         <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'woo_maps_lat', true); ?>" id="woo_maps_lat" tabindex="20" name="woo_maps_lat" /> <!-- Map Latitude -->
  85.     </fieldset>
  86.  
  87.     <fieldset class="woo_maps_long">
  88.         <label for="woo_maps_long">Longitude:</label><br />
  89.         <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'woo_maps_long', true); ?>" id="woo_maps_long" tabindex="21" name="woo_maps_long" /> <!-- Map Longitude -->
  90.     </fieldset>
  91.  
  92.     <h3>Update Profile Details</h3>
  93.  
  94.     <fieldset class="guide_experience_level">
  95.         <label for="guide_experience_level">Update Experience:</label><br />
  96.         <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'guide_experience_level', true); ?>" id="guide_experience_level" tabindex="22" name="guide_experience_level" /> <!-- Guide Experience -->
  97.     </fieldset>
  98.  
  99.     <fieldset class="training_certification">
  100.         <label for="training_certification">Update Certifications & Training:</label><br />
  101.         <div class="ginput_container"><textarea id="training_certification" cols="50" rows="10" tabindex="23" name="training_certification"><?php echo get_post_meta($post_to_edit->ID,'training_certification', true); ?></textarea></div> <!-- Guide Certifications & Training -->
  102.     </fieldset>
  103.  
  104.     <fieldset class="languages">
  105.         <label for="languages">Update Languages:</label><br />
  106.         <div class="ginput_container"><textarea id="languages" cols="50" rows="10" tabindex="24" name="languages"><?php echo get_post_meta($post_to_edit->ID,'languages', true); ?></textarea></div> <!-- Guide Languages -->
  107.     </fieldset>
  108.  
  109.     <fieldset class="submit">
  110.         <input type="submit" value="Update Profile" class="button gform_button" tabindex="40" id="submit" name="submit" /> <!-- SUBMIT BUTTON -->
  111.     </fieldset>
  112.     <input type="hidden" name="postid" value="<?php echo $post_to_edit->ID; ?>" /> <!-- DONT REMOVE OR CHANGE -->
  113.     <input type="hidden" name="action" value="edit_post" />                         <!-- DONT REMOVE OR CHANGE -->
  114.     <input type='hidden' name='redirect_to' id='redirect_to' value='http://sherpademo.co.cc/guide-portal/' />
  115.     <?php // wp_nonce_field( 'new-post' ); ?>
  116. </form>
  117.     <!-- END OF FORM -->
  118.  
  119.     </div><!-- post -->
  120.     </div><!-- main-single -->
  121.     <?php get_sidebar(); ?>
  122.     </div><!-- #content -->
  123.  
  124. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement