For storing the multiple values in the database through check box, when a user select multiple choices,that selected value will be shown in database For Example a user want to select their education in the form so it will shown in database in one column by using explode() function it will Split a string by string, so this will allow different values to the database table.
<?php
<input type="checkbox" value="10" name="education[]">10th
<input type="checkbox" value="12" name="education[]">12th
<input type="checkbox" value="btech" name="education[]">Btech
<input type="checkbox" value="btech" name="education[]">Mtech
<input type="checkbox" value="btech" name="education[]">phd
?>
controller code:
function register()
{
if($this->request->data)
{
pr($this->request->data);
$education = $this->request->data['education'];
$output = implode(',',$education);
$this->request->data['education'] = $output;
$this->request->data['password'] = md5($this->request->data['password']);
if($this->User->save($this->request->data))
{
$this->Session->setFlash('Registration successfully!!');
$this->redirect(array('action'=>'login'));
}
else
{
$this->Session->setFlash('Something went wrong!');
$this->redirect(array('action'=>'login'));
}
}
}
0 Comment(s)