Last active
September 25, 2015 02:27
-
-
Save bendi/847930 to your computer and use it in GitHub Desktop.
Zend_Form_Decorator_JsValidation - basic usage, with validation messages in frenc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL|E_STRICT); | |
set_include_path(get_include_path() . PATH_SEPARATOR . | |
'./library'); | |
require_once 'Zend/Loader.php'; | |
Zend_Loader::registerAutoload(); | |
//May need to have this set, the JavaScript file paths use baseUrl at the moment | |
//Zend_Controller_Front::getInstance()->setBaseUrl('public'); | |
// display validation messages in French | |
$translator = new Zend_Translate( | |
array( | |
'adapter' => 'array', | |
'content' => '/resources/languages', | |
'locale' => 'fr', | |
'scan' => Zend_Translate::LOCALE_DIRECTORY | |
) | |
); | |
Zend_Validate_Abstract::setDefaultTranslator($translator); | |
$form = new Zend_Form(); | |
$form->setView(new Zend_View()); | |
$form->addDecorator(new Zend_Form_Decorator_JsValidation()); | |
$name = $form->createElement('text', 'name', array( | |
'label' => 'Name' | |
)); | |
$name->addValidator('NotEmpty') | |
->setRequired(true); | |
$submit = $form->createElement('submit', 'ok', array( | |
'ignore' => true, | |
'label' => 'OK' | |
)); | |
$form->setElements(array( | |
$name, | |
$submit | |
)); | |
echo $form->getView()->headScript(); | |
echo $form->getView()->inlineScript(); | |
echo $form->render(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment