2013-07-25 29 views
0

設置:PHP/HTML/JS:這個HTML表單是如何處理的?

我是逆向工程這個網頁的樂趣和實踐的後端,當我沿着東西來讓我不太明白:

當點擊寄存器有一個初始輸入驗證通過/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」場「提交...」並填寫下面隱藏的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頁面,並用錯誤消息再次更新「註冊」輸入字段。

問題:

我在這裏錯過了什麼?有沒有在PHP或服務器設置的方式來轉移表單操作,「在這種情況下,thankyou_reg.html」,並將其重定向到一個PHP頁面?然後加載成功的「thankyou_reg.html」或失敗時加載到「index.html」,用JavaScript來執行「regstatus」的值更改?

回答

0

在.htaccess文件中,可以更改設置以在擴展名爲.html的文件中運行PHP代碼。您正在使用的網站可能已將其更改爲運行PHP。

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

+0

啊哈,那一定是吧。我要檢查一下。謝謝! – CAFontana

+0

對於其他人使用WAMP像我你這樣做的打算WAMP \ BIN \ apache的\ apache2.4.2 \的conf \ httpd.conf文件並添加行 '將AddType應用/ X的httpd - PHP .html' 附近另一個AddType應用程序/ x-httpd-php條目 – CAFontana

0

有與Apache和其他服務器的方式來指定哪些應用程序應該被加載特定文件擴展名。例如,.php擴展表示PHP應該被加載並且應該處理該請求。我的想法是.html擴展實際上是由一個服務器應用程序(可能是PHP)處理的,但他們可以做到這一點,以混淆正在進行的處理。

可能存在重寫規則,將thankyou_reg.html映射到php頁面。例如,將它映射到index.php?forward=thankyou_reg.html之類的東西可能會很好,它可以爲您提供更漂亮的面向用戶的網址。

另外thankyou_reg.html可能是一個內部有index.php文件的目錄。

但實際上任何事情都可能發生在引擎蓋下。

+0

也謝謝你:D – CAFontana