php - The validation not working after there is redirection in the form -
i'm trying validate , redirect page 2 variables(dates). validation going if don't redirect page. if use
action = "pagingstatic.php"
the validation not working.
here code:
<!doctype html> <html> <head> <title>Въвеждане на дата</title> <link rel="stylesheet" type="text/css" href="style.css"> <meta charset="utf-8"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <?php // define variables , set empty values function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } $from_dateerr = $to_dateerr = ''; $from_date = $to_date = ''; if ($_server["request_method"] == "get") { $valid = true; if (empty($_get["from_date"]) or empty($_get["to_date"])) { $from_dateerr = "Задължително поле"; $to_dateerr = "Задължително поле"; } else { $from_date = test_input($_get["from_date"]); $to_date = test_input($_get["to_date"]); // check if name contains letters , whitespace if (!preg_match("/[0-9\\-]/",$from_date)or !preg_match("/[0-9\\-]/",$to_date)) { $from_dateerr = "формат: 0-9 и разделящи символи - и /"; $to_dateerr = "формат: 0-9 и разделящи символи - и /"; } } } ?> <div class = "login-box"> <p class="headp">Язовир Искър</p> <div class = "login"> <!-- action = "pagingstatic.php" logo nek <div class="image"></div> --> <p>Зареждане на таблица от postgresql по зададена дата.</p> <p><span class="error">* required field.</span></p> <form action = "pagingstatic.php" method = "get"> <label for="odata">От дата</label> <input type = "text" name = "from_date"> <span class="error">* <?php echo $from_dateerr;?></span> <br /> <label for="odata">До дата</label> <input type = "text" name = "to_date"> <span class="error">* <?php echo $from_dateerr;?></span> <input type = "submit" name = "submit" value = "Покажи таблица"> </form> </div> </div> <?php echo "<h2>your input:</h2>"; echo $from_date; echo "<br>"; echo $to_date; echo "<br>"; echo $act; ?> </body> </html>
can give me suggestions?
thanks help! here code:
<!doctype html> <html> <head> <title>Въвеждане на дата</title> <link rel="stylesheet" type="text/css" href="style.css"> <meta charset="utf-8"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <?php // define variables , set empty values function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } $from_dateerr = $to_dateerr = ''; $from_date = $to_date = $act = ''; if ($_server["request_method"] == "get") { $valid = true; if (empty($_get["from_date"]) or empty($_get["to_date"])) { $from_dateerr = "Задължително поле"; $to_dateerr = "Задължително поле"; $valid = false; } else { $from_date = test_input($_get["from_date"]); $to_date = test_input($_get["to_date"]); // check if name contains letters , whitespace if (!preg_match("/[0-9\\-]/",$from_date)or !preg_match("/[0-9\\-]/",$to_date)) { $from_dateerr = "формат: 0-9 и разделящи символи - и /"; $to_dateerr = "формат: 0-9 и разделящи символи - и /"; $valid = false; } } //if valid action redirect if($valid){ header("location:pagingstatic.php?".$_server['query_string']); exit(); } } ?> <div class = "login-box"> <p class="headp">test</p> <div class = "login"> <!-- action = "pagingstatic.php" logo nek <div class="image"></div> --> <p>Зареждане на таблица от postgresql по зададена дата.</p> <p><span class="error">* required field.</span></p> <form method = "get"> <label for="odata">От дата</label> <input type = "text" name = "from_date"> <span class="error">* <?php echo $from_dateerr;?></span> <br /> <label for="odata">До дата</label> <input type = "text" name = "to_date"> <span class="error">* <?php echo $from_dateerr;?></span> <input type = "submit" name = "submit" value = "Покажи таблица"> </form> </div> </div> <?php echo "<h2>your input:</h2>"; echo $from_date; echo "<br>"; echo $to_date; echo "<br>"; echo $act; ?> </body> </html>
you should use session hold value.but can try this:
if($valid){ header("location:somepage.php?".$_server['query_string']); exit(); }
Comments
Post a Comment