I changed the html of the form, now the php file does not respond

Asked

Viewed 87 times

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: &#160;<input type="text" name="city" size="27" maxlength="70"><br><br> 
                SEXO:&#160;&#160;&#160;<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?

  • Yes, is appearing Input Fields are Empty!

  • Can you help me one more time @hugocsl?

  • 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...

  • Oh yes, I understand perfectly. Do you know any easier way to send these forms to emails than via php?

  • I don’t know unfortunately... when I need to get something ready... but look for Phpmailer, there are some tutorials that can help you!

  • Cool, thanks again!!! : ) I will look for yes.

  • 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??

  • @joaodias even so the error persists...already fixed the tag that was open and continues to inform that some input field is empty.

  • you can post the code for me to see. Or update your code on top so we can see

  • @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)

Show 6 more comments

1 answer

0


I was here correcting your code I hope it helps you, just a form I don’t see why you have a form inside another without counting that you have too many tags and some badly closed I leave you here the code

<?php
if(!isset($_POST['submit']))
{
	//This page should not be accessed directly. Need to submit the form.
	echo "error; you need to submit the form!";
}
$namefirst = $_POST['name_first'];
$contacto = $_POST['contacto'];
$visitor_email = $_POST['email'];
$message = $_POST['comentario'];
$info = $_POST['check1'];
if(count($info) > 0){
   foreach($info as $item){
       $produtos .= $item ."\r\n";
   }
}
$email_from = '[email protected]';//<== update the email address
$email_subject = "Nova Resposta ao Formulario";
$email_body = "Tem um novo pedido de informacoes da pessoa $namefirst . \r\n Contacto nº $contacto . \r\n Email: $visitor_email . \r\n " .
    "Aqui estão os produtos: \r\n $produtos . \r\n " .
    "Aqui estão os comentarios adicionais: \r\n $message . \r\n " .
$to = "[email protected]";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');
<div class="clearfix">
  <form action="contact_me.php" method="post" class="form contact-form" id="contact_form">
    <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: &#160;<input type="text" name="city" size="27" maxlength="70"><br><br>      SEXO:&#160;&#160;&#160;
      <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 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>
      </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>
    </div>
  </form>
</div>

  • Man, thank you very much, but still the php file does not answer. It still appears that the fields are empty. :(

  • your php code cannot be next to the form has to be in contact_me.php I’ll leave you an example here

  • Yes, it’s in a separate file.

  • up there you have an example for a php of mine that also had multiple choice

  • was here to see your code is right at least php the error must be in contact form but also I am not expert in php to see if someone detects something that I do not see

  • Man, I can’t find this mistake...?

  • Parse error: syntax error, Unexpected ']' in contact_us.php on line 22

Show 2 more comments

Browser other questions tagged

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