logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$5
Contact form 7 action hook tweak

Ive made an action hook inside the functions.php of my theme for contact form 7 plugin for Wordpress so that when someone fills out a specific form, it automatically creates a draft post using the details they provide.

However i have only figured out how to use a single form entry field for the post_content, i was wondering if someone could provide the code change required to use the following 3 formdata fields for the "postcontent" section: [time] [location] [webcon]

Here is the code:

function my_wpcf7_save($cfdata) {

$formtitle = $cfdata->title;
$formdata = $cfdata->posted_data;

if ( $formtitle == 'noticeboard') {

// access data from the submitted form
$formfield = $formdata['post'];

// create a new post
$newpost = array( 'post_title' => $formdata['title'],
'post_content' => $formdata['webcon'],
'post_status' => 'draft');

$newpostid = wp_insert_post($newpost);

// add meta data for the new post
add_post_meta($newpostid, 'custom-field1', $formdata['your-name']);

}

}
add_action('wpcf7_before_send_mail', 'my_wpcf7_save',1);

?>


As an extra, not as important aspect, if there is a way to get this hook to also take the image they upload and set it as featured image that would be great; if someone can supply that also i will reward extra money

This question has been answered.

tokenofhon | 02/06/13 at 10:06pm Edit
Tutorial: How to assign prize money


(5) Responses

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    02/07/13
    2:45am
    Arnav Joy says:

    what to you mean by " 3 formdata fields for the "postcontent" section: [time] [location] [webcon]"

    can you give an example to help understand you better?

  • avatar
    Last edited:
    02/07/13
    2:53am
    tokenofhon says:

    See this part in the code:

    // create a new post

    $newpost = array( 'post_title' => $formdata['title'],

    'post_content' => $formdata['webcon'],

    'post_status' => 'draft');


    [webcon] is a formsata from the contact form 7, e.g. formfield is Name: and in the backend whatever they enter in that textbox is known as [name] or whatever i decide to call it

    In this instance, [webcon] comes from the "enter your content for the website" text area.

    the line 'post_content' => $formdata['webcon'],

    the php hook grabs the data filled out by the user in the form which has been named [webcon] and posts this in the post content area in wordpress.

    what i want to do is grab data from 3 of these formfields and have it put them all in the post content area.

    the 3 formfields are [time [location] and [webcon]

  • avatar
    Last edited:
    02/07/13
    2:53am
    tokenofhon says:

    formdata*

  • avatar
    Last edited:
    02/07/13
    4:51am
    Arnav Joy says:

    you can try it as

    $newpost = array( 'post_title' => $formdata['title'],



    'post_content' =>$formdata['time'].' '.$formdata['location'].' '. $formdata['webcon'],



    'post_status' => 'draft');

  • avatar
    Last edited:
    02/07/13
    4:56am
    tokenofhon says:

    That worked! thankyou so much, been trying to figure this out for days xD

    One little thing; is there a way to get it to seperate each one with an enter ( ) rather than a space?

    If not thats fine, it can be done manually in the posts

This question has expired.



Arnav Joy had additional discourse to offer.

Gabriel Reguly, Francisco Javier Carazo Gil, tokenofhon voted on this question.



Current status of this question: Completed



Please log in to add additional discourse to this page.





Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.