Hello.
I have a set of form elements like this snippet below, but i only want to insert the name and address value into database, the rest is for validation only. How can i do that ? I tried using save() function like in the tutorial but it didn't work (wrong parameters exception). In my User database, there's no password column, only name and address
The form:
$name = new Text("name");
$name->setLabel("Name");
$name->setFilters(array('striptags', 'string'));
$name->addValidators(array(
new PresenceOf(array(
'message' => 'Name is required'
))
));
$this->add($name);
$pass = new Password("password");
$pass->setLabel("Password");
$pass->addValidators(array(
new PresenceOf(array(
'message' => 'Password is required'
)),
new Confirmation(array(
'message' => 'Password does not match',
'with' => 'cPass'
))
));
$this->add($pass);
$address = new TextArea("address");
$address->setLabel("Address");
$address->setFilters(array('striptags', 'string'));
$address->addValidators(array(
new PresenceOf(array(
'message' => 'Address is required'
))
));
$this->add($address);
The controller:
public function doRegisterAction(){
if (!$this->request->isPost()) {
return $this->forward("index/index");
}
$form = new register;
$user = new user();
$data = $this->request->getPost();
if (!$form->isValid($data, $user)) {
$error = array();
foreach ($form->getMessages() as $message) {
array_push($error, $message);
}
$this->view->setVar('error', $error);
return $this->forward('register/index');
}
if ($user->save() == false) {
foreach ($form->getMessages() as $message) {
echo $message;
}
return $this->forward('register/index');
}
$form->clear();
echo "User registered successfully";
return $this->forward("index/index");
}
Thanks in advance :)