php - Form data and image preview after form submit -


i use wordpress cms , need custom made form. allow users post front-end. there couple of fields , image upload field. 2 part form first part submits data , second step gets preview of data submitted. please remember this happens after submit.

form code :

<?php     global $wpdb;     $this_page  =   $_server['request_uri'];     $page       =   $_post['page'];     if ( $page == null ) { ?>   <form method="post" action="">  <div>location : <input type="text" name="location"/></div>  <div>description : <textarea id="details" cols="80" rows="10 maxlength="600" name="details" rows="20"></textarea></div>  <div>upload image : <input type="file" name="loc-image" id="loc-image" tabindex="25" /></div>   <input type="hidden" value="1" name="page" /> <input type="hidden" name="action" value="post_action" /> <input type="submit" name="submit" value="proceed"/> </form>  <?php  } else if ( $page == 1 ) { ?>   <?php  $location=$_post['location']; $description=$_post['details']; $photo=$_post['loc-image'];  echo 'location : ' . $location . '</br>'; echo 'details  : ' . $description . '</br>';  echo 'image    : ' . $photo . '</br></br>'; ?> <?php } ?> 

issue : in last step, current code able display submitted data along image name, not image. display image @ point. basically, need last step sort of preview-page.

code given below processes form , pull attention particularly specific part of code helps insert attachments, may devise solution.

form processor :

   if( 'post' == $_server['request_method'] &&  $_post['action'] == "post_action") {                  //some error checking done here                  //set vars                 $location       =  $_post['location'];                 $description =  $_post['details'];                   if (empty($error)) {                    $new_post = array(   //insert form inputs, set var , define array                 'post_title'    =>  $location,                  'post_content'  =>  $description,                 'post_status'   =>  'draft',                  'post_type' =>  'post',                   // assigning tags , categoris no issue                 );                  $pid = wp_insert_post($new_post);                                          //attachment helper function                                             function insert_attachment($file_handler,$post_id,$setthumb='false') {                                              if ($_files[$file_handler]['error'] !== upload_err_ok){ return __return_false();                                              }                                              require_once(abspath . "wp-admin" . '/includes/image.php');                                             require_once(abspath . "wp-admin" . '/includes/file.php');                                             require_once(abspath . "wp-admin" . '/includes/media.php');                                              $attach_id = media_handle_upload( $file_handler, $post_id );                                              //set post thumbnail                                             if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id);                                             return $attach_id;                                             }                                           //insert our media attachments                                         if ($_files) {                                         foreach ($_files $file => $array) {                                         $newupload = insert_attachment($file,$pid);                                         // $newupload returns attachment id of file                                         // uploaded. whatever want now.                                         }                                         } // end of attachment statement     }     } 

footnote : other issue code has been heavily customized , works on wp-install. so, please ignore secondary factors in code eg. validations, security etc.

if right didn't save image in temp folder first save temp folder , display image on preview page using image path [drive name]:/[folder name] /[img_path]

after submission form, remove image temp folder , saved orginal folder.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -