我无法让客户端部分正常工作。我遇到的第一个问题是,它只加载 quickform.js 脚本,而不是其他 2。所以我现在将它们加载到头部。但我的问题仍然是表单只验证客户端。我觉得我错过了一些明显的东西?
require_once('HTML/QuickForm2.php');
require_once ('HTML/QuickForm2/Renderer.php');
require_once ('HTML/QuickForm2/JavascriptBuilder.php');
$form = new HTML_QuickForm2('uploads');
$fieldset = $form->addElement('fieldset');
$name = $fieldset->addElement('text', 'name', array('size' => 50, 'maxlength' => 255))->setLabel('Enter your name:');
$fieldset->addElement('submit', null, array('value' => 'Send!'));
$name->addFilter('trim');
$name->addRule('required', 'Please enter your name');
if ($form->validate()) {
echo '<h1>Hello, ' . htmlspecialchars($name->getValue()) . '!</h1>';
exit;
}
$renderer = HTML_QuickForm2_Renderer::factory('default');
$renderer->setJavascriptBuilder(new HTML_QuickForm2_JavascriptBuilder('js/quickform2'));
$form->render($renderer);
foreach ($renderer->getJavascriptBuilder()->getLibraries() as $link) {
echo $link . "\n";
}
echo $renderer;