0

I'm using a custom form in CTools Modal to alter comment.

$form['subject'] = array(
   '#type' => 'textfield',
   '#title' => t('Title'),
   '#default_value' => $comment->subject,
);  
$form['comment_body'] = array(
   '#type' => 'text_format',
   '#default_value' => $comment->comment_body['und'][0]['value']
);

All is good. I get my comment title and my comment body which is pushed in ckeditor field. My submit :

$comment = comment_load($form_state['values']['cid']);
$comment->comment_body['und'][0]['value'] = $form_state['values']['comment_body']['und'][0]['value'];
$comment->subject = $form_state['values']['title'];

comment_submit($comment);
comment_save($comment);

The subject is goodly saved from my form but for the body, it save an empty value.

Ps: when I change text_format for textfield, it work.

0

You forgot to add the format:

$comment->comment_body[LANGUAGE_NONE][0]['format'] = $form_state['values']['comment_body'][LANGUAGE_NONE][0]['format'];
  • Even with this line, it save me an empty value. Maybe something to know, when in my validate I put a form_set_error in $form_state['values']['comment_body'] == '' it doesn't pass even if i let the comment input form empty. – guish Apr 13 '17 at 16:22
  • And you've confirmed that the form state array contains the elements you're trying to access? – Clive Apr 13 '17 at 16:46
  • Haha, your comment gave me an illumination : it was $form_state['values']['comment_body']['value'] missed this final value so, in the submit it looks like : $comment->comment_body['und'][0]['value'] = $form_state['values']['comment_body']['value']; (same thing for format). Thanks you @Clive – guish Apr 13 '17 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.