dongzhuohan7085 2013-06-09 15:07
浏览 42
已采纳

PHP:获取TEXTBOX的值然后将其传递给VARIABLE

My Problem is:

I want to get the value of textbox1 then transfer it to another page where the value of textbox1 will be appeared in the textbox2.

Below is my codes for PHP:

<html>
<body>

<form name='form' method='post' action="testing2.php">

Name: <input type="text" name="name" id="name" ><br/>

<input type="submit" name="submit" value="Submit">  

</form>
</body>
</html>

I also add the code below and the error is "Notice: Undefined index: name"

<?php 
$name = $_GET['name'];
echo $name;
?>

or

<?php 
$name = $_POST['name'];
echo $name;
?>
  • 写回答

4条回答 默认 最新

  • douqiu9529 2013-06-09 15:20
    关注

    In testing2.php use the following code to get the name:

    if ( ! empty($_POST['name'])){
        $name = $_POST['name']);
    }
    

    When you create the next page, use the value of $name to prefill the form field:

    Name: <input type="text" name="name" id="name" value="<?php echo $name; ?>"><br/>
    

    However, before doing that, be sure to use regular expressions to verify that the $name only contains valid characters, such as:

    $pattern =  '/^[0-9A-Za-zÁ-Úá-úàÀÜü]+$/';//integers & letters
    if (preg_match($pattern, $name) == 1){
        //continue
    } else {
        //reload form with error message
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用