Skip to content

Instantly share code, notes, and snippets.

@bendi
Last active September 25, 2015 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendi/847930 to your computer and use it in GitHub Desktop.
Save bendi/847930 to your computer and use it in GitHub Desktop.
Zend_Form_Decorator_JsValidation - basic usage, with validation messages in frenc
<?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