C
C
Chemodancheek2016-02-06 11:51:01
PHP
Chemodancheek, 2016-02-06 11:51:01

Why is the data from the contact form not being transferred?

Good afternoon! Dear experts, help.
There is a site template, but the feedback form does not work. The letter comes empty, although all data: name, mail and message are filled in.
Main: pastebin.com/GP1Fyn1C
JS script, which (if I understand correctly) is involved in sending the message: pastebin.com/qzceacQx
Sending PHP code: pastebin.com/Wc6LU3CA
I have unlimited respect and respect :)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vitaly Inchin ☢, 2016-02-07
@Chemodancheek

$.ajax({
url: $(this).attr('action')
});

In general, it's brilliant - just make a request and not send data, and then be surprised that they did not come.
//Contact form
$('#main-contact-form').submit(function(e){
    (e||event).preventDefault();
    
    var $this = $(this), $form_status = $('<div class="form_status"></div>');
    //Отправляем запрос
    $.ajax({
        url  : $this.attr('action'),
        type: "post",
        data: $this.serialize(),
        beforeSend: function(){
                $this.prepend( $form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn() );
        }
    }).done(function(data){
         $form_status.html('<p class="text-success">Thank you for contact us. As early as possible  we will contact you</p>').delay(3000).fadeOut();
    });
});

V
VZVZ, 2016-02-06
@VZVZ

So you don’t send form fields anywhere in JS. Just make an AJAX request to the action and that's it.
Or am I stupid, and jQuery is smarter than me, and even in such a situation it guesses that it is necessary to send the fields?))) I doubt it.
In general, I advise the Fiddler sniffer for such cases, it keeps a log of requests from the client to the server, you look at the log and it’s immediately clear whether the client sent the right request, and if it’s correct, then there is a problem on the server

M
Maxim Timofeev, 2016-02-06
@webinar

1. PHP has $_POST['subject'], while there is no such field in the form. I do not think that because of this, but it should be corrected in any case.
2. Check what goes in the ajax request.
3. If everything is OK in paragraph 2, then you can still try to replace

$name       = $_POST['name'];
$from       = $_POST['email'];
$subject    = $_POST['subject'];
$message    = $_POST['message'];

on the
$name       = @trim(stripslashes($_POST['name']));
$from       = @trim(stripslashes($_POST['email']));
$subject    = @trim(stripslashes($_POST['subject']));
$message    = @trim(stripslashes($_POST['message']));

and see what comes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question