douluan5523 2017-06-14 06:49
浏览 51
已采纳

仅在以相同形式在另一个字段中输入数据时传递表单字段数据

I have a 'Phone Number' field in my web form.

I also have a 'hidden' form field which contains a unicode phone icon [&#9742].

Entering a phone number is optional for my site visitors.

So... if they chose not to enter a number in the phone number field of the form, I do not want the icon to be shown on the uploadResults.php page.

I only want the icon to appear if they enter data into the phone number field.

I have no idea how to achieve this. But I have included a stripped down version of the form, and the result [php] page in my question.

Any help would be greatly appreciated, as I will need to incorporate this same type of function in a few different areas of my site.

Thanks in advance.

Here is the form page code:

    <!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="&#9742;" 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>

And here is the uploadResults.php page code:

    <?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;?>&nbsp;</span>
    <span class="phoneNumber"><?php $phoneNumber = ($_POST['phoneNumber']); echo  $phoneNumber;?></span>
    </div>


    </body>
    </html>

    <?php echo ''; (ob_get_contents()); ?>
  • 写回答

4条回答 默认 最新

  • duanshan2988 2017-06-14 06:55
    关注

    You can check below mentioned solution

    <?php if($_POST['phoneNumber'] != NULL || $_POST['phoneNumber'] != ''): ?>
          <div class="numberWrapper">
        <span class="phoneIcon"><?php $phoneIcon = ($_POST['phoneIcon']); echo  $phoneIcon;?>&nbsp;</span>
        <span class="phoneNumber"><?php $phoneNumber = ($_POST['phoneNumber']); echo  $phoneNumber;?></span>
        </div>
    <?php endif; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 ue5运行的通道视频都会有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数