Welcome Guest, Not a member yet? Register   Sign In
Using form and controller inside a controller
#1

[eluser]stormlead[/eluser]
Hi!
i have some queries regarding using forms. i have created a form and have done its validation. the code for the same is as below,

Code:
if ($this->form_validation->run() == FALSE)
        {
          $this->load->view('feedback');
        }
        else
        {  
            $username=$_POST['username'];
            $password=$_POST['password'];
            $email=$_POST['email'];
            $this->load->database();
            $data=array(
                        'username'=>$username,
                        'password'=>$password,
                        'email'=>$email
                        );
            $this->db->insert('test',$data);
            $this->load->view('formsuccess');
        }

as now you can after the validation is successfull i store the data inside the database and then load the formsuccess view.
Now in form success view i also want to put another form for searching the database.
There are some queries regarding the same.
1) How can i load a form inside the formsuccess view and perform validation for the same
2) how can i use submitted values from the second search form to search my DB.

Please help at the earliest..........
#2

[eluser]Phil Sturgeon[/eluser]
When your validation is successful you should redirect to a new page. This page will contain your second form action.

If data cannot be sent via the URL and you need to keep some of your variables, use the Session library (probably flash data).

Don't try to do everything all in the same controller method as it is much easier to break it down into multiple.

Note: Yay, 2000 posts! And only 1691 of them have been "RTFM"!.
#3

[eluser]stormlead[/eluser]
hi!
now tried doing this
i created one more controller and a view for the search form.
and i called the controller inside the page using include function like below

Code:
include('search');
the code for search controller is as below
Code:
<?php

class Form extends Controller {
    
    function index()
    {
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        $this->load->view('search');        
    }
    
}
?>
and for the search view is as follows
Code:
<html>
<head>
<title>My Form</title>
</head>
<body>

<h3>&nbsp;</h3>
&lt;?php echo form_open('form'); ?&gt;
<table width="614" border="0">
  <tr>
    <td width="312">&lt;input type="text" name="srchbox" size="50" &gt;&lt;/td>
    <td width="292">&lt;input type="submit" name="srch" value="Search" &gt;&lt;/td>
  </tr>
</table>
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
it is giving me warnings
A PHP Error was encountered

Severity: Warning

Message: include_once(search) [function.include-once]: failed to open stream: No such file or directory

Filename: views/formsuccess.php

Line Number: 9
A PHP Error was encountered

Severity: Warning

Message: include_once() [function.include]: Failed opening 'search' for inclusion (include_path='.;C:\php5\pear')

Filename: views/formsuccess.php

Line Number: 9


doono whats the problem????
#4

[eluser]Phil Sturgeon[/eluser]
Why are you trying to include a controller? Why would you use a relative URI segment to try and include a controller? Why are you expecting this to work?!

Use redirect('search'); to redirect there, don't randomly include things.




Theme © iAndrew 2016 - Forum software by © MyBB