Parse error: syntax error, unexpected T

I do not know, what is wrong with this code:

function my_wpcf7_save($cfdata) {

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

if ( $formtitle == 'contactform1') {

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

    // create a new post
    $newpost = array( 
                  'post_title' -> $formdata['name']);
                  'post_content' -> $formdata['message']);
                  'post_status' -> 'publish');

    $newpostid = wp_insert_post($newpost);

    // add meta data for the new post
    add_post_meta($newpostid, 'email', $formdata['email']);
    add_post_meta($newpostid, 'subject', $formdata['subject']);
}

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

I got the error: Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ')' ... for this line: 'post_title' -> $formdata['name']);

As far as I know, the syntax is right, isn't it?


Please read the comment from mario in your question:

// create a new post
$newpost = array( 
              'post_title' => $formdata['name'],  <------------------ Here
              'post_content' => $formdata['message'], <-------------- Here
              'post_status' => 'publish');

Update: Also replace -> with => , as shown above.


I'm pretty sure this:

$newpost = array( 
  'post_title' -> $formdata['name']);
  'post_content' -> $formdata['message']);
  'post_status' -> 'publish');

should be:

$newpost = array( 
  'post_title' => $formdata['name'],
  'post_content' => $formdata['message'],
  'post_status' => 'publish');

As it was you were closing the array and statement before you were actually finished declaring the array. That's what I think you were trying to do atleast.

链接地址: http://www.djcxy.com/p/69442.html

上一篇: 语法错误,意外的T

下一篇: 解析错误:语法错误,意外的T