[eluser]mukesh raj[/eluser]
hi all,
Im new to CI i've just started and trying to build a sample application where in user can register and edit thier information later.
so now that when i pass the id to the function in the controller i get all the details in the view page to edit , and when i submit the form after editing i get warning and error saying Undefined variable: id and Missing argument 1 for Form::edit() i even loose the items in foreach in the view after submit .
pls help me this how do i retain all those get values while in posting.
My function to edit in the controller is :-
Code:
function edit($id)
{
$this->web['edit']=$this->form_model->get_entry($id);
$this->form_validation->set_rules('user', 'Username', 'trim|required|min_length[5]|max_length[12]|xss_clean');
$this->form_validation->set_rules('opass', 'Old Password', 'trim|required');
$this->form_validation->set_rules('npassf', 'New Password', 'trim|required|matches[ncpassf]');
$this->form_validation->set_rules('ncpassf', 'New Password Confirmation', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$id=$this->input->post('id', TRUE);
$username=$this->input->post('user', TRUE);
$oldpassword=$this->input->post('opass', TRUE);
$newpassconf=$this->input->post('npassf', TRUE);
$newcpassconf=$this->input->post('ncpassf', TRUE);
$email=$this->input->post('email', TRUE);
if ($this->form_validation->run() == FALSE)
{
$this->load->view('form_edit',$this->web);
}
else
{
$pass_check=$this->form_model->pass_check($id);
print_r($pass_check);
exit();
$this->form_model->update_entry($this->data);
$this->web['query']=$this->form_model->get_entry($id);
$this->load->view('form_success', $this->web);
}
}
and the view page is
Code:
<body>
<div align="center">
<?php echo $header; ?>
<h1><?php echo $mytitle; ?> </h1>
<p><?php echo $mytext; ?> </p>
<h3>Edit Form</h3>
<p>Please edit the following form:</p>
<?php // echo validation_errors(); ?>
<?php echo form_open('/form/edit/'); ?>
<?php foreach($edit as $item): ?>
<h5>Username</h5>
<?php echo form_error('user'); ?>
<input type="text" name="user" value="<?php echo $item->username; ?>" size="50" />
<h5>Old Password</h5>
<?php echo form_error('opass'); ?>
<input type="password" name="opass" value="<?php echo set_value('opass'); ?>" size="50" />
<h5>New Password </h5>
<?php echo form_error('npassf'); ?>
<input type="password" name="npassf" value="<?php echo set_value('npassf'); ?>" size="50" />
<h5>New Password Confirm</h5>
<?php echo form_error('ncpassf'); ?>
<input type="password" name="ncpassf" value="<?php echo set_value('ncpassf'); ?>" size="50" />
<h5>Email Address</h5>
<?php echo form_error('email'); ?>
<input type="text" name="email" value="<?php echo $item->email; ?>" size="50" />
<?php endforeach;?>
<br /><br />
<?php form_hidden('id', $item->id); ?>
<?php echo form_submit('submit', 'Submit'); ?>
<?php echo form_close(); ?>
<br />
<?php echo $footer; ?>
</div>
</body>