无法在PHP中使用HTML表单发布 [英] unable to use html form post in php

查看:105
本文介绍了无法在PHP中使用HTML表单发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我有一个HTML表单,我发布的数据,但我无法获得张贴的数据在PHP页面(同一页)
你能帮我。
提前致谢

 < div class =left> 
< form name =form_signinmethod =postonsubmit =return signinValid(); >
< table>
< tr>
< td>
电子邮件地址:
< / td>
< td>
< input type =textid =emaillength =40>
< / td>
< / tr>
< tr>
< td>
Mot de Passe:
< / td>
< td>
< input type =passwordid =passlength =40>
< / td>
< / tr>
< tr>
< td>
& nbsp;
< / td>
< td>
< input type =submitvalue =Connexionlength =40>
< / td>
< / tr>

< / table>


< / form>

 <?php 
include'includes.php';
包含DB_CONNECT_FILE;
// session_start();
print_r($ _ POST); //打印一个空数组,即使填充了字段

$ smart-> assign('tpl_file',TEMPLATES_DIR.'signin.html');
$ smart-> display(TEMPLATES_DIR。with_right.html);

包含DB_DISCONNECT_FILE;

?>


解决方案

您的表单元素需要执行操作属性已定义,即使表单只是重新发布到同一页面。根据W3C规范,它是一个必需的属性:

http://www.w3.org/TR/html401/interact/forms.html#h-17.3



我很惊讶这行不会引发错误:

$ $ $ $ $ $ $ $ smart-> assign(' tpl_file 'TEMPLATES_DIR.'signin.html');

据我所知,回声时只能使用逗号分隔。



更新
不能相信我第一次错过!您需要将 name 属性添加到输入元素。它们可以与所讨论的元素的 id 属性相同:

 <输入类型=textid =emailname =emailsize =40> 

另外,没有像 length 这样的属性。有 maxlength ,但我怀疑你的意思是使用 size


Hello i have an html form and i'm posting data but i'm unable to get the posted data on a php page (same page) can you please help me. thanks in advance

<div class="left">
<form name="form_signin" method="post" onsubmit="return signinValid();" >
    <table>
        <tr>
            <td>
                Email :
            </td>
            <td>
                <input type="text" id="email" length ="40">
            </td> 
        </tr>
        <tr>
            <td>
                Mot de Passe :
            </td>
            <td>
                <input type="password" id ="pass" length ="40">
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
            <td>
                <input type="submit" value="Connexion" length ="40">
            </td>
        </tr>

    </table>


</form>

<?php
include 'includes.php';
include DB_CONNECT_FILE;
//session_start();
print_r($_POST); // prints an empty array even if fields are filled

$smart->assign('tpl_file',TEMPLATES_DIR.'signin.html');
$smart->display(TEMPLATES_DIR."with_right.html");

include DB_DISCONNECT_FILE;

?>

解决方案

Your form element needs to have an action attribute defined, even if the form is just reposting to the same page. According to the W3C spec, it is a required attribute:

http://www.w3.org/TR/html401/interact/forms.html#h-17.3

I'm suprised this line isn't throwing an error:

$smart->assign('tpl_file',TEMPLATES_DIR.'signin.html');

As far as I'm aware, you can only use comma seperation when echo-ing.

UPDATE Can't believe I missed it the first time around! You'll need to add the name attribute to the input elements. They can be the same as the id attribute for the element in question:

<input type="text" id="email" name="email" size="40">

Also, there is no such attribute as length. There is maxlength, but I suspect you mean to use size.

这篇关于无法在PHP中使用HTML表单发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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