Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Allow <button type=submit"> within form generation #806

Savageman opened this Issue · 6 comments

3 participants

Esperat Julian Harro Verton Jelmer Schreuder
Esperat Julian

When using the form generation with Fieldset::add(), it seems impossible to obtain a field.

type = submit generates <input type="submit">
type = button generates <button type=button">

The latter doesn't submit the form when clicked, it needs aditionnal JavaScript or onclick to operate. I'm not even sure why it behaves this way. It's much more logical in my point of view to generate instead of type="button".

Since the "type" attribute is used to determine which tag to use when displaying the field, we cannot display a tag with a "submit" type.

I'm in favor of changing the default behaviour on this and generateing a when adding a "button" field.
Another solution is to add a new "submit_button" type? (like "reset")

Harro Verton

This works ok in the Form class:

$form->submit() // generates <input type="submit"...
$form->reset() // generates <input type="reset"...
$form->button() // generates <button ...

The problem is in the Fieldset build() method, that indeed uses the 'type' attribute to determine which HTML tag needs to be generated.

I'm not really in favour of inventing new "fake" type's to work around it, I'd rather find a solution to allow you to define the tag. Maybe introduce a 'tag' attribute, and fall back to type detection if it is not present? I have to think about this...

Esperat Julian

Yeah, the tag attribute seems fine to me.

Harro Verton

@jschreuder Any preference on how to solve this?

Jelmer Schreuder

@WanWizard I like your 'tag' property proposal, that keeps current behavior intact and allows for the flexibility this issue requires to be solved. My only "but" is that it won't really choose the tag, but instead choose which Form class method is used. But I can't think of a better solution.

Esperat Julian

So if I implement this, I need to leave current "type" fully backwards-compatible.

And juste add the case type = submit & tag = button ?

I think in Form_Instance line 224 use $attributes['tag'] instead of 'input' when it exists and unset it is ok?

Actual code:

return html_tag('input', $this->attr_to_string($attributes));

Proposed code:

if (isset($attributes['tag']))
    $tag = $attributes['tag'];
    $tag = 'input';
return html_tag($tag, $this->attr_to_string($attributes));
Harro Verton WanWizard closed this in fd8b352
Esperat Julian

I'm just seeing this now. Thank you!
It needs a little tweak in the build() method from Fieldset_Field too. I'm taking care of that now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.