My situation:
I built a form with FAPI. I display the results in a table like this:
function grap_contact_repository_form_submit($form, &$form_state) {
...
$form_state['results_table'] = array('#markup' => grap_contact_repository($matches));
$form_state['rebuild'] = TRUE;
}
The grap_contact_repository
function returns a theme_table.
My problem:
Because of the results_table that already uses a #markup
type, I can't build a reset button for my form using '#type' => 'markup'
too. (Because all the results table will be clickable too).
I'm looking for an alternative to make this button work. I tried this:
$form['clear'] = array(
'#type' => 'button',
'#value' => 'Réinitialiser',
'#attributes' => array('onclick' => 'this.form.reset();'),
);
or this: (http://www.blue-bag.com/blog/drupal-form-api-reset-button)
$form['reset'] = array(
'#type' => 'button',
'#button_type' => 'reset',
'#value' => 'Réinitialiser',
'#validate' => array(),
'#attributes' => array(
'onclick' => 'this.form.reset(); return false;',
),
);
But it doesn't work. The onclick works if I put another JavaScript like alert
. I have nothing in my JS errors console.
Does someone have an idea to make it work?
Thanks a lot :-)