Im trying to create a block programatically. I have created a function, which does the work for me.

function _create_footer_contact() {

  form_load_include($form_state, 'inc', 'block', 'block.admin');

  $form_state = array();
  $form_state['values'] = array(
    'machine_name' => 'footer_contact',
    'title' => 'TITLE',
    'info' => 'INFO',
    'body' => array(
      'value' => 'BODY TEXT',
      'format' => 'full_html',
    'regions' => array(
      'mytheme' => 'footer',
      'myadmintheme' => '-1',
    'visibility' => '0',
    'pages' => NULL,
    'custom' => '0'

  drupal_form_submit('block_add_block_form', $form_state);

The problem is the 'format' value, which throws an error if it is set to anything but 'plain_text' (if format is set to 'plain_text' the form submits nicely and a block is created).

WD form: Illegal choice full_html in Text format element. 
An illegal choice has been detected. Please contact the site administrator.

To debug I have tried to examine the $form_state of 'block_add_block_form' using hook_form_alter and dpm(). When I manually submit a block the 'format' is set to 'full_html'.

So... how do I submit a form programatically with full_html set as format?

  • 1
    That error happens when the value provided for an input doesn't match the options available when the form was built. Is full_html definitely an option on that form in the same context?
    – Clive
    Feb 9, 2015 at 23:45
  • Yes it is. If I create a block manually (and examine $form_state with dpm() in hook_form_alter), format is set to full_html.
    – tolborg
    Feb 10, 2015 at 7:09

1 Answer 1


You can try this.It works i think so

$form['formItem'] = array(
     '#title' => t('Field Label'),
     '#value' => 'This is my value',

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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