A
A
Alex2018-03-18 19:10:11
PHP
Alex, 2018-03-18 19:10:11

How to substitute the name of the product in the application form using PHP?

Good day!
I have a submit form like this:

<form action="zakaz.php" method="post" >
<input type="text" name="name" placeholder="Имя" required>
<input type="text" name="pole2" placeholder="Второе поле" >
<input class="button" type="submit" value="Отправить заявку" />
</form>

<?
{
$email="[email protected]"; 
$headers  =  'MIME-Version: 1.0' . "\r\n";
$headers .=  'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .=  'From: <Заказ>' . "\r\n"; 
$subject    = "Заявка"; 
$message    = "
Имя: ".$_POST['name']."
// Сюда вставить pole2
";
$mail=mail($email, $subject, $message, $headers);
if($mail==true){
?>
<html>
Спасибо за заказ!
</html>
<?
}else{
    echo "no";
}
}
?>

I need to make it so that when entering data in the second input (pole2) in the application, data comes in according to the "If - Then" principle.
For example, if a person entered "1" - "1 Spb" should come in the application.
If you entered "2" - the application should be "2 Moscow".
Etc.
As I understand it, you need to first assign a variable:
<?php
$pole2 = $_POST['pole2'];
?>

And then you need to somehow list all the options through if - elseif. But, since I don't know PHP, I can't figure out how to substitute the received data in $message.
In general, I will be extremely grateful to the experts for their help!)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ipokos, 2018-03-18
@Xandrick

// $input = $_POST['pole2'];  при получении данных от пользователя, их нужно проверять, и хоть как то очистить
$input  = trim(strip_tags($_POST['pole2'])); // это очень примитивный пример. Но суть я думая ясна.. тут очищаем сообщение от html тегов и удаляем пробелы
$message = ''; // пустая переменная для сообщения
if($input == '1'){
    $message = 'текст в первом случае';
}elseif($input == 'text'){
    $message = 'текст во втором случае';
}else{
    $message = 'текст если нет подходящих условий';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question