0
Good afternoon, you guys, I am at the end of a project, and the php file of the forms do not respond. I have 02 separate forms on the page, one of them has file submission input. None of them are responding. Someone can give me a light???
<!-- Form -->
<div class="clearfix">
<form class="form contact-form" id="contact_form">
<form action="contact_me.php" method="post">
<div class="form-group">
NOME: <input type="text" name="name" size="76" maxlength="100"required><br><br>
E-MAIL: <input type="text" name="email" size="30" maxlength="100" value="@"required>
CIDADE:  <input type="text" name="city" size="27" maxlength="70"><br><br>
SEXO:   <input type="radio" name="genderm" value="Masculino"> Masculino | <input type="radio" name="genderf" value="Feminino"> Feminino <br><br>
<div class="mb-20 mb-md-10">
<h4>DEPARTAMENTO</h4>
<select class="input-md form-control" name"selection">
<option>ADMINISTRATIVO</option>
<option>RECURSOS HUMANOS</option>
<option>FINANCEIRO</option>
<option>COMERCIAL</option>
<option>DATA CENTER E ESTRUTURA</option>
<option>INOVAÇÃO</option>
<option>ESTATÍSTICA E MACHINE LEARNING</option>
<option>SUPORTE E ATENDIMENTO AO CLIENTE</option>
<option>GERENCIAMENTO E IMPLANTAÇÃO DE PROJETOS</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-12 col-md-offset-2">
<div class="clearfix">
<div class="mb-20 mb-md-10">
<h4>ANEXE SEU CURRICULO</h4>
<input type="file" id="exampleInputFile" name"send">
</div>
<!-- Send Button -->
<div class="align-left pt-10">
<button class="submit_btn btn btn-mod btn-medium btn-round" id="submit_btn">Enviar Mensagem</button>
</div>
<div id="result"></div>
</form>
</form>
</div>
</div>
</div>
</div></div></div>
<!-- End Contact Form -->
</div>
</section>
<!-- End Contact Section -->
PHP:
<?php
if ($_POST) {
$to_Email = "[email protected]"; //Replace with recipient email address
$subject = 'Mensagem do site ' . $_SERVER['SERVER_NAME']; //Subject line for emails
//check if its an ajax request, exit if not
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
//exit script outputting json data
$output = json_encode(array(
'type' => 'error',
'text' => 'Request must come from Ajax'
));
die($output);
}
//check $_POST vars are set, exit if any missing
if (!isset($_POST["userName"]) || !isset($_POST["userEmail"]) || !isset($_POST["userCity"]) || !isset($_POST["userGenderf"]) || !isset($_POST["userGenderm"]) || !isset($_POST["userSend"])) {
$output = json_encode(array(
'type' => 'error',
'text' => 'Campos Vazios!'
));
die($output);
}
//Sanitize input data using PHP filter_var().
$user_Name = filter_var($_POST["userName"], FILTER_SANITIZE_STRING);
$user_Email = filter_var($_POST["userEmail"], FILTER_SANITIZE_EMAIL);
$user_City = filter_var($_POST["userCity"], FILTER_SANITIZE_STRING);
$user_Genderf = filter_var($_POST["userGenderf"], FILTER_SANITIZE_STRING);
$user_Genderm = filter_var($_POST["userGenderm"], FILTER_SANITIZE_STRING);
$user_Send = filter_var($_POST["userSend"], FILTER_SANITIZE_STRING);
//additional php validation
if (strlen($user_Name) < 4) // If length is less than 4 it will throw an HTTP error.
{
$output = json_encode(array(
'type' => 'error',
'text' => 'Name is too short or empty!'
));
die($output);
}
if (!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
{
$output = json_encode(array(
'type' => 'error',
'text' => 'Please enter a valid email!'
));
die($output);
}
//proceed with PHP email.
$headers = 'From: ' . $user_Email . '' . "\r\n" . 'Reply-To: ' . $user_Email . '' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
$sentMail = @mail($to_Email, $user_City, $user_Genderf, $user_Genderm, $user_Send, $user_Selection . "\r\n\n" . '-- ' . $user_Name . "\r\n" . '-- ' . $user_Email, $headers);
if (!$sentMail) {
$output = json_encode(array(
'type' => 'error',
'text' => 'Could not send mail! Please check your PHP mail configuration.'
));
die($output);
} else {
$output = json_encode(array(
'type' => 'message',
'text' => 'Olá ' . $user_Name . '! Recebemos seu email'
));
die($output);
}
}
?>
CONTACT-FORM
/* ---------------------------------------------
Contact form
--------------------------------------------- */
$(document).ready(function(){
$("#submit_btn").click(function(){
//get input field values
var user_name = $('input[name=name]').val();
var user_email = $('input[name=email]').val();
var user_city = $('input[name=city]').val();
var user_gender = $('input[name=gender]').val();
var user_send = $('input[name=send]').val();
//simple validation at client's end
//we simply change border color to red if empty field using .css()
var proceed = true;
if (user_name == "") {
$('input[name=name]').css('border-color', '#e41919');
proceed = false;
}
if (user_email == "") {
$('input[name=email]').css('border-color', '#e41919');
proceed = false;
}
//everything looks good! proceed...
if (proceed) {
//data to be sent to server
post_data = {
'userName': user_name,
'userEmail': user_email,
'userCity': user_city,
'userGender': user_gender,
'userSend' : user_send,
};
//Ajax post data to server
$.post('contact_me.php', post_data, function(response){
//load json data from server and output message
if (response.type == 'error') {
output = '<div class="error">' + response.text + '</div>';
}
else {
output = '<div class="success">' + response.text + '</div>';
//reset values in all input fields
$('#contact_form input').val('');
}
$("#result").hide().html(output).slideDown();
}, 'json');
}
return false;
});
//reset previously set border colors and hide all message on .keyup()
$("#contact_form input").keyup(function(){
$("#contact_form input").css('border-color', '');
$("#result").slideUp();
});
});
Did it work before? What did you change to stop it? An error appears on the page or console?
– hugocsl
Yes, is appearing Input Fields are Empty!
– Cris Credie
Can you help me one more time @hugocsl?
– Cris Credie
Cris in this I can not pq I do not know anything PHP, but it was probably some input that you removed from the html form and that is still in the PHP code, then it is empty because it is not filled. Or else the action is not searching the data of the two presses at the same time when sending... I do not understand much of this part :/ . I just questioned you, because in more detail it’s easier for someone to help you understand...
– hugocsl
Oh yes, I understand perfectly. Do you know any easier way to send these forms to emails than via php?
– Cris Credie
I don’t know unfortunately... when I need to get something ready... but look for Phpmailer, there are some tutorials that can help you!
– hugocsl
Cool, thanks again!!! : ) I will look for yes.
– Cris Credie
if I am not mistaken you have 2 <form> tags and only 1 is closed. The error can come from there. Then if you have 2 presses should not be separated ? because it’s inside each other??
– joao dias
@joaodias even so the error persists...already fixed the tag that was open and continues to inform that some input field is empty.
– Cris Credie
you can post the code for me to see. Or update your code on top so we can see
– joao dias
@joaodias just edited, and I’m getting an error : PHP Fatal error: Cannot use isset() on the result of an Expression (you can use "null !== Expression" Instead)
– Cris Credie