I'm developing a pretty basic module catalog_request
that creates a form. I'm replacing the form's default submit button <input ..type="submit" />
with a <button ...>click</button>
using following in form definition.
function catalog_request_form($form, &$form_state) {
/**
* form fields here
*/
$form['fieldset_submit']['the_submit_button'] = array(
'#type' => 'markup',
'#prefix' => '<button class="btn submit">',
'#markup' => 'Send Request...',
'#suffix' => '</button>',
);
/* ... */
}
and have defined other two form related functions
function catalog_request_form_validate($form, &$form_state) {
drupal_set_message(t('The form was validated'));
}
function catalog_request_form_submit($form, &$form_state) {
die('submitted');
//drupal_set_message(t('The form was submitted'));
}
The problem
My submit function catalog_request_form_submit
isn't being called. I've read numerous articles online but none resolved my issue. Following didn't work
- Adding
'#submit' => 'catalog_request_form_submit',
tothe_submit_button
key - Adding
'$form['#submit'] => 'catalog_request_form_submit';
to end ofcatalog_request_form
function - Adding
'$form['#submit'][] => 'catalog_request_form_submit';
to end ofcatalog_request_form
function
I've read that adding something along the lines of $form['actions']['#submit'][] = 'custom_function';
could solve the problem but I'm not sure how to adapt it for my form.
I know that having '#type' => 'submit'
for the submit button makes the form work but I want a button
tag.
My problem is exactly When altering the submit button, the form does not work but it doesn't have a solution (only an answer that ignores the question's point)
P.S. I do not develop for drupal frequently so I might be missing something very obvious.
Any help will be greatly appreciated. thanks
<button>
where it doesn't make sense to use one. If you want something that submits the form, use a submit input, which was created for that specific purpose.<input ... type="submit"../>
submits the form. I know that using'#type'=>'submit'
generates aninput
element. But I have to use<button...>
. why? I'll start with "button
can have HTML content". The<input ... type="submit"../>
and<button..>
both submit the form in all browsers I care about so there is no issue there. There are ways around every issue and I'm willing to get around this issue when somebody proves that there is no way this problem can be resolved in Durpal. Drupal is the problem here, not my HTML. thanks for your help guys :)