CodeIgniter Forums
[solved] POST datas not found - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: [solved] POST datas not found (/showthread.php?tid=65111)



[solved] POST datas not found - gaska96 - 04-30-2016

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 )


RE: POST datas not found - InsiteFX - 04-30-2016

You need to set the form to post to the controller/method.


RE: POST datas not found - gaska96 - 05-01-2016

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'; )


RE: POST datas not found - InsiteFX - 05-01-2016

And what does your html form look like please show your code for the form and controller method for us to help you.


RE: POST datas not found - gaska96 - 05-01-2016

Controller: 

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;
 
           for($i=0;$i<=5;$i++){    
                if
($captcha[$i]!= $captchaSession[$i]){    
                    $v
=0;
 
                   break;
 
               }
 
           }
 
           if($v == 0){
 
               $error "Your Captcha is invalid !";
 
           } else {
 
               $error "Success";
 
           }
 
       }
 
       $this->session->set_flashdata('addMessage'$error);
 
       redirect(base_url());
 
   

Form:

Code:
<form role="form" action="addserver" method="POST">
                                    <tr>
                                        <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();?>
                                            </select>
                                        </td>
                                        <td>
                                            <i class='fa fa-globe red'></i> Country
                                            <select name="country" class="form-control" required/>
                                                <option value="RO">Romania</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <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: csgo.domain.com / 125.23.51.29" 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>
                                    </tr>
                                    <tr>
                                        <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>
                                    </tr>
                                    <tr>
                                        <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>
                                    </tr>
                                </form>



RE: POST datas not found - Wouter60 - 05-01-2016

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>';
print_r($this->input->post());
echo 
'</pre>';
die(); 
As soon as you submit the form, the method should output all POST data on your screen.


RE: POST datas not found - gaska96 - 05-01-2016

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 ?


RE: POST datas not found - Wouter60 - 05-01-2016

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.


RE: POST datas not found - gaska96 - 05-02-2016

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)