1

http://pear.php.net/package/HTML_QuickForm2/ http://download.pear.php.net/package/HTML_QuickForm2-0.6.1.tgz

I am able to use this fine for forms but I'm having problems getting the client side validation to work. I don't think I have the correct files and includes but the explanation online is confusing the heck out of me. There's an example file that I'm trying to load (builtin-rules.php) but the javascript doesn't work. Here is an excerpt that I think should validate using ONBLUR event but it doesn't.

$username->addRule('required', 'Username is required', null,
               HTML_QuickForm2_Rule::ONBLUR_CLIENT_SERVER);

2 Answers2

1

I've just updated the docs which deal with including JS files. Hopefully they should be clearer now.

Alexey Borzov
  • 241
  • 1
  • 2
  • BTW, if you have trouble running even the package examples, then you probably copied some files around manually and the package cannot find them. See [a similar bug report](http://pear.php.net/bugs/bug.php?id=19311) – Alexey Borzov Mar 27 '12 at 11:08
  • Got it working now with your help and getting a little basic javascript reading done. I included them myself and had to obtain the .js file by manually downloading the package. Thank you, I will vote as answer as soon as I get some more rep points. – user1222532 Apr 06 '12 at 20:57
0

This if from their documentation:

<?php
require_once 'HTML/QuickForm2/Renderer.php';
require_once 'HTML/QuickForm2/JavascriptBuilder.php';

$renderer = HTML_QuickForm2_Renderer::factory('default');
// Here '/path/to/libraries' is whatever directory available via HTTP you copied libraries to
$renderer->setJavascriptBuilder(new HTML_QuickForm2_JavascriptBuilder('/path/to/libraries'));
$form->render($renderer);

// This will output necessary <script src="/path/to/libraries/..."></script> tags
foreach ($renderer->getJavascriptBuilder()->getLibraries() as $link) {
    echo $link . "\n";
}
echo $renderer;
?> 
Mark Steudel
  • 1,662
  • 3
  • 18
  • 31