doumao1917 2017-11-09 22:56
浏览 43

将变量从html输入传递到包含的php文件

I have situation where I have an accordian and I am referencing a php file gridlist.php within another php file displayvar.php. In other words the context of displayvar.php are shown in the webpage gridlist.php. Now gridlist.php has a checkbox input:

 <input type="checkbox" id="foodlike" value="icecrm">I like ice cream</input>
 <input type="checkbox" id="foodlike" value="pizza">I like pizza</input>
 <input type="checkbox" id="foodlike" value="soda">I like soda</input>

Now when I check on the checkboxes in the table referenced by gridlist.php displayvar.php should be able to display a list of the items checked. For instance it should display if all three checkboxes are checked:

 icecrmpizzasoda

If the last one is checked then only soda should be displayed. Keep in mind because this displayvar.php is displayed within the context of the website gridlist.php I used the following command in gridlist.php:

<?php include 'displayvar.php'; ?>

I tried in the displayvar.php to obtained the variables foodlike (as defined by the variable id in the checkbox gridlist.php) from gridlist.php and then echo them based on this snippet of code:

<?php

   $like=$_POST['foodlike'];
   echo "$like";

?>

How can I tweak this code to get my desired result?

  • 写回答

2条回答 默认 最新

  • douhuiyan2772 2017-11-09 23:29
    关注

    You can achieve this with :

    gridlist.php

    <form method="post" action="displayvar.php">
        <input type="checkbox" name="icecrm" value="icecrm">I like ice cream</input>
        <input type="checkbox" name="pizza" value="pizza">I like pizza</input>
        <input type="checkbox" name="soda" value="soda">I like soda</input>
        <input type="submit" value="Submit">
    </form>
    

    displayvar.php

    <?php
        $icecrm = isset($_POST['icecrm']) ? $_POST['icecrm'] : null;
        $pizza = isset($_POST['pizza']) ? $_POST['pizza'] : null;
        $soda = isset($_POST['soda']) ? $_POST['soda'] : null;
    
        echo is_null($soda) ? $icecrm.$pizza : $soda;
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据