我的网络表单中有一个“电话号码”字段。
我还有一个'隐藏'表单字段,其中包含一个unicode电话图标[&#9742]。
为我的网站访问者输入电话号码是可选的。
所以......如果他们选择不在表单的电话号码字段中输入数字,我不希望该图标显示在uploadResults.php页面上。
我只想在他们将数据输入电话号码字段时显示图标。
我不知道如何实现这一目标。但是我已经在表格中包含了一个精简版本和结果[php]页面。
我将非常感谢任何帮助,因为我需要在我网站的几个不同区域中加入相同类型的功能。
提前致谢。
这是表单页面代码:
<!DOCTYPE html>
<html>
<head>
<title>The Form</title>
<style>
.container { margin-top:50px; margin-left:40px; }
.fieldTitle { font-family: Arial, Helvetica, sans-serif; font-size: 12pt; }
.phoneIcon { margin-bottom:10px; display:none;} /* This field hidden in form */
.phoneNumber { margin-top:10px; width:200px; height:25px; font-family:Arial, Helvetica, sans-serif; font-size: 12pt; }
.submitButton { margin-top:30px; font-family:Arial, Helvetica, sans-serif; font-size: 12pt; }
</style>
</head>
<body>
<form action="uploadResults.php" method="post" enctype="multipart/form-data">
<div class="container">
<div class="fieldTitle">Phone Number:</div>
<div><input class="phoneIcon" name="phoneIcon" id="phoneIcon" value="☎" readonly/></div>
<div><input class="phoneNumber" name="phoneNumber" id="phoneNumber" autocomplete="off"/></div>
<div><input class="submitButton" type="submit" name="submit" value="Submit"></button></div>
</div>
</form>
</body>
</html>
这是uploadResults.php页面代码:
<?php ob_start(); ?>
<!DOCTYPE html>
<html>
<head>
<title>Upload Results</title>
<style>
body{margin:0;}
.numberWrapper {margin: 100px 0px 0px 30px; }
.phoneIcon {font-size: 20px;}
.phoneNumber {font-family:Arial, Helvetica, sans-serif; font-size:12pt;}
</style>
</head>
<body>
<div class="numberWrapper">
<span class="phoneIcon"><?php $phoneIcon = ($_POST['phoneIcon']); echo $phoneIcon;?> </span>
<span class="phoneNumber"><?php $phoneNumber = ($_POST['phoneNumber']); echo $phoneNumber;?></span>
</div>
</body>
</html>
<?php echo ''; (ob_get_contents()); ?>
答案 0 :(得分:3)
Check whether telephone number is posted and not equal to null.
<?php ob_start(); ?>
<!DOCTYPE html>
<html>
<head>
<title>Upload Results</title>
<style>
body{margin:0;}
.numberWrapper {margin: 100px 0px 0px 30px; }
.phoneIcon {font-size: 20px;}
.phoneNumber {font-family:Arial, Helvetica, sans-serif; font-size:12pt;}
</style>
</head>
<body>
<?php if( isset($_POST['phoneIcon']) && $_POST['phoneIcon'] != '')
{ ?>
<div class="numberWrapper">
<span class="phoneIcon"><?php $phoneIcon = ($_POST['phoneIcon']); echo $phoneIcon;?> </span>
<span class="phoneNumber"><?php $phoneNumber = ($_POST['phoneNumber']); echo $phoneNumber;?></span>
</div>
<?php } ?>
</body>
</html>
<?php echo ''; (ob_get_contents()); ?>
答案 1 :(得分:1)
试试这个:
Logger.log
答案 2 :(得分:1)
您可以查看下面提到的解决方案
<?php if($_POST['phoneNumber'] != NULL || $_POST['phoneNumber'] != ''): ?>
<div class="numberWrapper">
<span class="phoneIcon"><?php $phoneIcon = ($_POST['phoneIcon']); echo $phoneIcon;?> </span>
<span class="phoneNumber"><?php $phoneNumber = ($_POST['phoneNumber']); echo $phoneNumber;?></span>
</div>
<?php endif; ?>
答案 3 :(得分:1)
您需要使用isset
和empty
<?php
if(isset($_POST['phoneNumber']) && !empty($_POST['phoneNumber']))
{?>
<div class="numberWrapper">
<span class="phoneIcon"><?php $phoneIcon = ($_POST['phoneIcon']); echo $phoneIcon;?> </span>
<span class="phoneNumber"><?php $phoneNumber = ($_POST['phoneNumber']); echo $phoneNumber;?></span>
</div>
<?php}?>