J
J
Jacksnow2017-01-08 13:25:04
PHP
Jacksnow, 2017-01-08 13:25:04

How to deal with the form and php code?

Hello guys. Please help me with the order form. I don't know much about PHP at all.
Task number 1 : It is necessary that when you click the "Go to payment" button, it goes to my payment page, but now for some reason it sends it to an empty one.
Task number 2 : It is necessary that if a person chooses the delivery method "Russian Post", he will be redirected to another page (different from other delivery methods, by the total amount)
Explanation:I use a payment form for individuals from Yandex on my website, and there the amount cannot be changed depending on the choice of the person, you can only set the standard one or prescribe the person himself (which looks stupid), I just want him to be redirected to different pages with two different forms of payment with already standard amounts, that is, if he chooses the Russian Post, the amount will increase by the amount of delivery.

HTML:

<div class="col-md-12">
    <label for="dostavka">Cпособ доставки<span> *</span></label>
    <input type="radio" checked name="dostavka" value="Po4ta" />Почта России
    <input type="radio" name="dostavka" value="DL"/>Деловые линии
    <input type="radio" name="dostavka" value="PEC"/>ПЭК
</div>
    <input type="submit" value="Перейти к оплате" onclick="AjaxFormRequest('messegeResult', 'formMain', 'form.php')" />
    </div>

PHP:
if(!empty($_POST['mail'] ))
{
$to = "[email protected]";
$from = 'почта@.ru';
$subject = "Новый заказ";
$message = 'Имя: '.$_POST['name'].'; Телефон: '.$_POST['telephone'].'; E-mail: '.$_POST['mail'].'; Адрес: '.$_POST['adres'].'; Способ доставки: '.$_POST['dostavka'].'; Способ оплаты: '.$_POST['oplata'].'; Коментарии: '.$_POST['coment'].'; ';
$headers = "Content-type: text/html; charset=UTF-8 \r\n";
$headers .= "From: <почта@.ru>\r\n";
$result = mail($to, $subject, $message, $headers);

    if ($result){ 
         header('Location: http:site.ru/oplata.html'); exit;
   }
    else{
        echo "<p>Попробуйте еще раз</p>";
    }
}
else {
echo "<p>Обязательные поля не заполнены.</p>";
}
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Jacksnow, 2017-01-08
@Jacksnow

Made the transition.
Instead of :

if ($result){ 
         header('Location: http:site.ru/oplata.html'); exit;
   }

Registered:
if ($result){ 
         echo '<script>location.replace("http://site.ru/oplata.html");</script>'; exit;
   }

It remains to make the transition to different pages depending on the choice of delivery method.

T
Twelfth Doctor, 2017-01-08
@verdex

Moving to different pages depending on the choice of delivery method:

$dostavka = $_POST['dostavka'];
//если выбрана Почта России
if ($dostavka == 'Po4ta') {
 echo '<script>location.replace("http://url1");</script>'; exit;
}
//если выбрана компания "Деловые линии"
if ($dostavka == 'DL') {
 echo '<script>location.replace("http://url2");</script>'; exit;
}
//если выбрана компания ПЭК
if ($dostavka == 'PEC') {
 echo '<script>location.replace("http://url3");</script>'; exit;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question