newhck / php-form-builder-class

Automatically exported from code.google.com/p/php-form-builder-class
GNU General Public License v3.0
0 stars 0 forks source link

Improve submit buttons supporting name, value and label #152

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
If submit button has the "name" attribute, when clicked name and value of the 
button are submitted with the request, indicating that the button with that 
name and with that value was clicked.

However with the current implementation, if you add two submit button giving 
them different values like this:

$form->addElement(new Element_Button('Submit 1', 'submit', array('name' => 
'submit_1')));
$form->addElement(new Element_Button('Submit 2', 'submit', array('name' => 
'submit_2')));

You get HTML code like this:

<button id="form-element-1" name="submit_1" type="submit">Submit 1</button>
<button id="form-element-2" name="submit_2" type="submit">Submit 2</button>

So the first parameter is not used as the "value" attribute, but more like a 
"label".
If you click on the "Submit 1" button, "submit_1=" is added to the request, but 
it has no value. If a validation error occurs, field 'submit_1' is rendered as 
if it was submitted with value '', so it will not output "Submit 1" as the 
content of <buttton> tag.

I suggest to modifiy the Element_Button class as follows:
- The first parameter of the constructor should be called "$label" and not 
"$value". If empty, it should became "Submit", and it should be passed as the 
first parameter of parent::__construct().
- 'value' should be '1' by default. It may be the same as $label, but '1' would 
be enough to easily check what submit button was clicked.
- render() should be:
echo '<button', $this->getAttributes(), '>', $this->label, '</button>';

In this way you can easily set a name for a submit button, and check what 
button was clicked. I think these modifications are quite backward compatible, 
and will have almost no effect to the existing code.

Original issue reported on code.google.com by fabiofab...@gmail.com on 24 Aug 2011 at 10:54

GoogleCodeExporter commented 8 years ago
Thanks for the feedback.  I agree and will make these changes asap.

- Andrew

Original comment by ajporterfield@gmail.com on 24 Aug 2011 at 2:35

GoogleCodeExporter commented 8 years ago
The latest revision - r537 - contains this update.  Thanks again for the 
feedback/suggestion.

- Andrew

Original comment by ajporterfield@gmail.com on 25 Aug 2011 at 2:42