Note that there are some explanatory texts on larger screens.

plurals
  1. POForm data and image preview after form submit
    primarykey
    data
    text
    <p>I use wordpress cms and I need help with a custom made form. It allow users to post from front-end. There are a couple of fields and a image upload field. It is a two part form where the first part is where he submits data and second step where he gets a preview of data he just submitted. Please remember that <strong>this happens after the submit</strong>.</p> <p><strong>FORM CODE :</strong></p> <pre><code>&lt;?php global $wpdb; $this_page = $_SERVER['REQUEST_URI']; $page = $_POST['page']; if ( $page == NULL ) { ?&gt; &lt;form method="post" action=""&gt; &lt;div&gt;LOCATION : &lt;input type="text" name="location"/&gt;&lt;/div&gt; &lt;div&gt;DESCRIPTION : &lt;textarea id="details" cols="80" rows="10 maxlength="600" name="details" rows="20"&gt;&lt;/textarea&gt;&lt;/div&gt; &lt;div&gt;UPLOAD IMAGE : &lt;input type="file" name="loc-image" id="loc-image" tabindex="25" /&gt;&lt;/div&gt; &lt;input type="hidden" value="1" name="page" /&gt; &lt;input type="hidden" name="action" value="post_action" /&gt; &lt;input type="submit" name="submit" value="PROCEED"/&gt; &lt;/form&gt; &lt;?php } else if ( $page == 1 ) { ?&gt; &lt;?php $location=$_POST['location']; $description=$_POST['details']; $photo=$_POST['loc-image']; echo 'Location : ' . $location . '&lt;/br&gt;'; echo 'Details : ' . $description . '&lt;/br&gt;'; echo 'Image : ' . $photo . '&lt;/br&gt;&lt;/br&gt;'; ?&gt; &lt;?php } ?&gt; </code></pre> <p>ISSUE : In the last step, my current code is able to display all submitted data along with the image name, but NOT the image. I would like to <strong>display the image</strong> at this point. Basically, I need the last step to be sort of a preview-page.</p> <p>Code given below processes the form and I would like to pull your attention particularly to the specific part of the code which helps insert attachments, as it may help devise a solution.</p> <p><strong>FORM PROCESSOR :</strong></p> <pre><code> if( 'POST' == $_SERVER['REQUEST_METHOD'] &amp;&amp; $_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 and define array 'post_title' =&gt; $location, 'post_content' =&gt; $description, 'post_status' =&gt; 'draft', 'post_type' =&gt; 'post', // assigning tags and categoris is 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 as $file =&gt; $array) { $newupload = insert_attachment($file,$pid); // $newupload returns the attachment id of the file that // was just uploaded. Do whatever you want with that now. } } // end of attachment statement } } </code></pre> <p>Footnote : Other than the issue the code has been heavily customized and works well on my wp-install. So, please ignore secondary factors in the code eg. validations, security etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload