KJThaDon Posted February 20, 2014 Share Posted February 20, 2014 I have a form, with multiple inputs that I am trying to get posted to the wordpress "post_content". I am able to get the title field and only one other field to post successfully, only when making a field name "description" instead of "description[]", but have no idea how I can get the rest to submit into the post_content. I would like the inputs posted like the image I have created below. Here is the code I currently have that works for the title only. <?php /* Template Name: Question Form */ ?> <?php if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_post") { if (isset ($_POST['title'])) { $title = $_POST['title']; } else { echo 'Please enter a title'; } if (isset ($_POST['description'])) { $description = $_POST['description']; } else { echo 'Please enter the content'; } $tags = $_POST['post_tags']; $new_post = array( 'post_title' => $title, 'post_content' => $_POST['description'], 'post_parent' => 599, 'post_status' => 'publish', 'post_type' => 'topic' ); $topic_meta = array( 'forum_id' => $new_post['post_parent'] ); $topic_id = bbp_insert_topic($new_post, $topic_meta); wp_redirect(get_permalink($topic_id)); exit; } ?> <form id="new_post" name="new_post" method="post" action=""> <p class="question"><label>Title</label><input name="title" type="text"></p> <p class="question"><label>Description</label><input name="description[]" type="text"></p> <p class="question"><label>Your First Name</label><input name="description[]" type="text"></p> <p class="question"><label>Your Last Name</label><input name="description[]" type="text"></p> <p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p> <input type="hidden" name="action" value="new_post" /> <?php wp_nonce_field( 'new-post' ); ?> </form> I don't know how to add the other fields to be a part of post_content. I have tried a few other things, but have been unsuccessful. I would appreciate any help very much! Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 20, 2014 Share Posted February 20, 2014 (edited) Change <p class="question"><label>Description</label><input name="description[]" type="text"></p> <p class="question"><label>Your First Name</label><input name="description[]" type="text"></p> <p class="question"><label>Your Last Name</label><input name="description[]" type="text"></p> to <p class="question"><label>Description</label><input name="description" type="text"></p <p class="question"><label>Your First Name</label><input name="firstName" type="text"></p> <p class="question"><label>Your Last Name</label><input name="lastName" type="text"></p> Now get the description with $_POST['description'], the first name with $_POST['firstName'] and the last name with $_POST['lastName'] You'll then define 'post_content' using $post_content = '<p>Description: ' . $_POST['description'] . '</p>'. '<p>First Name: ' . $_POST['firstName'] . '</p>'. '<p>Last Name: ' . $_POST['lastName'] . '</p>'; ... $new_post = array( 'post_title' => $title, 'post_content' => $post_content, ... ); Edited February 20, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
KJThaDon Posted February 20, 2014 Author Share Posted February 20, 2014 Change <p class="question"><label>Description</label><input name="description[]" type="text"></p> <p class="question"><label>Your First Name</label><input name="description[]" type="text"></p> <p class="question"><label>Your Last Name</label><input name="description[]" type="text"></p> to <p class="question"><label>Description</label><input name="description" type="text"></p <p class="question"><label>Your First Name</label><input name="firstName" type="text"></p> <p class="question"><label>Your Last Name</label><input name="lastName" type="text"></p> Now get the description with $_POST['description'], the first name with $_POST['firstName'] and the last name with $_POST['lastName'] You'll then define 'post_content' using $post_content = '<p>Description: ' . $_POST['description'] . '</p>'. '<p>First Name: ' . $_POST['firstName'] . '</p>'. '<p>Last Name: ' . $_POST['lastName'] . '</p>'; ... $new_post = array( 'post_title' => $title, 'post_content' => $post_content, ... ); You are my hero lol, thank you so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.