Welcome Guest, Not a member yet? Register   Sign In
how to retain all the get variable while posting
#1

[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">
&lt;?php echo $header; ?&gt;
<h1>&lt;?php echo $mytitle; ?&gt; </h1>
<p>&lt;?php echo $mytext; ?&gt; </p>
<h3>Edit Form</h3>
<p>Please edit the following form:</p>
&lt;?php // echo validation_errors(); ?&gt;

&lt;?php echo form_open('/form/edit/'); ?&gt;
&lt;?php  foreach($edit as $item):  ?&gt;
<h5>Username</h5>
&lt;?php echo form_error('user'); ?&gt;
&lt;input type="text" name="user" value="&lt;?php echo $item-&gt;username; ?&gt;" size="50" />

<h5>Old Password</h5>
&lt;?php echo form_error('opass'); ?&gt;
&lt;input type="password" name="opass" value="&lt;?php echo set_value('opass'); ?&gt;" size="50" /&gt;

<h5>New Password </h5>
&lt;?php echo form_error('npassf'); ?&gt;
&lt;input type="password" name="npassf" value="&lt;?php echo set_value('npassf'); ?&gt;" size="50" /&gt;

<h5>New Password Confirm</h5>
&lt;?php echo form_error('ncpassf'); ?&gt;
&lt;input type="password" name="ncpassf" value="&lt;?php echo set_value('ncpassf'); ?&gt;" size="50" /&gt;

<h5>Email Address</h5>
&lt;?php echo form_error('email'); ?&gt;
&lt;input type="text" name="email" value="&lt;?php echo $item-&gt;email; ?&gt;" size="50" />
&lt;?php endforeach;?&gt;
<br /><br />
&lt;?php form_hidden('id', $item->id); ?&gt;
&lt;?php echo form_submit('submit', 'Submit'); ?&gt;
&lt;?php echo form_close(); ?&gt;
<br />
&lt;?php echo $footer; ?&gt;
</div>
&lt;/body&gt;
#2

[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...
&lt;?php form_open('/form/edit/'); ?&gt;

// to this...
&lt;?php form_open("form/edit/{$item->id}"); ?&gt; // also note the double-quotes
#3

[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 .
#4

[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.
#5

[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.
#6

[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 &lt;?php echo form_hidden('id', $item->id); ?&gt; 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:
&lt;?php echo form_open('/form/editform/'); ?&gt;
&lt;?php  foreach($edit as $item):  ?&gt;


<h5>Old Password Check</h5>
&lt;?php echo form_error('opass'); ?&gt;
&lt;?php if(isset($error)): echo $error; endif; ?&gt;
&lt;input type="password" name="opass" value="&lt;?php echo set_value('opass'); ?&gt;" size="50" /&gt;



<h5>Username</h5>
&lt;?php echo form_error('user'); ?&gt;
&lt;?php echo form_hidden('id', $item->id); ?&gt;
&lt;input type="text" name="user" value="&lt;?php echo $item-&gt;username; ?&gt;" size="50" />
</p>



<h5>New Password </h5>
&lt;?php echo form_error('npassf'); ?&gt;
&lt;input type="password" name="npassf" value="&lt;?php echo set_value('npassf'); ?&gt;" size="50" /&gt;



<h5>New Password Confirm</h5>
&lt;?php echo form_error('ncpassf'); ?&gt;
&lt;input type="password" name="ncpassf" value="&lt;?php echo set_value('ncpassf'); ?&gt;" size="50" /&gt;



<h5>Email Address</h5>
&lt;?php echo form_error('email'); ?&gt;
&lt;input type="text" name="email" value="&lt;?php echo $item-&gt;email; ?&gt;" size="50" />


&lt;?php endforeach;?&gt;
<br /><br />
&lt;?php echo form_submit('submit', 'Submit'); ?&gt;
&lt;?php echo form_close(); ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB