jelix / jelix

A PHP framework
http://jelix.org
Other
84 stars 38 forks source link

Missing attributes array/class option for form #262

Closed hiromik closed 8 years ago

hiromik commented 8 years ago

It should be possible to add an array of attributes such as array('class' => 'myformclass) to either a {form} or {formfull}, I had to override the htmlbuilder just to add a class to the

tag (and by using my custombuilder which basically does exactly the same as its parent beside adding class, I get a javascript error and form validation doesn't work anymore and submits everytime I click submit no matter the values).

laurentj commented 8 years ago

It is already possible to add any html attributes, on the <form> element, but it is not documented. I will do it.

You can specify options for the builder. One of these option (not yet documented), is "attributes", which is an associative array "attr name" => "value".

Example:

{formfull $theformobject,'module~act:ion', $action_params, 'html',
              array('attributes'=>array('class'=>'foo'))}

or

{form $theformobject,'module~act:ion', $action_params, 'html', 
          array('attributes'=>array('class'=>'foo'))}
...
{/form}

You can add also attributes on controls, but this is already documented :-)

laurentj commented 8 years ago

This is now documented http://docs.jelix.org/en/manual-1.6/jforms/display/html-generator#builder-options

hiromik commented 8 years ago

I strongly advise you to add that to the jForms part where it explains how to provide classes for form inputs and such, adding this to the html generator part is really not intuititive and will lead user like me who enjoy the framework but hate the doc very confused

laurentj commented 8 years ago

Well, feel free to propose improvements : the documentation is not hidden ;-) All help are welcomed.

Keep in mind that jForms in not tied to HTML, and can have builder for other kind of forms technologies like XUL or XFORMS (even if these examples are a bit deprecated :-)), or other type of HTML forms builder based on some specific JS libraries. This is why I separated the doc in two parts : the first part is how to use jforms in a template, and the second part (html generator) is how to customize the HTML output. But probably, as you said, some improvements can be done, and any help would be appreciated. Anyway, thank you for your feedback :-)