Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] $_POST is getting only the last field
#1

(This post was last modified: 03-11-2015, 08:07 PM by fcordeiro.)

I'm starting now with Codeiginiter and for days I'm trying to fix this code. I have a lot of fields in my form: name, email, phone, message, etc, but $_POST only get the last field, Message.

View HOME.PHP

PHP Code:
<?php echo form_open('/home/cadastrar'); ?>
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="compname">
                                Nome
                            </label>
                            <div class="input-group">
                                <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                                <input type="text" class="form-control" id="name" placeholder="Nome completo" required="required" /></div>
                        </div>
                        <div class="form-group">
                            <label for="mail">
                                Email Address
                            </label>
                            <div class="input-group">
                                <span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
                                <input type="email" class="form-control" id="email" placeholder="Digite seu email" required="required" /></div>
                        </div>
                        <div class="form-group">
                            <label for="mobile">
                                Telefone Celular
                            </label>
                            <div class="input-group">
                                <span class="input-group-addon"><span class="glyphicon glyphicon-earphone"></span></span>
                                <input type="text" class="form-control" id="phone" placeholder="(XX) XXXXX-XXXX" required="required" /></div>
                        </div>
                        <div class="form-group">
                            <label for="zip">
                               CEP
                           </label>
                           <div class="input-group">
                                <span class="input-group-addon"><span class="glyphicon glyphicon-home"></span></span>
                           <input type="text" class="form-control" id="cep" /></div>
                        </div>
                        <div class="form-group">
                            <label for="addr">
                                Endereço
                            </label>
                            <input type="text" class="form-control" id="addr" required="required" />
                        </div>
                        <div class="form-group">
                            <label for="complement">
                               Número / Complemento
                           </label>
                           <input type="text" class="form-control" id="numr" required="required" />
                        </div>
                        <div class="form-group">
                            <label for="neighborhood">
                               Bairro
                           </label>
                           <input type="text" class="form-control" id="bairro" />
                        </div>
                        <div class="form-group">
                            <label for="city">
                               Cidade
                           </label>
                           <input type="text" class="form-control" id="cidade" />
                        </div>
                        <div class="form-group">
                            <label for="state">
                               Estado
                           </label>
                           <input type="text" class="form-control" id="estado" />
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="messag">
                                Message</label>
                            <textarea name="message" id="message" class="form-control" rows="9" cols="25"
                                placeholder="Message"></textarea>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <button type="submit" class="btn btn-skin pull-right" id="submit">
                            Efetuar Matrícula
                        </button>
                    </div>
                </div>
                <?php echo form_close(); ?>

Controller HOME.PHP

PHP Code:
public function cadastrar() {
        
$this->output->enable_profiler(TRUE);

        
$this->load->library('form_validation');
        
$this->form_validation->set_rules('name''Nome Completo''trim|required|min_length[6]|max_length[50]|xss_clean');
        
$this->form_validation->set_rules('email''Email''trim|required|valid_email');
        
$this->form_validation->set_rules('phone''Telefone Celular''trim|required');
        
$this->form_validation->set_rules('cep''CEP''trim|required|min_length[8]|max_length[9]|xss_clean');
        
$this->form_validation->set_rules('addr''Endereço''trim|required|min_length[6]|max_length[50]|xss_clean');
        
$this->form_validation->set_rules('numr''Número / Complemento''trim|required|min_length[1]|max_length[50]|xss_clean');
        
$this->form_validation->set_rules('bairro''Bairro''trim|required|min_length[3]|max_length[50]|xss_clean');
        
$this->form_validation->set_rules('cidade''Cidade''trim|required|min_length[3]|max_length[50]|xss_clean');
        
$this->form_validation->set_rules('estado''Estado''trim|required|min_length[2]|max_length[2]|xss_clean');
        
        
$data['title'] = "Curso";
        
        if (
$this->form_validation->run() === FALSE) {
            
$data['msg'] = " Desculpe, não foi possível concluir a matrícula.";
            
$this->load->view('templates/header'$data);
            
$this->load->view('pages/home');
            
$this->load->view('templates/footer');    
        } else {
            
$data['msg'] = " Matrícula efetuada! Clique no botão abaixo para efetuar o pagamento.";
            
$this->load->view('templates/header'$data);
            
$this->load->view('templates/registered');
            
$this->load->view('templates/footer');
        }
    } 

So, form_validation always return FALSE because I'm only receiving data from the textarea "message".

Form submited:
[Image: Sele_o_043.jpg]

Data received ($_POST):
[Image: Sele_o_044.jpg]

Thank you for your help.
Reply


Messages In This Thread
[SOLVED] $_POST is getting only the last field - by fcordeiro - 03-11-2015, 07:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB