Zend Framework form input element with spaces

When I create an html form like:

$form = new Zend_Form();
$form->setMethod('post');
$form2->addElement('textarea', 'Name with Space');

      

HTML becomes:

...
<textarea name="NamewithSpace" id="NamewithSpace" rows="24" cols="80"></textarea>
...

      

Mention that the login is getting correct!

When I call $ form-> getValues ​​(); after the message with the filled text field, the result is:

array('Name with Space' => NULL); // Whitespace name! But value empty!

      

When I call $ this-> getRequest (); after the message with the filled text field, the result is:

array('NamewithSpace' => 'filled in value'); // Camelcase name! Value filled, but name changed!

      

How to access filled values ​​with the given name "Name with space"?

I am using ZF 1.7.6.

+1


a source to share


2 answers


Sorry, I don't think you can! For an application where you just have to have an element name that is not acceptable for ZF, you will have to change the ZF source.

In ZF 1.8.1 the regex that needs to be changed to allow space (and any other characters) is on line 424 from Zend / Form / Element.php



One possible (better) solution would be to create a custom element and override the filterName method, however this is not very convenient if you want to change multiple element types.

Surely there must be a better solution ?!

+1


a source


$form->getValues()

will always show the original keys and values ​​that you set on the form object as they are not updated after the form is submitted. However, you can use this to your advantage, for example:

$textarea = $form->getElement('Name with Space');
$key      = str_replace(' ', '', trim($textarea->getName()));

      



By using this key in the request object, you should be able to access the value you want. This is a bit of a hack, but it looks like it might work.

+1


a source







All Articles