使用相同的php文件显示表单并接收表单数据 [英] Using same php file to show form and receive the form's data

查看:95
本文介绍了使用相同的php文件显示表单并接收表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成表单的php页面.表单的action属性是页面本身.用户提交表单后,将加载同一页面,但是这次设置了POST变量,因此该页面运行另一个脚本来处理来自表单的传入数据.我通过使用条件分叉来做到这一点:

I have a php page that generates a form. The action attribute of the form is the page itself. After the user submits the form, the same page is loaded, but this time a POST variable is set, so the page runs another script to deal with the incoming data from the form. I do this by using a conditional fork:

if(isset($_POST['var'])){
    generate form
}else{
    insert $_POST data into database
}

我想知道这是好的还是一个坏主意.

I'd like to know if this is ok or a bad idea.

推荐答案

最糟糕的部分是将action属性设置为脚本.完全省略它会向浏览器指示应将其发布到相同的URL.

The bad part is setting the action attribute to the script. Omitting it completely indicates to the browser that it should be posted to the same URL.

这篇关于使用相同的php文件显示表单并接收表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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