Jump to content

Recommended Posts

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.

 

dRjCS.jpg

 

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!

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 by Ch0cu3r

 

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.