Option and file upload values do not arrive by form

Asked

Viewed 23 times

0

I was finally able to finalize the file submission form. The email reaches my inbox but without the file and without the value of Selection, from where the customer marks the option. Could someone give me a glimpse of where I’m going wrong?

/* ---------------------------------------------
 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_selection = $('input[name=selection]').val();
        var user_message = $('textarea[name=message]').val();
        var user_send =$('file[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;
        }
        
        if (user_message == "") {
            $('textarea[name=message]').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,
                'userSelection' : user_selection,
                'userMessage': user_message,
                '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('');
                    $('#contact_form textarea').val('');
                    $('#contact_form file').val('');
                }
                
                $("#result").hide().html(output).slideDown();
            }, 'json');
            
        }
        
        return false;
    });
    
    //reset previously set border colors and hide all message on .keyup()
    $("#contact_form input, #contact_form textarea").keyup(function(){
        $("#contact_form input, #contact_form textarea").css('border-color', '');
        $("#result").slideUp();
    });
    
});
<!-- Contact Form -->                            
                    <div class="row">
                        <div class="col-md-6 col-md-offset-0">
                        <form class="form contact-form" id="contact_form">
                                <div class="clearfix">
                                      <!-- Form -->
                                    
    				      <!-- Nome -->
    				      NOME:
    				        <div class="form-group">
    				        <input type="text" name="name" id="name" class="input-md round form-control" pattern=".{3,100}" required>
                                        </div>
                                       <!-- Email -->
                                      EMAIL:
                                        <div class="form-group">
                                        <input type="email" name="email" id="email" class="input-md round form-control"  pattern=".{5,100}" required>
                                        </div>
                                      CIDADE:
                                        <!-- Cidade -->
                                        <div class="form-group">
                                        <input type="text" name="city" id="city" class="input-md round form-control"  pattern=".{5,100}" required>
                                        </div>
     				      MENSAGEM:
	 				<div class="form-group">                                            
                                        <textarea name="message" id="message" class="input-md round form-control" style="height: 118px;" ></textarea>
                                        </div></div>
     
        <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-6 col-md-offset-6">
      <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>

                    
                    <!-- End Contact Form -->
                    
                </div>
            </section>
            <!-- End Contact Section -->

  • Inside each option should have the tag value with the value that will be sent by the form. example: <option value="arroz">Arroz</option>

  • MESSAGE TEST 12 >> CRISTINA FERNANDES >> [email protected] >> SÃO PAULO >> >> @Viniciusdejesus still appears empty even with the option marked.

  • Find the PHP code that receives the form data, and update the options to see if there are any other errors.

No answers

Browser other questions tagged

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