Welcome Guest, Not a member yet? Register   Sign In
How to put a field value to a controller/model
#1

[eluser]CodeIgniterNoob[/eluser]
Hello,

So I have a form in one view:
Code:
echo form_open('main/find/');        
echo "<label for='name'>Name</label>";
$data = array('name'=>'name','value'=>set_value('name'),'id'=>'name','size'=>35,'maxlength'=>'30');
echo form_input($data) ."</p>";
echo "<p><label></label>";
echo form_submit('submit','search');
echo "</p>";
echo form_close();

And I want to pass the value of name field to a controller which calls a function in one of my models:

Code:
function getResults($name)
  {    
    $this->db->where('b.name', $name);
    $this->db->join('person AS b', 'a.event_id = b.event_id', 'inner');
    $this->db->select('a.*');
    $this->db->select('b.*');
    $Q = $this->db->get('events AS a');

    if($Q->num_rows()>0)
    {
        return $Q->result_array();
    }
}

This is my controler:

Code:
function Main()
{
    parent::Controller();
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->library('validation');
    $this->load->library('form_validation');    
}
    
function index()
{
    $data['results'] = $this->Mfunctions->getAllResults();
    $this->load->view('main', $data);
}
    
function find($name=NULL)
{
    $data['results'] = $this->Mfunctions->getResults($name);
    $this->load->view('results', $data);
}

How can I pass the value of name to the $name variable?
#2

[eluser]pistolPete[/eluser]
Only use one validation library, preferable the latter (because it's newer):
Code:
$this->load->library('validation');
$this->load->library('form_validation');


Quote:How can I pass the value of name to the $name variable?
Have a look at the user guide.
In your controller:
Code:
$name = $this->input->post('name');
#3

[eluser]CodeIgniterNoob[/eluser]
Ok its searching and finding properly. But how come its not writing the input value into the uri string? I want it to show like this /index.php/main/find/someguysname
#4

[eluser]pistolPete[/eluser]
[quote author="CodeIgniterNoob" date="1237242655"]But how come its not writing the input value into the uri string? I want it to show like this /index.php/main/find/someguysname[/quote]

Because you are doing a POST request.
Have a look at this: http://ellislab.com/forums/viewreply/547980/
#5

[eluser]CodeIgniterNoob[/eluser]
Pete, that post helped me out alot, thank you so much.




Theme © iAndrew 2016 - Forum software by © MyBB