Welcome Guest, Not a member yet? Register   Sign In
Can't get data from form (clearly missing something obvious) - solved
#1

[eluser]infro[/eluser]
Hello,
trying out CI and now im trying to do very simple thing: submit some data from form and get it. But im surely not understanding something or didn't read all info on that, cause i can't get it working.
simple form:
Code:
<form action="http://localhost/codeigniter/general/change_language"    method="POST">
    <input type="text" name="test" value="labas" />
    <input type="submit" name="submit1" value="GoGo" />
</form>
controller:
Code:
class General extends Controller {

    function General() {
        parent::Controller();
    }

    function change_language() {
        var_dump($_GET);
        if (isset($_GET['test']))
            echo 'YES!';
        if (isset($_GET['submit1']))
            echo 'YES!';
        var_dump($_POST);
        if (isset($_POST['test']))
            echo 'YES!';
        if (isset($_POST['submit1']))
            echo 'YES!';
        print ($this->input->get_post('test'));
        print ($this->input->get_post('submit1'));
        print ($this->input->post('submit1'));
        print ($this->input->get('submit1'));
    }

}
tried every way i know to display any data. also tried using GET method. no luck. :/
anyone knows what i did wrong?
#2

[eluser]Dam1an[/eluser]
Firstly, $_GET will never work in this case as you specify the form to be POST (and $_GET is destroyed by default)

Just put a simple echo at the start of the function to make sure it's even being called

Also, it's best not to have the absolute URL hard coded in the form action, use either the form helper, base_url() or just use POST and it will call the function which displayed the form (thats what I do)
#3

[eluser]infro[/eluser]
to Dam1an: I'm aware of the things You pointed out.

The function is being called. All code is reduced to basics, just to make sure I didn't do anything stupid in other things.
Any ideas?
#4

[eluser]Dam1an[/eluser]
I just tried your code, and it works as expected (I obviously had to change the path to be valid for me
This is what I got
Quote:array(0) { } array(2) { ["test"]=> string(5) "labas" ["submit1"]=> string(4) "GoGo" } YES!YES!labasGoGoGoGo

So what exactly happens when you submit? An error? blank page?
#5

[eluser]infro[/eluser]
I said I was clearly missing something. The problem was my .htaccess file, which redirected to add "/" to the end.
Now to do it with CI...

Thanks anyway Smile
#6

[eluser]Dam1an[/eluser]
Oh, ok
Well glad you got it all sorted for now Smile




Theme © iAndrew 2016 - Forum software by © MyBB