-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
– user148170
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
– Marcos Lance
I’d need those codes to understand where he’s getting lost
– user148170
Which one do you need? unico q did not send was the route that is this here $route['alterando_contact/(:num)'] ='Schedule/changeContact/$1';
– Marcos Lance
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'/>
– Icaro Martins