0

I'm using ZF2 on our project and lately, we integrated it to Smarty templating system. We already made forms for our views with the help of Zend\Form native to ZF2. My question is: how can I get the actual HTML value (<input type="text">...) on the controller level of all the form elements made by the Zend\Form of ZF2? Since Smarty3 doesn't allow PHP tags on the template side by default, I cannot just use the:

$form = $this->form;
$form->setAttribute('action', $this->url($property_folder, array('action' => $property_folder)));
$form->setAttribute('class', 'searchform');
$form->prepare();
. . .

If I can extract the actual HTML value of form elements, that would be a great help reusing them to other templates/themes the user desired.

Thanks in advance!

eli_daxs
  • 176
  • 1
  • 10

1 Answers1

1

Okay, after re-reading i assume you want the full HTML String of a Form-Element and not the Element-Value. This is possible, too, and simply requires you to access the redering ViewHelper inside your Controller. This is done as follows:

$viewHelperManager = $sm->get('viewhelpermanager');
$formElementRenderer = $viewHelperManager->get('formElement');

$elementHtml = $formElementRenderer($form->get('element'));

There are obviously more ViewHelpers to use. You can find out which they are by checking the Zend\Form\View\HelperConfig

Sam
  • 16,435
  • 6
  • 55
  • 89
  • Thanks @Sam but I think getValue() function only returns the value of that element, sorry if my question is not that clear. For example I have a textbox added on my ApplicationForm.php, I want to get the `...etc.` on the Controller level – eli_daxs Jan 29 '13 at 07:58
  • So you want the full HTML-String of an Element? – Sam Jan 29 '13 at 07:59
  • Yes, is it the right thing to do? Or I have no choice but to put into garbage what we have done on ZF2 Zend\Form helper and just create a function that somehow does this for Smarty? – eli_daxs Jan 29 '13 at 08:02
  • @eli_daxs I've editted the answer, check if this meets your requirements now. I didn't test it but it should work *me hopes* – Sam Jan 29 '13 at 08:07
  • Wow! Nice, it works! Thank you very much @Sam! This would be a time saver. Danke! :) – eli_daxs Jan 29 '13 at 08:13