нужна помощь с формой

  • Автор темы seosius
  • 35
  • Обновлено
  • 17, May 2024
  • #1
Здравствуйте, милые люди.

У меня есть эта форма, которая меня озадачивает (что меня никак). Это работает (с ненужными предупреждениями), если я отправлю его дважды.

Я знаю, это много но ты видишь мою ошибку? ------------------------------------------------- это код:
 <!DOCTYPE HTML><html>

<head>

<style>

.error {color: #FF0000;}

</style>

</head>

<body bgcolor="ccffff"><center><b>

<?php

echo "<center>";echo date('m/d/y');echo "</center>";

// define variables and set to empty values

$tenantErr = $unitErr = $rentpaidErr = $datepaidErr = $commentErr = "";

$tenant = $unit = $rentpaid = $hudpay = $datepaid = $comment = "";

if ($_SERVER["REQUEST_METHOD"] == "POST")

{

if (empty($_POST["tenant"])) { $tenantErr = "tenant is required"; }

else {

$tenant = test_input($_POST["tenant"]);

// check if tenant only contains letters and whitespace

if (!preg_match("/^[a-zA-Z-' ]*$/",$tenant)) {

$tenantErr = "Only letters and white space allowed"; }

}

}

if (empty($_POST["unit"])) {

$unitErr = "unit is required";

}

else {

$unit = test_input($_POST["unit"]);

// check if unit only contains letters and whitespace

if (!preg_match("/^[a-zA-Z-' ]*$/",$unit)) {

$unitErr = "Only letters and white space allowed";

}

}

if (empty($_POST["rentpaid"])) {

$rentpaidErr = "rentpaid is required";

}

else {

$rentpaid = test_input($_POST["rentpaid"]);

// check if rentpaid only contains letters and whitespace

if (!preg_match("/^[a-zA-Z-' ]*$/",$rentpaid)) {

$rentpaidErr = "Only letters and white space allowed";

}

}

if (empty($_POST["hudpay"])) {

$hudpayErr = "hudpay is required";

}

else {

$hudpay = test_input($_POST["hudpay"]);

// check if hudpay only contains letters and whitespace

if (!preg_match("/^[a-zA-Z-' ]*$/",$hudpay)) {

$hudpayErr = "Only letters and white space allowed";

}

}

if (empty($_POST["datepaid"])) {

$datepaidErr = "datepaid is required";

}

else {

$datepaid = test_input($_POST["datepaid"]);

// check if datepaid only contains letters and whitespace

if (!preg_match("/^[a-zA-Z-' ]*$/",$datepaid)) {

$datepaidErr = "Only letters and white space allowed";

}

}

if (empty($_POST["comment"])) {

$comment = "";

}

else {

$comment = test_input($_POST["comment"]);

}

function test_input($data) {

$data = trim($data);

$data = stripslashes($data);

$data = htmlspecialchars($data);

return $data;

}

?>

<h3>Fill in form for rent payment</h3>

<p><span class="error">* required field</span></p>

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

Tenant: <input type="text" name="tenant" value="<?php echo $tenant;?>">

<span class="error">* <?php echo $tenantErr;?></span>

<br><br>

Unit: <input type="text" name="unit" value="<?php echo $unit;?>">

<span class="error">* <?php echo $unitErr;?></span>

<br><br>

Rentpaid: <input type="text" name="rentpaid" value="<?php echo $rentpaid;?>">

<span class="error">* <?php echo $rentpaidErr;?></span>

<br><br>

Hudpay: <input type="text" name="hudpay" value="<?php echo $hudpay;?>">

<span class="error">* <?php echo $hudpayErr;?></span>

<br><br>

Datepaid: <input type="text" name="datepaid" value="<?php echo $datepaid;?>">

<span class="error">* <?php echo $datepaidErr;?></span>

<br><br>

Comment: <textarea name="comment" rows="2" cols="100"><?php echo $comment;?></textarea>

<br><br>

<input type="submit" name="submit" value="Submit">

</form>

<?php

//echo "<h2>Data for Payment:</h2>";

echo $tenant;echo "<br>";

echo $unit;echo "<br>";

echo $rentpaid;echo "<br>";

echo $datepaid;echo "<br>";

echo $comment;echo "<br>";

?>

</b></center></body></html>


PHP: -----------------------------------------

это внешний вид формы:

06/02/21

Заполните форму для оплаты аренды

* Обязательное поле

Жилец: *

Единица измерения: * требуется единица измерения

Арендная плата: * требуется арендная плата

Hudpay: * требуется hudpay

Дата оплаты: * требуется указать дату оплаты.

Комментарий:

-----------------------------------------

когда я заполняю форму и отправляю это, отображается:

06/02/21

Заполните форму для оплаты аренды

* Обязательное поле

Арендатор: * Разрешены только буквы и пробелы.

Модуль: * Разрешены только буквы и пробелы.

Арендная плата: * Разрешены только буквы и пробелы.

Hudpay: * Разрешены только буквы и пробелы.

Дата оплаты: * Разрешены только буквы и пробелы.

Комментарий: арендатор5 кв.1 530.00 3/8/2021 ----------------------------------

seosius


Рег
01 Jun, 2012

Тем
3

Постов
4

Баллов
34
  • 21, May 2024
  • #2
Эй, попробуй этот код. Я добавил определение этой переменной ($hudpayErr) в начале. Если возникнут еще проблемы с кодом, буду рад помочь.
 <!DOCTYPE HTML><html>

<head>

<style>

.error {color: #FF0000;}

</style>

</head>

<body bgcolor="ccffff"><center><b>

<?php

echo "<center>" . date('m/d/y') . "</center>";

// define variables and set to empty values

$tenantErr = $unitErr = $rentpaidErr = $datepaidErr = $commentErr = $hudpayErr = "";

$tenant = $unit = $rentpaid = $hudpay = $datepaid = $comment = "";

if ($_SERVER["REQUEST_METHOD"] == "POST")

{

if (empty($_POST["tenant"]))

{

$tenantErr = "tenant is required";

}

else

{

$tenant = test_input($_POST["tenant"]);

// check if tenant only contains letters and whitespace

if (!preg_match("/^[a-zA-Z-' ]*$/", $tenant))

{

$tenantErr = "Only letters and white space allowed";

}

}

}

if (empty($_POST["unit"]))

{

$unitErr = "unit is required";

}

else

{

$unit = test_input($_POST["unit"]);

// check if unit only contains letters and whitespace

if (!preg_match("/^[a-zA-Z-' ]*$/", $unit))

{

$unitErr = "Only letters and white space allowed";

}

}

if (empty($_POST["rentpaid"]))

{

$rentpaidErr = "rentpaid is required";

}

else

{

$rentpaid = test_input($_POST["rentpaid"]);

// check if rentpaid only contains letters and whitespace

if (!preg_match("/^[a-zA-Z-' ]*$/", $rentpaid))

{

$rentpaidErr = "Only letters and white space allowed";

}

}

if (empty($_POST["hudpay"]))

{

$hudpayErr = "hudpay is required";

}

else

{

$hudpay = test_input($_POST["hudpay"]);

// check if hudpay only contains letters and whitespace

if (!preg_match("/^[a-zA-Z-' ]*$/", $hudpay))

{

$hudpayErr = "Only letters and white space allowed";

}

}

if (empty($_POST["datepaid"]))

{

$datepaidErr = "datepaid is required";

}

else

{

$datepaid = test_input($_POST["datepaid"]);

// check if datepaid only contains letters and whitespace

if (!preg_match("/^[a-zA-Z-' ]*$/", $datepaid))

{

$datepaidErr = "Only letters and white space allowed";

}

}

if (empty($_POST["comment"]))

{

$comment = "";

}

else

{

$comment = test_input($_POST["comment"]);

}

function test_input($data)

{

$data = trim($data);

$data = stripslashes($data);

$data = htmlspecialchars($data);

return $data;

}

?>

<h3>Fill in form for rent payment</h3>

<p><span class="error">* required field</span></p>

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">

Tenant: <input type="text" name="tenant" value="<?php echo $tenant; ?>">

<span class="error">* <?php echo $tenantErr; ?></span>

<br><br>

Unit: <input type="text" name="unit" value="<?php echo $unit; ?>">

<span class="error">* <?php echo $unitErr; ?></span>

<br><br>

Rentpaid: <input type="text" name="rentpaid" value="<?php echo $rentpaid; ?>">

<span class="error">* <?php echo $rentpaidErr; ?></span>

<br><br>

Hudpay: <input type="text" name="hudpay" value="<?php echo $hudpay; ?>">

<span class="error">* <?php echo $hudpayErr; ?></span>

<br><br>

Datepaid: <input type="text" name="datepaid" value="<?php echo $datepaid; ?>">

<span class="error">* <?php echo $datepaidErr; ?></span>

<br><br>

Comment: <textarea name="comment" rows="2" cols="100"><?php echo $comment; ?></textarea>

<br><br>

<input type="submit" name="submit" value="Submit">

</form>

<?php

//echo "<h2>Data for Payment:</h2>";

echo $tenant;

echo "<br>";

echo $unit;

echo "<br>";

echo $rentpaid;

echo "<br>";

echo $datepaid;

echo "<br>";

echo $comment;

echo "<br>";

?>

</b></center></body></html>

PHP:
 

fAcknet


Рег
29 Apr, 2012

Тем
0

Постов
2

Баллов
2
Тем
49554
Комментарии
57426
Опыт
552966

Интересно