2

I have the following controller file:

<?php
class Test extends CI_Controller 
{
    function __construct()
    {
        parent::__construct();  
    }

    function index()
    {   
        print_r($_POST);
        $view_params = array();

        $this->load->view('test', $view_params);
    }
}
?>

with a view file of:

<form action="/test" method="post">
    <input type="text" name="test" />
    <input type="submit" />
</form>

<ul id="account">
    <li class="separator url"><label>Domain Address (URL)</label><input maxlength="22" type="text" name="sub_url" />
    <small class="subtext">This is the link people use to find your site. You can change this at any time.</small>
</li>
</ul>
<img class="green_arrow" src="assets/images/green_arrow.png" />

When I hit the submit button, no post data is being spit out, but when I do a page refresh, it says data has been posted and will resend it.

Also, I think that html is just a snippet, but please understand that I am trying to reduce code and therefore reduce the number of problem areas. The reason where there is so much garbage after that is because if I remove that the view file ceases to work, but that's another question.

3
  • You don't need your constructor there if you're just calling the parent's constructor - that's done for you already. Commented Mar 5, 2011 at 0:11
  • What does it print exactly? Array()? Or nothing at all? Commented Mar 5, 2011 at 0:15
  • Thanks Jacob, I didn't know that I didn't need the constructor. That'll help reduce my code from now on. Commented Mar 5, 2011 at 0:22

2 Answers 2

2

CodeIgniter empties $_POST, $_GET etc. for security purposes. Use the Input class instead.

$post = $this->input->post();

or

$some_data = $this->input->post('some_data');

Have a read here: http://codeigniter.com/user_guide/libraries/input.html

Sign up to request clarification or add additional context in comments.

Comments

1

Hey Johnathan, I'm glad I got to fix your problem. All you had to do was enable apache's mod rewrite.

a2enmod rewrite 
/etc/init.d/apache2 reload

Because you didn't have apache's mod rewrite, code igniter must have screwed up some rewrite rules and messed up your form data on post back.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.