I’m new in Zend Framework, and I’m having a problem.
usually when verifying data in forms we use javascript like bellow:
<html>
<head>
<script>
function verify(){
if( document.form.name.value=="") { alert("Error"); return false}
}
</script>
</head>
<body>
<form onSubmit="verify()" name="form">
<input name="name" />
<input type="submit" />
</form>
</body>
</html>
I’m using zend forms and i don’t have a clue how to do it.
<?php
class Application_Form_Login extends Zend_Form {
public function init() {
$login = new Zend_Form_Element_Text('login');
$password = new Zend_Form_Element_Password('password');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel("Login");
$remember = new Zend_Form_Element_Checkbox('remember');
$this->addElements(array($login, $password,$remember ,$submit));
}
}
?>
Any help please.
thanks for any help.
You do it the same way as before, but here is how to tell
Zend_Formto add theonsubmitevent to your so that the HTML code generated contains the attribute in the<form>tag.This adds an attribute
onsubmitto theZend_Formobject, such that when the form is rendered your<form>tag hasonsubmit="return verify()"in it.Now you can just put the actual Javascript code to verify the form in the view script itself, or an external javascript file that you can reference in a
<script>tag.