how to retain all the get variable while posting - El Forum - 09-15-2009
[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>
how to retain all the get variable while posting - El Forum - 09-15-2009
[eluser]bigtony[/eluser]
Your controller signature expects to receive the id, so in your view you need to change the html form tag to pass the id back into it:
Code: // change this...
<?php form_open('/form/edit/'); ?>
// to this...
<?php form_open("form/edit/{$item->id}"); ?> // also note the double-quotes
how to retain all the get variable while posting - El Forum - 09-15-2009
[eluser]mukesh raj[/eluser]
Thanks for the reply bigtony.
This kind of not helping me ends with the error on submition "The URI you submitted has disallowed characters."
Also i feel that this {$item->id} , if was in the for each might have worked , however my form is outside foreach and $item is accessed inside foreach , things will be clear if look at my code posted .
how to retain all the get variable while posting - El Forum - 09-15-2009
[eluser]bigtony[/eluser]
Sorry, I missed the foreach. This is probably why you get message about disallowed characters as well. Am I right in thinking that there should only be 1 item in the loop anyway? In which case I would either change the data format you send to the view so you don't need to loop or move the form and /form to inside the foreach loop.
how to retain all the get variable while posting - El Forum - 09-15-2009
[eluser]BrianDHall[/eluser]
Check the HTML source your form is producing, and post that. I don't see anything wrong per se, but I'm betting something in the HTML this is producing will make it much clearer what is wrong.
how to retain all the get variable while posting - El Forum - 09-16-2009
[eluser]mukesh raj[/eluser]
hey all thanks for the support and the reply .
i actually solved that problem .
well if you see my bit modified code of view i have inserted the line of code <?php echo form_hidden('id', $item->id); ?> inside the foreach in the form , which was actually outside the foreach ..u will see that if u compare the code in my last post , so this helped me retain my all values even after validating and submiting .
Code: <?php echo form_open('/form/editform/'); ?>
<?php foreach($edit as $item): ?>
<h5>Old Password Check</h5>
<?php echo form_error('opass'); ?>
<?php if(isset($error)): echo $error; endif; ?>
<input type="password" name="opass" value="<?php echo set_value('opass'); ?>" size="50" />
<h5>Username</h5>
<?php echo form_error('user'); ?>
<?php echo form_hidden('id', $item->id); ?>
<input type="text" name="user" value="<?php echo $item->username; ?>" size="50" />
</p>
<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 echo form_submit('submit', 'Submit'); ?>
<?php echo form_close(); ?>
|