这个代码有什么问题吗? (表单传递变量) [英] What is wrong with this code please? (Form passing variables)

查看:104
本文介绍了这个代码有什么问题吗? (表单传递变量)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码。尝试将表单值从一个内部页面传递到另一个,并且它不工作。

I have this code. Trying to pass form values from one internal page to the other and it's not working.

以下是代码:

Here's the code:

<div data-role="page" id="home">

    <div data-role="header">
        <h1>Page One</h1>
    </div><!-- /header -->

    <div data-role="content">   
        <form action="post" name="myform">
        <input type="text" value="" name="mytext" />
               <input type="submit" value="submit" />
               </form>
    </div><!-- /content -->
</div><!-- /page -->

//和第2页

<div data-role="page" id="page2">

    <div data-role="header">
        <h1>Page Two</h1>
    </div><!-- /header -->

    <div data-role="content">   
        <?php if (isset($_POST['mytext'])) {
  // do something with $_POST['value']
  echo 'it works'; } ?>
    </div><!-- /content -->
</div><!-- /page -->

它基本上不工作...没有错误,但没有数值。

It's basically not working ... no errors but no values either.

推荐答案

很可能错误在这里: $ b

Most likely the error is here:

<form action="post" name="myform">
        <input type="text" value="" name="mytext" />
        <input type="submit" value="submit" />
</form>

动作应该是表单的处理程序,可以是同一页面或另一个页面详细描述表单的PHP脚本)。 POST是方法。(可以是GET或POST)

action is supposed to be the handler of the form, either the same page or another one (where the php script that elaborates the form resides). POST is the METHOD. (which can be either GET or POST)

所以它应该是:

So it should be:

<form action="" method="POST" name="myform">  <!-- action = "" reloads the same page, otherwise you could write action="myphppage.php" or whatever -->
    <input type="text" value="" name="mytext" />
    <input type="submit" value="submit" />
</form>

这篇关于这个代码有什么问题吗? (表单传递变量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆