PHP/HTML/JS:这个HTML表单是如何处理的?
设置: 为了好玩和练习,我对本页的后端进行了反向工程,这时我发现了一些我不太理解的东西: 单击register时,/js/login.js中的AttemptRegister()会进行初始输入验证,检查所有字段是否为空,是否包含默认值,并确保密码匹配PHP/HTML/JS:这个HTML表单是如何处理的?,php,javascript,forms,Php,Javascript,Forms,设置: 为了好玩和练习,我对本页的后端进行了反向工程,这时我发现了一些我不太理解的东西: 单击register时,/js/login.js中的AttemptRegister()会进行初始输入验证,检查所有字段是否为空,是否包含默认值,并确保密码匹配 function AttemptRegister() { // Simple validation of input fields first var status=document.getElementById("regstatus"); s
function AttemptRegister() {
// Simple validation of input fields first
var status=document.getElementById("regstatus");
status.style.color='#000000';
status.value = "";
var username = document.getElementById("username");
var email = document.getElementById("email");
var password = document.getElementById("password");
var confirmPassword = document.getElementById("confirmPassword");
if(""==username.value || "user name"==username.value) {
status.style.color='#C00000';
status.value = "Invalid user name";
username.selected = true;
return;
}
if(""==email.value || "email" == email.value) {
status.style.color='#C00000';
status.value = "Invalid email address";
email.selected = true;
return;
}
if(""==password.value || "password" == password.value) {
status.style.color='#C00000';
status.value = "Must provide password";
password.selected = true;
return;
}
if(password.value!=confirmPassword.value ) {
status.style.color='#C00000';
status.value = "Passwords do not match";
password.selected = true;
return;
}
// We open the thankyou page for registering, as that's where the actual registration occurs on the POST variables. If they fail, we'll get kicked back here
status.value = "Submitting...";
//window.location.href='thankyou_reg.html';
// Submit with hidden form
var form = document.getElementById("submitEmail").form;
document.getElementById("submitEmail").value = email.value;
document.getElementById("submitUsername").value = username.value;
document.getElementById("submitPassword").value = password.value;
form.submit();
}
它将html中的“regstatus”字段设置为“Submitting…”,并填写下面隐藏的html表单,然后将其提交到thankyou_reg.html?
<form action="thankyou_reg.html" method="post">
<input type="hidden" name="submitEmail" id="submitEmail" value=""/>
<input type="hidden" name="submitUsername" id="submitUsername" value=""/>
<input type="hidden" name="submitPassword" id="submitPassword" value=""/>
<input type="hidden" name="registerSubmit" id="registerSubmit" value="true"/>
</form>
这就是我困惑的地方,一个扁平的.html页面如何处理表单数据?它进行二次验证检查,以确保用户名和密码足够长,电子邮件格式正确,并查询数据库以确保此电子邮件或用户名尚未使用。如果其中任何一个操作失败,它将返回index.html页面,并用错误消息再次更新“regstatus”输入字段
问题:
我错过了什么?在PHP或服务器设置中是否有方法转移表单操作,在本例中为“Thankyu_reg.html”,并将其重定向到PHP页面?然后在成功时加载“Thankyu_reg.html”,或在失败时加载回“index.html”,使用javascript将在.htaccess文件中执行“regstatus”的值更改?,可以更改设置以在扩展名为.html的文件中运行PHP代码。您使用的网站可能将其更改为运行PHP
Apache和其他服务器可以通过多种方式指定应为特定文件扩展名加载哪些应用程序。例如,
.php
扩展表示应该加载php并处理请求。我的想法是,.html
扩展实际上是由一个服务器应用程序(可能是PHP)处理的,但是他们可以这样做来混淆在后台处理的内容
可能存在将thankyou\u reg.html
映射到php页面的重写规则。例如,将它映射到像index.php?forward=thankyou\u reg.html
这样的东西可能会很好,这样可以提供更漂亮的面向用户的url
另外,thankyou_reg.html
可以是一个目录,其中包含index.php
文件
但实际上任何事情都可能发生在引擎盖下。啊哈,一定是这样。我去看看。非常感谢。对于像我这样使用WAMP的其他人,您可以通过转到WAMP\bin\apache\apache2.4.2\conf\httpd.conf并在其他AddType应用程序/x-httpd-php条目附近添加行
AddType application/x-httpd-php.html