Welcome Guest, Not a member yet? Register   Sign In
Passing Variables to the controller.
#1

[eluser]Unknown[/eluser]
Newbie to CI and MVC-style stuffs of this nature, I've tried to look for a answer, I really have, but I'm an idiot and wondering if anyone has any ideas. I'm trying to do something vaguely simple, take the input from a text box and have the value use able in a function the controller.

What's in the View
Code:
<?=form_open('blog/search');?>


<p><label for="number">Number 1:</label>
&lt;input type="text" name="num1" value="&lt;?php echo set_value('num1');?&gt;" /&gt;&lt;/p>

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


&lt;/form&gt;

And here's the Blog controller
Code:
class Blog extends Controller {

function Blog()
{
    parent::Controller();
    $this->load->helper('url');
    $this->load->helper('form');

function search()
{
    $n1 = $this->input->post('num1');
    echo $n1;
        print_r($_POST);  
}

}

The plan down the line is to try and have multiple inputs to use to search against a database, but I'm at this point just trying to see if I can get one text input to pass through. When I try to print_r, I get a empty array. Removing the value in the text input gets me nothing either. If anyone has any ideas, I'm all ears.
#2

[eluser]InsiteFX[/eluser]
Look at the form_validation library in the User Guide!

InsiteFX
#3

[eluser]dudeami0[/eluser]
Try this first and see if you get something:

Code:
function search() {
    $n1 = $this->input->get_post('num1');
    echo $n1;  
}

If that returns your value, its a matter of the form method (get/post). If it doesn't work then let us know Smile




Theme © iAndrew 2016 - Forum software by © MyBB