CodeIgniter Forums

Full Version: [solved] POST datas not found
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi. I created a view file with a form and I want to send all datas to a controller. I use $this->input->post('NAME', TRUE) to get each data then I check each to see if they are empty. And... all are empty. Why controller don't receive data ? I hope it's a good question. (Have mercy !Smile )
You need to set the form to post to the controller/method.
I did that. I thought is something with $config['uri_protocol'] ? Or it's something with routes ? (beucase I set my route like
$route['addServer'] = 'home/addServer'; )
And what does your html form look like please show your code for the form and controller method for us to help you.

PHP Code:
public function addserver(){
       // Varibles
       $game $this->input->post('game');
       $country $this->input->post('country');
       $ip $this->input->post('ip');
       $port $this->input->post('port');
       $qport $this->input->post('query_port');
       $captcha $this->input->post('captcha');
       $captchaSession $this->session->userdata('code');
       // Our error
       $error "";
       // Let's check
       if($game == 0){
           $error "Select a game !";
       } elseif($country == 0){
           $error "Select a country !";
       } elseif(ctype_space($ip)){
           $error "You must write a DNS / IP Address !";
       } elseif(ctype_space($port) || ctype_space($qport)){
           $error "You must write Port / Query Port !";
       } elseif(strlen($captcha) != strlen($captchaSession)){
           $error "Your Captcha is invalid !";
       } else {
           $v 1;
($captcha[$i]!= $captchaSession[$i]){    
           if($v == 0){
               $error "Your Captcha is invalid !";
           } else {
               $error "Success";


<form role="form" action="addserver" method="POST">
                                        <td colspan="2"><i class='fa fa-gamepad lblue'></i> Game Type
                                            <select name="game" class="form-control" id="game" required/>
                                                <option value="0" selected="true" disabled> Select a game</option>
                                                <?php echo $this->settings->getGames();?>
                                            <i class='fa fa-globe red'></i> Country
                                            <select name="country" class="form-control" required/>
                                                <option value="RO">Romania</option>
                                        <td><i class='fa fa-location-arrow pink'></i> IP / DNS Address<input type="text" class="form-control input-lg" name="ip" placeholder="e.g: /" autocomplete="off" required/></td>
                                        <td><i class='fa fa-location-arrow green'></i> Port<input type="text" class="form-control input-lg numOnly" id="port" name="port" maxlength="5" autocomplete="off" placeholder="27015" required/></td>
                                        <td><i class='fa fa-location-arrow green'></i> Query Port<input type="text" class="form-control input-lg numOnly" id="query_port" name="query_port" maxlength="5" autocomplete="off" placeholder="27015" required/></td>
                                        <td><center><?php echo img(array('src'=>base_url('captcha'),'id'=>'captcha','border'=>'0'));?><br /><a onclick="loadimgs()"><font color="green"><i class='fa fa-refresh'></i></font> Refresh</a></center></td>
                                        <td><input class="form-control input-lg numOnly" name="captcha" type="text" maxlength="6" placeholder="Captcha" autocomplete="off" required /></td>
                                        <td><center><div class="checkbox"><label><input type="checkbox" value="1" required>I accept <u><a href="#">Terms & Conditions</a></u> of this website !</label></div></center></td>
                                        <td><center><button type="reset" class="btn btn-warning btn-block btn-sm"><i class='fa fa-trash'></i> Reset</button></center></td>
                                        <td colspan="2"><center><button class="btn btn-success btn-sm btn-block" type="submit" name="query"><i class='fa fa-check'></i> Add this server !</button></td>
Did you test whether submitting the form calls the addserver method in your controller?
Usually, in the form declaration you need to include controller AND method, like this:
PHP Code:
<form role="form" action="servers/addserver" method="POST"
Assuming that your controller is named "Servers.php".

Put the following code at the top of the addserver method:
PHP Code:
echo '<pre>';
As soon as you submit the form, the method should output all POST data on your screen.
When I do this, I get that array... I don't know what could be wrong. I did this before 2-3 times and works fine. Maybe reinstall Codeigniter ?
If you get the POST array (with values), nothing is wrong, and you are good to go. Now you can save the data into a table in your database.
I know I know. But my problem is really strange. If I print only $game for example (check before posts), it prints good , but if I make : if($game == 0){ $error = "ERROR"; } my site returns that error even if $game is CS (for example). What is wrong with this ?

EDIT: Solved. There was an error with session, because I wrote sesion and I compared integer with string. (I'm dumb)