首先,我用下面的代碼生成通過JavaScript形式,並將它附加一些容器(我的選擇):PHP&JavaScript |包括PHP數學驗證碼在JavaScript生成的表單
var registerStructureWrapper = '<div class="content-register"></div>';
var registerStructure = [
'<form name="',opts.regFormClass,'" class="',opts.regFormClass,'" method="post" action="#">',
'<fieldset class="',opts.regFieldsWrapper,'">',
'<fieldset class="',opts.regUserWrapper,'">',
'<label for="',opts.regUserInt,'" class="',opts.regUserLbl,'">',checkNameLenght(opts.regUserName,regNamesLenght.userNameLenght,20,'Username'),'</label>',
'<input type="text" name="',opts.regUserInt,'" class="',opts.regUserInt,'" placeholder="" value="" autocomplete="off" />',
'</fieldset>',
'<fieldset class="',opts.regEmailWrapper,'">',
'<label for="',opts.regEmailInt,'" class="',opts.regEmailLbl,'">',checkNameLenght(opts.regEmailName,regNamesLenght.emailNameLenght,20,'Email'),'</label>',
'<input type="email" name="',opts.regEmailInt,'" class="',opts.regEmailInt,'" placeholder="" value="" autocomplete="off" />',
'</fieldset>',
'<fieldset class="',opts.regPassWrapper,'">',
'<label for="',opts.regPassInt,'" class="',opts.regPassLbl,'">',checkNameLenght(opts.regPassName,regNamesLenght.passNameLenght,20,'Password'),'</label>',
'<input type="password" name="',opts.regPassInt,'" class="',opts.regPassInt,'" placeholder="" value="" autocomplete="off" />',
'</fieldset>',
'<fieldset class="',opts.regConfWrapper,'">',
'<label for="',opts.regConfInt,'" class="',opts.regConfLbl,'">',checkNameLenght(opts.regConfName,regNamesLenght.confNameLenght,20,'Confirm Password'),'</label>',
'<input type="password" name="',opts.regConfInt,'" class="',opts.regConfInt,'" placeholder="" value="" autocomplete="off" />',
'</fieldset>',
'<fieldset class="',opts.regBtnWrapper,'">',
'<div class="message-handling"></div>',
'<button type="submit" name="',opts.regBtnInt,'" class="',opts.regBtnInt,'">',checkNameLenght(opts.regBtnName,regNamesLenght.btnNameLenght,8,'Register'),'</button>',
'</fieldset>',
'</fieldset>',
'</form>',
'<div class="',opts.regBackBtn,'">',
'<ul class="inside">',
'<li class="back"><a><img src="assets/gfx/back.png" alt="Back" /></a></li>',
'</ul>',
'</div>'
];
$(registerStructureWrapper).appendTo(container).hide();
var registerWrapper = $(container).find('.content-register');
$(registerStructure.join('')).appendTo(registerWrapper);
和我有下面的代碼生成一個數學驗證碼:
<?php
public function mathCaptcha()
{
$sum1 = mt_rand(1,9);
$sum2 = mt_rand(1,9);
$sum3 = $sum1 + $sum2;
$_SESSION['answer'] = $sum3;
return $sum1 . ' + ' . $sum2 . ' = ';
}
?>
我的問題是我能以某種方式包括總和爲JS生成的表單?有沒有一種方法可以做到這一點,而沒有在純HTML中的形式,但生成它,因爲我已經這樣做?
提示:該腳本不在頁面上,它是一個帶有<script>
標籤的加載腳本。
只是clerafication ..你知道,php是在服務器端執行和HTML和Javascript在clint端執行? – reporter 2012-01-13 11:39:13
是的,這就是爲什麼我問,因爲有一個js captcha將是無用的,我想有一個php並將其包含在窗體中,並且處理我將使用'$ _POST'和Ajax執行此操作 – Roland 2012-01-13 11:41:07
在此處如果您應該使用AJAX,建議兩次。您必須使用JS創建Ajax源代碼,並且在您的php文件中,您必須創建方法調用並簡單寫入響應。 – reporter 2012-01-13 11:50:02