PHP/HTML/JS:这个HTML表单是如何处理的


PHP/HTML/JS: How is this HTML form processed?

设置:

为了好玩和练习,我正在对这个页面的后端进行逆向工程,这时我发现了一些我不太理解的东西:

当单击register时,/js/login.js中的AttemptRegister()会进行初始输入验证,检查字段是否为空,是否包含默认值,并确保密码匹配。

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"字段设置为"Submiting…",并填写下面隐藏的html表单并提交以感谢_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>

这就是我困惑的地方,一个flat.html页面如何处理表单数据?它会进行二次验证检查,以确保用户名和密码足够长,电子邮件的格式正确,并查询数据库,以确保此电子邮件或用户名尚未使用。如果其中任何一个失败,它将返回到index.html页面,并再次更新"regstatus"输入字段并显示错误消息。

问题:

我在这里错过了什么?在PHP或服务器设置中,是否有一种方法可以转移表单操作,在本例中为"thankyou_reg.html",并将其重定向到PHP页面?然后在成功时加载"thankyou_reg.html",或者在失败时加载回"index.html",用javascript执行"regstatus"的值更改?

在.htaccess文件中,可以更改设置以在扩展名为.html的文件中运行PHP代码。您使用的网站可能将其更改为运行PHP。

http://php.about.com/od/advancedphp/p/html_php.htm

Apache和其他服务器有一些方法可以指定应该为特定的文件扩展名加载什么应用程序。例如,.php扩展表示应该加载PHP并处理请求。我的想法是,.html扩展实际上是由服务器应用程序(可能是PHP)处理的,但他们这样做可能会混淆幕后处理的内容。

可能存在将thankyou_reg.html映射到php页面的重写规则。例如,将它映射到类似index.php?forward=thankyou_reg.html的东西可能会很好,这样可以为您提供更漂亮的面向用户的url。

thankyou_reg.html也可以是一个目录,里面有一个index.php文件。

但事实上,任何事情都可能在幕后发生。