skip to Main Content

I have page in HTML CSS JS: https://handmade.company/seo/index.html
on this page i have form

<form class="webform" action="send.php" method="post">
            <input class="webinput" type="text" name="imja" placeholder="Ваше имя">
            <input class="webinput" type="text" name="phone" placeholder="Ваш телефон">
            <input class="webinput" type="text" name="sajt" placeholder="Ваш сайт">
            <input class="webinput_btn" type="submit" value="Отправить запрос">
        </form>

with php file SEND.PHP

<?php
   $imja = $_POST['imja'];
   $phone = $_POST['phone'];
   $sajt = $_POST['sajt'];
   $wrong = 'при отправке сообщения возникли ошибки';
   $good = 'сообщение успешно отправлено';
   if (mail("[email protected]", "Заказ с сайта", "Ваше имя: ".$imja. " Ваш телефон: ".$phone. " 
   Ваш сайт: ".$sajt ,"From: [email protected] rn"))
     {     echo "<script>alert('$good');window.location.href='index.html'</script>;";
     } else {
         echo "<script>alert('$wrong');window.location.href='index.html'</script>";
      }?>

The problem is: when i click input with type="submit" button browser go to page https://handmade.company/seo/send.php and alert and after it it go back to index.html

I want: the page not reload and browser not redirect me to send.php page. I just want alert and nothing should change anymore

i tried to add function with preventDefault onclick on submit input BUT my php stopped working

2

Answers


    1. Remove send.php page
    2. Change method = “post” to method = “get”
    3. Do  document.getElementsByClassName("webform")[0].onsubmit = function( e ) { e.preventDefault(); }
    4. Use JavaScript to get URL parameters which will be the values of the from
    5. Then alert
    Login or Signup to reply.
  1. you can do this with Javascript or Jquery and Ajax. But if you want a simple way. You can try to add to your php file.

       header('Location: https://handmade.company/seo/index.html');
        exit;
    

    replace https://handmade.company/seo/index.html for the url you want

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search