I use wordpress as a cms. I wanted to insert custom data via a form from the frontend in my wordpress site and then echo it on a page somewhere. After learning from here and there I am able to put together a codes below which works. Here is a code of what my form looks like currently.
<form id="costing_submit_form" action="http://somesite.com/..../process-costing.php" method="post"> <input type="hidden" name="costing_submit_date" value="<?php echo $costing_submit_date;?>"/> <input type="text" id="costing_submit_title" name="costing_submit_title" size="90%" maxlength="150" /><br> <textarea id="costing_submit_description" name="costing_submit_description" size="90%" cols="60" rows="10 tabindex="15" maxlength="2000" rows="20" required="" /></textarea> <input type="submit" class="costing_submit_button" name="costing_submit_button" value="SUBMIT COSTING" /> </form>
At this point I am able to insert the data and also display it in the frontend using $wpdb. This part of the code is in
process-costing.php which inserts the data in the database table.
global $wpdb; require_once('../../../wp-load.php'); $costing_submit_date = strip_tags($_POST['costing_submit_date']); $costing_submit_title = strip_tags($_POST['costing_submit_title']); $costing_submit_description = strip_tags($_POST['costing_submit_description']); $table_name = $wpdb->prefix . "costing"; $wpdb->insert( $table_name, array( 'costing_date' => $costing_submit_date, 'costing_title' => $costing_submit_title, 'costing_description' => $costing_submit_description, ));
Now, I would like to add an image to every entry made, so how do I go about it. If not a complete solution kindly give me a road-map as to what I should be doing or following, what specific functions should I be using ? Even if I am able to upload the image. My main concern is how do I
associate the uploaded image to that particular entry...something like post-thumbnail perhaps ? If possible I would also like to
assign a particular folder to these images. Thanks in advance.