0
I am creating a plugin for CMS Wordpress, in it I have a script that runs perfectly until the part to make the request ajax to record some data in the database. The code works until the part displaying the text inside the div
passo2form
which initially becomes empty and after clicking the button the text is inserted inside it. However the data is not written in the database. My code is like this:
Main html:
<div class='principal-form'>
<input type='text' name='nome' id='nome' class='campo-form' placeholder='Nome' maxlength='50'><br>
<input type='email' name='email' id='email' class='campo-form' placeholder='Email' maxlength='120'/>
<button type='submit' id='enviarform' class='botao-enviar'>Efetuar Simulação</button>
</div>
<div id='passo2form' class='passo2form'></div>
Javascript file that runs:
jQuery('#enviarform').click(function(){
var nome = document.getElementById('nome').value;
var email = document.getElementById('email').value;
jQuery( "#passo2form" ).html("<div class='col-md-35 padding-top-15'><div class='texto-ola'><p>Olá <span class='cor-vermelho'>" + nome + "</span>,</p><p>Estaremos enviando em breve sua cotação para o email <span class='cor-vermelho'>" + email + " </span></p></div></div>");
var formData = {
'nome' : jQuery('input[name=nome]').val(),
'email' : jQuery('input[name=email]').val()
};
// process the form
jQuery.ajax({
type : 'POST',
url : 'processa.php',
data : formData,
dataType : 'json',
encode : true
})
.done(function(data) {
console.log(data);
});
});
I tested the file processes.php and works perfectly by inserting the data into the database. But it follows the code:
<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/wordpress/wp-config.php' );
global $wpdb;
$nome = trim($_POST['nome']);
$email = trim($_POST['email']);
$wpdb->insert(
wp_formclientes,
array(
'nome' => $_POST['nome'],
'email' => $_POST['email']
)
);
$wpdb->show_errors();
?>
Gives some error in the console?
– Sampaio Leal
@Sampaioleal returns no error to me
– Wendell
@Wendell In the Network tab of your web inspector appears the request for the
processa.php
?– rdleal
@Panther does not appear, only the request of
processa.js
which is the script file.– Wendell
@Wendell with the Networks tab open, and clicking the button
#enviarform
nothing appears? And what that propertyencode: true
in the object sent to thejQuery.ajax
makes? I did not find it in the official documentation.– rdleal