By giustigianni on
I want a button in the form like this (not a submit button but a button type button):
<input class="form-submit" name="op" value="New" type="button">
I use this code:
$form['New'] = array(
'#type' => 'button',
'#value' => t('New'),
'#weight' => 19,
);
....but I obtain a submit button like this:
<input class="form-submit" name="op" value="New" type="submit">
Where is the error?
Comments
there is no core support for
there is no core support for type="button".. here's what I did:
array('#type' => 'markup', '#value' => '<input '. drupal_attributes(array('type' => 'button', ......)) .'/>')Button - as a link
Was just working on this for our site, here's the code using the "button" form type. used this directly in my login page template.
-greg
How about two buttons?
This is nice. But I have a question here. what if I want two (or more) link buttons on one page?
I tried using the code above to define two buttons, and tried to use drupal_get_form once or twice (after each form element), but the result is the same, it will give me only one button, the first one, or two buttons but link to the same page(link for the second button).
Any idea?
thanx
Figured it out
Oh, I figured it out. Just put those codes in a function and call that function twice.
The only thing is how to make the buttons side by side?
Zick
You figure out how to get
You figure out how to get those buttons side by side? It's exactly what I wish to do. Could you share the code? Thanks.
Addition to forms API
There is a patch to the forms API which allows for the button type, you could apply it, then use regular theming functions on your form button elements.
Dave
Reply
Drupal 5 am using
Hi u used ur code, but when i see the view source,,
button not created ,, only submit is create
View source
Why have the 'button' #type
Why have the 'button' #type listed as an element in the documentation when its not even supported in core?
Patch
Someone/I created a patch for this, but I forget where it is. It actually isn't all that hard to fix.
Not sure why it hasn't been fixed.
Dave
Reason?
A patch is nice of course, but if the patch is not implemented, it's not much of use to implement a 'button' type button in a module. Then everybody who wants to use the module needs to patch the core.
Is there a reason why this button type button is not implemented? Even in the 'Pro Drupal Development' book this button type button is mentioned on page 182.
But anyway, it is not working. I am using Drupal 5.2 and my button type buttons are translated as submit buttons. I am getting headache to try to find a workaround for the feature I want to implement in a module. I can use a link but that would just not look nice.
Quick Fix
Nevermind, my idea causes problems elsewhere.
I'll add another vote for a
I'll add another vote for a #type -> button to be actually a <input type=button and not a <input type=submit.
I'd also like to be able to assign javascript actions as attributes without having all the "s turned into "s.
I came across this today and
I came across this today and filed a bug report:
#289240: Allow #type 'button' that aren't form submits
first time using it in D6
When pressing a button form gets submit to Drupal, but the submit handler is not invoked. Weird behavior. Why not leaving the type button as it is? I am confused.
You can do it by simply
You can do it by simply overriding the button theme in your theme template.php file
Need Drupal help?
Reach me
Backend Frontend and DevOps.
Drupal 8+
See this issue: https://www.drupal.org/project/drupal/issues/1671190
http://www.DROWL.de || Professionelle Drupal Lösungen aus Ostwestfalen-Lippe (OWL)
http://www.webks.de || webks: websolutions kept simple - Webbasierte Lösungen die einfach überzeugen!
http://www.drupal-theming.com || Individuelle Responsive Themes