[eluser]Brain Coder[/eluser]
hey guys
i have some issues with my validation here
Controller :
Code: function edit($id = 0){
$data['title'] = "Edit Server";
$data['main'] = 'admin_server_edit';
$data['value'] = $this->MServers->getServer($id);
if (!count($data['value'])){
redirect('admin/servers/index','refresh');
}
$this->load->vars($data);
$this->load->view('admin/dashboard');
}
function edit_do($id){
$this->load->library('form_validation');
if($this->form_validation->run() != FALSE){
$this->MServers->updateServer();
$this->session->set_flashdata('message','Server Updated');
redirect('admin/servers/index','refresh');
}else{
$this->form_validation->set_rules('plan_name','Plan Name',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_processor','Plan Processor',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_ram','RAM',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_hd','Hard Disk',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_connection','Connection',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_traffic','Traffic',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_system','System',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_cpanel','Control Panel',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_ip','IP',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_firewall','FireWall',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_nomange','No Manage',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_normal','With Manage',"trim|required|xss_clean");
$this->form_validation->set_error_delimiters('<div class="Error">', '</div>');
$data['title'] = "Edit Server";
$data['main'] = 'admin_server_edit';
$data['value'] = $this->MServers->getServer($id);
$this->load->vars($data);
$this->load->view('admin/dashboard');
}
}
View :
Code: <?php
$attributes = array('name' => 'server-form', 'id' => 'server-form');
echo form_open_multipart('admin/servers/edit_do/'.$value['plan_id'],$attributes);
?>
<div id='page'>
<table border="0" width="100%" dir="ltr" cellspacing="0" cellpadding="0" align="center" class="cat_table">
<tr>
<td colspan="2" width="100%" class="main_td1">Plan Name</td>
</tr>
<tr>
<td width="50%" class="main_td2">Plan Name</td>
<td width="50%" class="main_td2">
<?php $data = array('name'=>'plan_name','id'=>'plan_name','size'=>50,'value'=>$value['plan_name']);
echo form_input($data);?>
<?php form_error('plan_name') ?>
</td>
</tr>
</table>
the problem is like that
if i want to edit Plan name (example) and left the input field EMPTY
it will redirect me to the view file again but without showing the error msg
like required.
in insert function its work , but with this one not working
can i have any help please
[eluser]theprodigy[/eluser]
Quote:
if($this->form_validation->run() != FALSE){
$this->MServers->updateServer();
$this->session->set_flashdata('message','Server Updated');
redirect('admin/servers/index','refresh');
}else{
$this->form_validation->set_rules('plan_name','Plan Name',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_processor','Plan Processor',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_ram','RAM',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_hd','Hard Disk',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_connection','Connection',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_traffic','Traffic',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_system','System',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_cpanel','Control Panel',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_ip','IP',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_firewall','FireWall',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_nomange','No Manage',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_normal','With Manage',"trim|required|xss_clean");
$this->form_validation->set_error_delimiters('<div class="Error">', '</div>');
//...code...
You're running your validation check before ever setting the rules.
You need to load the library, set your rules, and then run the validation check.
Code: function edit_do($id)
{
$this->load->library('form_validation');
$this->form_validation->set_rules('plan_name','Plan Name',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_processor','Plan Processor',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_ram','RAM',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_hd','Hard Disk',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_connection','Connection',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_traffic','Traffic',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_system','System',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_cpanel','Control Panel',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_ip','IP',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_firewall','FireWall',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_nomange','No Manage',"trim|required|xss_clean");
$this->form_validation->set_rules('plan_normal','With Manage',"trim|required|xss_clean");
$this->form_validation->set_error_delimiters('<div class="Error">', '</div>');
if($this->form_validation->run() != FALSE)
{
$this->MServers->updateServer();
$this->session->set_flashdata('message','Server Updated');
redirect('admin/servers/index','refresh');
}
else
{
$data['title'] = "Edit Server";
$data['main'] = 'admin_server_edit';
$data['value'] = $this->MServers->getServer($id);
$this->load->vars($data);
$this->load->view('admin/dashboard');
}
[eluser]Brain Coder[/eluser]
Thank you very much
its work now
|