PHP 表单与进程在同一页面上?
我在我的页面上创建了一个表单,从教程中我看到它说我必须有第二个页面,其中包含所有 php 处理,是否无法将 php 保留在同一页面上,并且当用户点击提交时表格已发送?
为什么这在我的流程页面上不起作用?它没有回显任何内容:S
<?php
$kop = mysql_real_escape_string($_POST['severity']);
$loc = mysql_real_escape_string($_POST['location']};
$summary = mysql_real_escape_string($_POST['summary']);
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
echo $kop;
echo $loc;
echo $summary;
echo $name;
echo $email;
?>
I've created a form on my page and from the tutorials im following it says I have to have a second page with all the php processing in, is it not possible to keep the php on the same page and when the user hits submit the form is sent?
Why isnt this working on my process page? It doesnt echo anything :S
<?php
$kop = mysql_real_escape_string($_POST['severity']);
$loc = mysql_real_escape_string($_POST['location']};
$summary = mysql_real_escape_string($_POST['summary']);
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
echo $kop;
echo $loc;
echo $summary;
echo $name;
echo $email;
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果按下提交按钮,您可以签入同一文件。 (http://pastebin.com/8FC1fFaf)
关于表单检查,可以保存用户输入,如果有他们的数据无效,您可以回显旧数据并再次显示表单。
编辑:正如 PeeHaa 所说,你需要将操作留空;)
You can check in the same file if the submit button is pressed. (http://pastebin.com/8FC1fFaf)
Regarding form checking, you can save the user input, and if one of their data is unvalid you can echo the old data back and show the form again.
edit: As PeeHaa stated, you need to leave the action blank though ;)
是的,这是可能的。正如 Pekka 所建议的,实际上并不建议这样做。但这是如何做到的。
只需使用 isset 方法来检查表单是否已发布。因此,假设您的表单中有以下输入:
在 php 脚本的顶部,您可以使用以下内容来了解表单是否已提交,从而对其进行处理。
希望这有帮助;)
Yes it is possible. As adviced by Pekka, it's not really suggested to do so. But here is how it can be done.
Simply using the isset method to check if the form has been posted. So say in your form you have the follwing input:
At the top of your php script you can use the following to know if the form has been submitted and thus process it.
Hope this helps ;)
可以让同一个脚本处理表单。
如果您想执行此操作,只需将操作留空即可。
但是,如果您想在不重新加载页面的情况下处理表单,则必须使用 Javascript。
It is possible to let the same script process the form.
If you want to do this just leave the action blank.
However If you want to process the form without the page being reloaded you have to use Javascript.
听起来您正在描述 AJAX。示例: http: //www.elated.com/res/File/articles/development/javascript/jquery/slick-ajax-contact-form-jquery-php/
这是使用 jQuery 框架 - 有许多框架用于这样做(例如YUI)也可以同样做到这一点。你可以自己写这个来了解它是如何工作的,但 IHMO 这将是重新发明轮子。这是一个关于使用 jQuery 创建 AJAX 表单的不错的教程:
http: //www.elated.com/articles/slick-ajax-contact-form-jquery-php/
It sounds like you are describing AJAX. Example: http://www.elated.com/res/File/articles/development/javascript/jquery/slick-ajax-contact-form-jquery-php/
This is using the jQuery framework - there are a number of frameworks for doing this (such as YUI) which could do this equally as well. You could write this yourself to learn how it all works, but IHMO this would be reinventing the wheel. Here is a decent tutorial on creating AJAX forms with jQuery:
http://www.elated.com/articles/slick-ajax-contact-form-jquery-php/