[英]PHP validate form on submission
I have a form and in the page I have to validate if values are posted.我有一个表单,在页面中我必须验证是否发布了值。 But when I print the post array I am getting
Array ( )
outside the if
condition.但是当我打印 post 数组时,我在
if
条件之外得到了Array ( )
。 When I try to use print_r()
inside the if
condition, it is not working.当我尝试在
if
条件中使用print_r()
,它不起作用。 The code I am using is below:我正在使用的代码如下:
<?php
print_r($_POST);
if (isset($_POST['submit'])) {
print_r($_POST); // Not Working
}
?>
<form method="post" action="anotherpage.php">
<input type="text" name="course" />
<input type="text" name="location" />
<input type="submit" name="submit" value="GO"/>
</form>
I also tried using a hidden input inside the form and post it.我还尝试在表单中使用隐藏的输入并发布它。 It is also not working.
它也不起作用。
Your form is POSTing to anotherpage.php
, not to the same page.您的表单正在发布到
anotherpage.php
,而不是发布到同一页面。
You can either change your <form>
to post to the same page:您可以更改您的
<form>
以发布到同一页面:
<form method="post">
...
</form>
Or put your PHP code in anotherpage.php
:或者将您的 PHP 代码放在
anotherpage.php
:
<?php
print_r($_POST);
if (isset($_POST['submit'])) {
print_r($_POST);
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.