M
M
Maxim Lesnikov2015-10-09 20:36:33
css
Maxim Lesnikov, 2015-10-09 20:36:33

How to return to the main page from a modal window with a form?

Good evening everyone. Guys tell me please.
Made a feedback form in a modal window. How to make it so that after sending the data, it returns to the main page, but it is better that it be without reloading the page and an inscription about successful sending pops up? I give the code below:
HTML

<form action="form.php" method= "POST">
            <p align="center" style="font-family:NautilusPompiliusRegular;">
                Друзья, <br />
                Вам осталось заполнить данные, и мы Вам перезвоним.<br />
              
            </p>
            <p>
              <label> <span style="font-family:NautilusPompiliusRegular;">Имя</span>
                <input type="text" name="name" class="name-q">
              </label>
            </p>
       <p>
              <label> <span style="font-family:NautilusPompiliusRegular;">Телефон</span>
                <input type="text" name="phone" class="name-q">
              </label>
            </p>
      
            <center><input type="submit" name="submit" value="Купить" class="offer-item__btn malina-font"></center>
        </form>

PHP
<?php 
// если была нажата кнопка "Отправить" 
if($_POST['submit']) {
        $name = substr(htmlspecialchars(trim($_POST['name'])), 0, 1000); 
        $phone =  substr(htmlspecialchars(trim($_POST['phone'])), 0, 1000000); 
        // $to - кому отправляем 
        $to = '[email protected]'; 
        // $from - от кого 
        $from='[email protected]'; 
    $subject = 'Новый запрос с сайта ';
        // функция, которая отправляет наше письмо
        mail($to, $subject, $name, $phone, 'From:'.$from); 
        echo 'Спасибо! Ваше письмо отправлено.'; 
} 
?>


The form works, everything submits. But after sending the data, it opens the form.php file with the inscription "Thank you! Your letter has been sent"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dk-web, 2015-10-09
@dk-web

header('location: index.php') add, after mail like
if without reloading, then it's already js... and submit the form with ajax.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question