Drupal 7: drupal_execute has Gone, Say Hello to drupal_form_submit

17th August 2011 | Tags:

As has been com­mented else­where, when you’re pro­gram­mat­i­cally insert­ing data the most reli­able way of doing so is often to sim­u­late form sub­mis­sion — that way, any val­i­da­tion rules are applied and other mod­ules have a chance to inter­cept the sub­mis­sion to do what they need to with the data. This was achieved using the func­tion drupal_execute:

$form_state = array();
$form_state['values'] = array();
$form_state['values']['field1'] = $value1;
$form_state['values']['field2'] = $value2;
drupal_execute('your_form_id', $form_state);

How­ever,

drupal_execute has gone alto­gether from Dru­pal 7. Instead, you need sim­ply replace any call to drupal_execute with the new func­tion drupal_form_submit (see the doc­u­men­ta­tion). Oth­er­wise, every­thing (from the point of view of your syn­tax) remains the same. Don’t for­get to use form_get_errors() to ensure that the form has validated.

Comments

No comments yet.

Links and images are allowed, but please note that rel="nofollow" will be automactically appended to any links.