Welcome Guest, Not a member yet? Register   Sign In
[solved] POST datas not found
#1

(This post was last modified: 05-02-2016, 01:34 AM by gaska96.)

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 )
Reply
#2

You need to set the form to post to the controller/method.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 05-01-2016, 03:21 AM by gaska96.)

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'; )
Reply
#4

And what does your html form look like please show your code for the form and controller method for us to help you.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

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>
Reply
#6

(This post was last modified: 05-01-2016, 06:31 AM by Wouter60.)

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.
Reply
#7

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 ?
Reply
#8

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.
Reply
#9

(This post was last modified: 05-02-2016, 01:34 AM by gaska96.)

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)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB