N
N
Napisator2018-11-15 22:59:05
JavaScript
Napisator, 2018-11-15 22:59:05

Why is the php contact form throwing an error?

Good day !
I am writing my first landing page, the problem is in the feedback form.
after filling in and pressing the "send" button, it redirects to the page localhost:3000/php/send.php
where there is one term: Cannot POST /php/send.php
and an error occurs in the console:

Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-KpHv3zgivMSB4dPnfYfqMt2lBibsYvM36EdoBBAsfbM='), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.

content of send.php file:
<?php
$back = "<p><a href=\"javascript: history.back()\">Вернуться назад</a></p>";

if(!empty($_POST['name']) and !empty($_POST['phone']) and !empty($_POST['mail'])
    and !empty($_POST['message'])){
    $name = trim(strip_tags($_POST['name']));
    $phone = trim(strip_tags($_POST['phone']));
    $mail = trim(strip_tags($_POST['mail']));
    $message = trim(strip_tags($_POST['message']));

    mail('[email protected]', 'Пледы',
        'Вам написал: '.$name.'<br />Его номер: '.$phone.'<br />Его почта: '.$mail.'<br />
      Его сообщение: '.$message,"Content-type:text/html;charset=windows-1251");

    echo "Ваши данные успешно отправлено!<Br> Вы получите ответ в 
      ближайшее время<Br> $back";

    exit;
}
else {
    echo "Для отправки сообщения заполните все поля! $back";
    exit;
}
?>

pug file:
form(method="post" action="../../php/send.php")
  label(for="name") Имя:
  input(maxlength="30" type="text" name="name")
  label(for="phone") Телефон:
  input(maxlength="30" type="text" name="phone")
  input(type="submit" value="Отправить")

js file:
function checkForm(form) {

    var name = form.name.value;
    var n = name.match(/^[A-Za-zА-Яа-я ]*[A-Za-zА-Яа-я ]+$/);
    if (!n) {
        alert("Имя введено неверно, пожалуйста исправьте ошибку");
        return false;
    }

    var phone = form.phone.value;
    var p = phone.match(/^[0-9+][0-9- ]*[0-9- ]+$/);
    if (!p) {
        alert("Телефон введен неверно");
        return false;
    }
return true;
}

PS I launch the site through gulp
in gulpfile.js there are no mentions of php files, this one is the first one, do I need to register a block so that it is also transferred to the build folder? And if necessary, how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antony Tkachenko, 2018-11-16
@LemonFox

Because for php to work you need a web server with a php interpreter maybe?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question