我很难确定如何修复此通知。我已经做了,但结果是代码没有用。我的逻辑不是代码那么高:
您是否也会解释为什么性别不受影响但是文本框和文本区域没问题呢?
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<?php
if(isset($_POST['submit'])){
$x=$_POST['name'];
$y=$_POST['email'];
$z=$_POST['website'];
$c=$_POST['comment'];
$v=$_POST['gender'];
if($x == '' or $y == '' or $z==''or $c=='' or $v==''){
echo "* required all fields";
}else{
$result=$x.'<br>'.$y.'<br>'.$z.'<br>'.$c.'<br>'.$v;
}
}
?>
<form action="" method="post">
NAME:<input type="text" name="name"><br><br>
EMAIL:<input type="text" name="email"><br><br>
WEBSITE:<input type="text" name="website"><br><br>
<textarea name="comment" rows="5" cols="40"></textarea><br><br>
GENDER:<input type="radio" name="gender" value="Male">MALE
<input type="radio" name="gender" value="Female">Female<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
echo "<h3>YOUR INPUT:</h3>";
echo $result;
?>
</body>
</html>
答案 0 :(得分:1)
raw_input()
您无法让用户或人员查看PHP手册
答案 1 :(得分:0)
试试这种方式
if(($x="" || empty($x))&&($y="" || empty($y))&&($z="" || empty($z)))
{
echo "* required all fields";
}
可能会有所帮助
答案 2 :(得分:0)
您需要的是JS
功能,首先验证您的单选按钮,或者您也可以使用HTML
属性required
(我已经写过它们),然后只有一些if-statements
这应该可以正常工作。
<!DOCTYPE HTML>
<html>
<head>
<script>
function validateForm(){
for(i=0; i<document.form.radios.length; i++){
if(document.form.radios[i].checked==false){
c=1;
}
else{
c=0;
break;
}}
if(c==1){
alert('Please select an option');
}
}
</script>
</head>
<body>
<?php
if(isset($_POST['submit'])){
$x=$_POST['name'];
$y=$_POST['email'];
$z=$_POST['website'];
$c=$_POST['comment'];
if($x == '' or $y == '' or $z==''or $c=='')
{ echo "* required all fields";
}else{
$result=$x.'<br>'.$y.'<br>'.$z.'<br>'.$c;
}
}
?>
<form action="" method="post">
NAME:<input type="text" name="name"><br><br>
EMAIL:<input type="text" name="email"><br><br>
WEBSITE:<input type="text" name="website"><br><br>
<textarea name="comment" rows="5" cols="40"></textarea><br><br>
<input type="radio" name="gender" value="Male" required /> Male
<input type="radio" name="gender" value="Female" /> Female
<input type="submit" name = "submit" value="SAVE" />
</form>
<?php
if(isset($_POST['submit']))
{
if(!($x == '' or $y == '' or $z==''or $c=='')){
echo "<h3>YOUR INPUT:</h3>";
echo $result;
}else
echo "NOT ALL FIELDS WERE SELECTED.";}
?>
</body>
</html>
答案 3 :(得分:0)
你有一些未定义的变量。为了使其工作,试试这个:
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<?php
$result = '';
$x = '';
$y = '';
$z = '';
$c = '';
$v = '';
if(isset($_POST['submit'])){
if(isset($_POST['name'])){
$x= $_POST['name'];
}
if(isset($_POST['email'])){
$y=$_POST['email'];
}
if(isset($_POST['website'])){
$z=$_POST['website'];
}
if(isset($_POST['comment'])){
$c=$_POST['comment'];
}
if(isset($_POST['gender'])){
$v=$_POST['gender'];
}
.......
但是你应该将你的HTML代码与PHP分开, 也许创建和index.html和from.php文件。 将所有文件保存到同一个文件中是一种非常糟糕的做法。
答案 4 :(得分:0)
<div class="ui four cards">
<%= link_to {controller: 'apps', action: 'show'}, {class: "red card"} do %>
<div class="image">
<%= image_tag("white-image.png") %>
</div>
<div class="ui bottom attached button">
<i class="fa fa-cloud-upload"></i>
<span class="little-space"></span>
Deploy
</div>
<% end %>
</div>