简单的表单不通过_POST发送数据 [英] Simple form not sending data via _POST

查看:127
本文介绍了简单的表单不通过_POST发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哇,所以这很尴尬。这应该是另一个无聊的网络形式。我以前做过很多,但由于某种原因,这个特定的人不想合作。我不知何故失去了一些东西?我一直试图弄清楚这几个小时。我发誓我已经尝试故障排除一切,没有任何运气。



基本上,我试图通过$ _POST发送到PHP文件。最终我会使用AJAX,但现在我甚至无法将POST的愚蠢的东西。所以当你点击提交时,它会转到正确的页面。但是我得到一个错误Undefined Index(然后指向我称之为$ _POST变量的行)。我已经注释了PHP端(signup1.php)上的所有内容,现在它所做的只是 var_dump($ _ POST); 这样我就可以看到数据,它不会从_POST获取任何东西,愚蠢的东西是空的,我真的认为问题出在HTML端。 。它有很多额外的格式和布局的目的,我会保留所有的内容,以防万一是错误的原因,也许你们中的一个人会知道,另外,你可能会注意到我正在使用bootstrap。也许这是什么?我已经使用bootstrap来处理表单,它的工作,但是谁知道。

 < form action =actions / signup1.phpmethod =post> 
< div class =row>
< div class =col-md-6>
< div class =form-group>
< label for =name>名称:< / label>
< input type =textid =nameclass =form-controlplaceholder =John Smith>
< / div>
< / div> <! - 名称输入栏末尾 - >
< div class =col-md-6>
< div class =form-group>
< label for =phone>电话号码:< / label>
< input type =textid =phoneclass =form-controlplaceholder =801-321-9876>
< / div>
< / div> <! - 电话号码输入栏末尾 - >
< / div> <! - 输入的第一行的结束 - >

< div class =row>
< div class =col-md-6 column-sm-12>
< div class =form-group>
< label for =email>电子邮件地址:< / label>
< input type =textid =emailclass =form-controlplaceholder =johnsmith@me.com>
< / div>
< / div> <! - 电子邮件地址输入栏末尾 - >

< div class =col-md-3 col-sm-6>
< div class =form-group>
< label for =city>城市:< / label>
< select id =cityclass =form-control>
< option>拉斯维加斯< / option>
< option>盐湖城< / option>
< option>我会稍后选择一个默认值...< / option>
< / select>
< / div>
< / div> <! - 城市下拉式结束 - >

< div class =col-md-3 col-sm-6>
< div class =form-group>
< label for =类型的电话>电话类型:< / label>
< select id =type-of-phoneclass =form-control>
< option> iPhone< / option>
< option> Android< / option>
< option> Windows Phone< / option>
< option> Blackberry< / option>
< option>其他手机< / option>
< option>固定电话< / option>
< / select>
< / div>
< / div> <! - 智能手机问题下拉菜单结束 - >
< / div> <! - 输入的第二行结束 - >
< div class =row>
< div class =col-md-12>< input type =submitvalue =Submit>< / div>
< / div>
< / form>

如果有人有任何想法,请告诉我。我正在拉我的头发。我想我会整晚都遇到问题,比如查询数据库,或者搞乱AJAX来打磨它,但是我甚至无法通过提交RAW数据的表单!非常令人沮丧。我希望有人在那里可以看到这个问题。



为了记录,这是我的表单重定向到signup1.php后的确切消息(是的,它进入了正确的页面) 。在PHP中,我所做的就是整个$ _POST变量的Var_dump。



$ p $ var_dump($ _ POST);

它显示了我:

 array(0){} 


解决方案



例如:

 < input name =phonetype =textid =phoneclass =form-controlplaceholder =801-321-9876> 


Wow, so this is embarrassing. This is just supposed to be another boring web form. I have done plenty before, but for some reason this specific one doesn't want to cooperate. Am I somehow missing something? I have been trying to figure this out for hours. I swear I have tried troubleshooting everything, without any luck.

Basically, I am attempting to send via $_POST to a PHP file. Eventually I will use AJAX, but right now I can't even get the stupid thing to POST. So when you click submit, it goes to the correct page. But i get an error "Undefined Index (then points to the line that I call my $_POST variable). I have commented out everything on the PHP side (signup1.php) so that now all it does is var_dump($_POST); so I can see the data and it isnt getting anything from _POST, the stupid thing is empty. I really think the problem is on the HTML side. I will post my code exactly. It has a ton of extra divs for styling and layout purposes. I am going to keep all of that in there just in case that is the cause of the error, maybe one of you will know. Also, you may notice I am using bootstrap. Maybe that is something? I have used bootstrap for forms before and its worked, but who knows.

<form action="actions/signup1.php" method="post">
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="name">Name:</label>
                    <input type="text" id="name" class="form-control" placeholder="John Smith">
                </div>
            </div> <!-- end of name input column -->
            <div class="col-md-6">
                <div class="form-group">
                    <label for="phone">Phone Number:</label>
                    <input type="text" id="phone" class="form-control" placeholder="801-321-9876">
                </div> 
            </div> <!-- end of phone number input column -->
        </div> <!-- end of first .row of inputs -->

        <div class="row">
            <div class="col-md-6 column-sm-12">
                <div class="form-group">
                    <label for="email">Email Address:</label>
                    <input type="text" id="email" class="form-control" placeholder="johnsmith@me.com">
                </div>
            </div> <!-- end of email address input column -->

            <div class="col-md-3 col-sm-6">
                <div class="form-group">
                    <label for="city">City:</label>
                    <select id="city" class="form-control">
                        <option>Las Vegas</option>
                        <option>Salt Lake City</option>
                        <option>I'll Choose a Default Later...</option>
                    </select>
                </div>
            </div> <!-- end of city dropdown -->

            <div class="col-md-3 col-sm-6">
                <div class="form-group">
                    <label for="type-of-phone">Type of Phone:</label>
                    <select id="type-of-phone" class="form-control">
                        <option>iPhone</option>
                        <option>Android</option>
                        <option>Windows Phone</option>
                        <option>Blackberry</option>
                        <option>Other Cellphone</option>
                        <option>Landline</option>
                    </select>
                </div>
            </div> <!-- end of Smartphone Question Dropdown -->
        </div> <!-- end of second .row of inputs -->
        <div class="row">
            <div class="col-md-12"><input type="submit" value="Submit"></div>
        </div>
    </form>

If anyone has any idea please let me know. I am pulling my hair out. I figured I would be up all night with problems having it querying the database, or messing with the AJAX to make it polished, but instead I can't even get past the form submitting the RAW data! Very frustrating. I hope someone out there can see the issue.

For the record this is my exactmessage after the form redirects to the signup1.php (yes it goes to the right page). On the PHP all i do is a Var_dump of the whole $_POST variable.

var_dump($_POST);

And it shows me this:

array(0) { } 

解决方案

You should be adding the name attribute to the form fields.

For example:

<input name="phone" type="text" id="phone" class="form-control" placeholder="801-321-9876">

这篇关于简单的表单不通过_POST发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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