POST does not receive the data

Asked

Viewed 71 times

-1

I’m having a problem retrieving the form data.

I have this excerpt on my page, it gets the array contact and I print the data in the respective fields, I click on the link at the end to send the new data to the controller (this and to change an already registered contact). So far so good, it follows my method correctly but at the time of data recovery via POST comes all empty.

That passage and my page.

<form action='alterando_contato' method="post"> 
    <h4>Alterar contato</h4>

    <div class="form-group">
        <label for="nome">Nome completo</label>
        <input type="text" class="form-control form-control-md" name="newnome" value="<?php echo $contato['nome']; ?>"/>
    </div>

    <div class="form-group">
        <label for="email">E-mail</label>
        <input type="email" class="form-control form-control-md" name="newemail" value="<?php echo $contato['email']; ?>"/>
    </div>

    <div class="form-group">
        <label for="telefone">Telefone</label>
        <input type="tel" class="form-control form-control-md" name="newcelular" value="<?php echo $contato['celular']; ?>"/>
    </div>

    <div class="form-group">
        <label for="nome">Redes sociais</label>
        <input type="text" class="form-control form-control-md" name="newfacebook" value="<?php echo $contato['facebook']; ?>"/>
    </div>

    <div class="form-group">
        <input type="text" class="form-control form-control-md" name="newlinkedin" value="<?php echo $contato['linkedin']; ?>"/>
    </div>

    <div class="form-group">
        <input type="text" class="form-control form-control-md" name="newtwitter" value="<?php echo $contato['twitter']; ?>"/>
    </div>

    <div class="form-group">
        <input type="text" class="form-control form-control-md" name="newinstagram" value="<?php echo $contato['instagram']; ?>"/>
    </div>

    <a href="<?php echo base_url('alterando_contato').'/'.$contato; ?>" class="btn btn-warning btn-sm">Alterar</a>

</form>

My controller.

public function alterarContato($id){
    $this->load->model('Contato');
    $newnome = trim($this->input->post('newnome', true));
    $newemail = trim($this->input->post('newemail', true));
    $newcelular = trim($this->input->post('newcelular', true));
    $newfacebook = trim($this->input->post('newfacebook', true));
    $newlinkedin = trim($this->input->post('newlinkedin', true));
    $newtwitter = trim($this->input->post('newtwitter', true));
    $newinstagram = trim($this->input->post('newinstagram', true));
        $dados = array(
            'nome' => $newnome,
            'email' => $newemail,
            'celular' => $newcelular,
            'facebook' => $newfacebook,
            'linkedin' => $newlinkedin,
            'twitter' => $newtwitter,
            'instagram' => $newinstagram
        );

    var_dump($_POST);

    $this->Contato->alterarContato($id, $dados);
    redirect('Agenda');
}

When I give a var_dump($_POST) happens this

array(0) { }
  • you are calling the function when? ajax? via action? You need to post more code there to help you

  • I am doing by route, via action I am using codeigniter, my route and this alterando_contact. i can get to the function in fact, but I can’t recover the form data

  • I’d need those codes to understand where he’s getting lost

  • Which one do you need? unico q did not send was the route that is this here $route['alterando_contact/(:num)'] ='Schedule/changeContact/$1';

  • 2

    It seems to me that your problem is the change button, it is a <a href= with the link, try to do the following: Place the post url in the action of your form and at the end of your form change the <a href= by a <input type='submit' value='alterar'/>

2 answers

1


Mark, do the following, exchange your action for the href that is on the link. Shortly after,

<form action='<?php echo base_url('alterando_contato').'/'.$contato; ?>' method="post"> 
    <h4>Alterar contato</h4>

    <div class="form-group">
        <label for="nome">Nome completo</label>
        <input type="text" class="form-control form-control-md" name="newnome" value="<?php echo $contato['nome']; ?>"/>
    </div>

    <div class="form-group">
        <label for="email">E-mail</label>
        <input type="email" class="form-control form-control-md" name="newemail" value="<?php echo $contato['email']; ?>"/>
    </div>

    <div class="form-group">
        <label for="telefone">Telefone</label>
        <input type="tel" class="form-control form-control-md" name="newcelular" value="<?php echo $contato['celular']; ?>"/>
    </div>

    <div class="form-group">
        <label for="nome">Redes sociais</label>
        <input type="text" class="form-control form-control-md" name="newfacebook" value="<?php echo $contato['facebook']; ?>"/>
    </div>

    <div class="form-group">
        <input type="text" class="form-control form-control-md" name="newlinkedin" value="<?php echo $contato['linkedin']; ?>"/>
    </div>

    <div class="form-group">
        <input type="text" class="form-control form-control-md" name="newtwitter" value="<?php echo $contato['twitter']; ?>"/>
    </div>

    <div class="form-group">
        <input type="text" class="form-control form-control-md" name="newinstagram" value="<?php echo $contato['instagram']; ?>"/>
    </div>

    <button type="submit" class="btn btn-warning btn-sm">Alterar</button>

</form>

Done this, you will be sending your data via post.

0

Hey, guys, thanks for all your help.

I managed to solve my problem using a little of Leandro’s solution and a little of what Icaro posted.

I put this snippet in my action.

'<?php echo base_url('alterando_contato').'/'.$contato['id']?>'

and traded the button for that stretch.

<input type="submit" class="btn btn-warning btn-sm" value="Alterar">

Browser other questions tagged

You are not signed in. Login or sign up in order to post.