I am new with cake php and I am building a Invpoice Manager for one of
my cleint . I am stuck with data valdation an need your help to figure
out the error , data validation is not working . Plerase find all the
code below:
Controller
<?php
class AdminsController extends AppController {
var $name = 'Admins';
var $uses = array('Admin','User_role');
function index() {
$this->set('admins', $this->Admin->find('all'));
}
function user_register() {
if($this->Session->check('USER') == false)
{
$this->flash('Your session has been expired, please login to
continue.','/');
return;
}
if (!empty($this->data)) {
if ($this->Admin->save($this->data))
{
$this->Session->setFlash('Your post has been saved.');
$this->redirect(array('action' => 'success'));
}
else
{
$this->set('data', $this->data);
$this->validateErrors($this->data);
$this->render();
}
}
}
function user_role()
{
if($this->Session->check('USER') == false)
{
$this->flash('Your session has been expired, please login to
continue.','/');
return;
}
// get the list of all users for which there is no role data in db
$user_id = $_SESSION['USER'];
$allNewCompanies = $this->Admin->__get_users_norole($user_id);
$this->set('user_norole_list' , $allNewCompanies);
}
function assign_role($id)
{
$this->set("company_id",$id);
// form posted now handle data and save to db
if( isset($_POST['submit']) || isset($this->data) )
{
/*
if($this->User_role->validate())
{
$this->Admin->__assign_user_role($this->data->rdAssignRole,$this-
>data->company_id);
}
else
{
$errors = $this->User_role->invalidFields();
$this->Session->setFlash(implode('<br>', $errors));
}
*/
if(!empty($_POST['role_id']))
{
$this->Admin->__assign_user_role($_POST['company_id'],$_POST
['role_id']);
$this->Session->setFlash('Role has been successfully assigned.');
$this->redirect(array('action' => 'success'));
}
}
}
function success()
{
if($this->Session->check('USER') == false)
{
$this->flash('Your session has been expired, please login to
continue.','/');
return;
}
}
}
?>
model
<?php
class Admin extends AppModel {
var $name = 'Admin';
var $useTable = false;
var $validate = array(
'fldCompanyName' => VALID_NOT_EMPTY,
'fldContactPerson' => VALID_EMAIL,
'fldAddress' => VALID_NUMBER
);
// This is where the magic happens
function schema() {
return array (
'fldCompanyName' => array('type' => 'string', 'length' => 60),
'fldContactPerson' => array('type' => 'string', 'length' => 60),
'fldAddress' => array('type' => 'text', 'length' => 100),
'fldPhone' => array('type' => 'string', 'length' => 8),
'fldMobile' => array('type' => 'string', 'length' => 10),
'fldFax' => array('type' => 'string', 'length' => 8),
'fldCSTNo' => array('type' => 'string', 'length' => 8),
'fldTINNo' => array('type' => 'string', 'length' => 8),
'fldRemarks' => array('type' => 'string', 'length' => 8),
'fldEmail' => array('type' => 'string', 'length' => 8),
'fldWebUrl' => array('type' => 'string', 'length' => 12)
);
}
function __get_users_norole($user_id)
{
$ret = $this->query("SELECT id FROM user_roles
WHERE user_id = '$user_id'");
if( $ret[0]['user_roles']['id'] == '' )
{
$user_list = $this->query("SELECT * FROM companies
WHERE id = '$user_id'");
return $user_list;
}
return ;
}
function __assign_user_role($user_id,$role_id)
{
$ret = $this->query("INSERT INTO user_roles(user_id,role_id) VALUES
('$user_id','$role_id')");
return ;
}
}
?>
view
<div id="content-wrapper">
<div id="main">
<div class="icon-error">
<i>Please fill all the required fields.</i><br>
<?php $session->flash() ;?>
</div>
<?php echo $form->create(null, array('action' => 'user_register')); ?
>
<table id="user_registration" border="0">
<tr>
<th scope="row" abbr="User Name" class="specalt">Company Name
<span class="required">*</span>
</th>
<td>
<?php echo $form->text('fldCompanyName'); ?>
</td>
</tr>
<tr>
<th scope="row" abbr="User Name" class="specalt">Contact Person
<span class="required">*</span>
</th>
<td>
<?php echo $form->text('fldContactPerson'); ?>
</td>
</tr>
<tr>
<th scope="row" abbr="Password" class="specalt">
Company Password <span class="required">*</span>
</th>
<td>
<?php echo $form->text('fldCompanyPass'); ?>
</td>
</tr>
<tr>
<th scope="row" abbr="ConfirmPass" class="specalt">
Confirm Password <span class="required">*</span>
</th>
<td>
<?php echo $form->text('fldCompanyPassC'); ?>
</td>
</tr>
<tr>
<th scope="row" abbr="contact person" class="specalt">
Contact Person <span class="required">*</span>
</th>
<td>
<?php echo $form->text('fldContactPerson'); ?>
</td>
</tr>
<tr>
<th scope="row" abbr="Email" class="specalt">
Email address <span class="required">*</span>
</th>
<td>
<?php echo $form->text('fldEmail'); ?>
</td>
</tr>
<tr>
<tr>
<th scope="row" abbr="Address" class="specalt">
Address<span class="required">*</span>
</th>
<td>
<?php echo $form->textarea('fldAddress'); ?>
</td>
</tr>
<tr>
<th scope="row" abbr="Phone" class="specalt">
Phone<span class="required">*</span>
</th>
<td>
<?php echo $form->text('fldPhone'); ?>
</td>
</tr>
<tr>
<th scope="row" abbr="Mobile" class="specalt">
Mobile<span class="required">*</span>
</th>
<td>
<?php echo $form->text('fldMobile'); ?>
</td>
</tr>
<tr>
<th scope="row" abbr="Fax" class="specalt">
Fax<span class="required">*</span>
</th>
<td>
<?php echo $form->text('fldFax'); ?>
</td>
</tr>
<tr>
<th scope="row" abbr="CST" class="specalt">
CST No<span class="required">*</span>
</th>
<td>
<?php echo $form->text('fldCSTNo'); ?>
</td>
</tr>
<tr>
<th scope="row" abbr="TIN" class="specalt">
TIN No<span class="required">*</span>
</th>
<td>
<?php echo $form->text('fldTINNo'); ?>
</td>
</tr>
<tr>
<th scope="row" abbr="TIN" class="specalt">
Remarks<span class="required">*</span>
</th>
<td>
<?php echo $form->text('fldRemarks'); ?>
</td>
</tr>
<tr>
<th scope="row" abbr="Website" class="specalt">
WebSite<span class="required">*</span>
</th>
<td>
<?php echo $form->text('fldWebUrl'); ?>
</td>
</tr>
<tr>
<td>
<?php echo $form->submit(); ?>
</td>
</tr>
</table>
<?php echo $form->end(); ?>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
<div id="sidebar">
<h3>Available Options</h3>
<ul class="sidemenu">
<li><a href="./AccessManager/add_access_details">Add New Access
Details</a></li>
<li><a href="./AccessManager/view_access_details">View Access Details</
a></li>
<li><a href="./AccessManager/edit_access_details">Edit/Delete Access
Details</a></li>
</ul>
<p> </p>
<p>
</p>
</div>
</div>
thanks ,
Rahul
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment