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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改