作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的网络表单中有一个“电话号码”字段。
我还有一个“隐藏”表单字段,其中包含一个 unicode 电话图标 [☎]。
对于我的站点访问者来说,输入电话号码是可选的。
所以...如果他们选择不在表单的电话号码字段中输入数字,我不希望图标显示在 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()); ?>
最佳答案
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()); ?>
关于javascript - 仅当在同一表单的另一个字段中输入数据时才传递表单字段数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44537436/
我是一名优秀的程序员,十分优秀!