Olli Bolli
Olli Bolli

Reputation: 347

Drupal 7 db_insert on WYSIWYG textarea field

this is my first post here at stackoverflow and i'll try make sharp and short ;-)

I am running into problems when inserting a textarea form field using CKeditor into the database.

Here is my form element:

    $form['add']['description'] = array(
    '#wysiwyg' => true,
    '#name' => 'description',
    '#title' => t('description'),
    '#type' => 'text_format',
    '#base_type' => 'textarea',
);

When submitting the form i do get a SQL error like this because Drupal appends the placeholder elements 'value' and 'format'

db_insert failed. Message = SQLSTATE[21S01]: 
Insert value list does not match column list: 
1136 Column count doesn't match value count at row 1, 
query= INSERT INTO {tablename} (description) 
VALUES (:db_insert_placeholder_13_value, :db_insert_placeholder_13_format)

Unfortunately i exactly have to set up the textarea this way to make the CKeditor work. Can you advice me how to get rid of the :db_insert_placeholder_13_value, :db_insert_placeholder_13_format to a single variable again?

I really appriciate your help

PROBLEM SOLVED --- silly me, should have used my glasses more :-D

Just use the correct array index inside the submit hook for saving the data to the database and it will work:

function MYMODULE_form_add_submit($form, &$form_state) {
...
'description' => $form_state['values']['description']['value'], 
...
}

Upvotes: 2

Views: 839

Answers (1)

Clive
Clive

Reputation: 36957

If you're just interested in the text itself (not the format), add a validation handler for the form and use something like this

function MYMODULE_form_name_validate($form, &$form_state) {
  $form_state['values']['description'] = $form_state['values']['description']['value'];
}

Upvotes: 2

Related Questions