您如何创建一个受密码保护的注册表单,在提交之前根据数据库 table 检查密码?
How do you create a password protected registration form that checks the password against a database table before submit?
我有一个 php 注册表单,其中一个字段是密码字段,我希望表单在允许之前根据数据库 table 密码列表检查密码提交用户信息的表单。所以几乎用户需要密码才能注册。我一直在为此寻找解决方案,但没有遇到过。
HTML
<input type="text" name="promo" required>
PHP
<?php
$promo_codes = ['code1', 'code2'];
if(in_array($_POST['promo'], $promo_codes) {
//in array, continue
} else {
//not in array, exit gracefully
}
基本上在 html 中为促销代码创建一个表单条目以及类似上面的内容来验证促销代码。
伪代码:
<form>
<input name="username" />
<input name="email" />
<input name="promo_code" id="promo" />
<input type="submit" value="Register" />
</form>
<script>
+ use jQuery to fire off an AJAX call with the value in the #promo input of the form
+ if a match is found in the database enable the form or the button on the form so that they can register
+ delete the promo code from the database once the registration takes place
</script>
我有一个 php 注册表单,其中一个字段是密码字段,我希望表单在允许之前根据数据库 table 密码列表检查密码提交用户信息的表单。所以几乎用户需要密码才能注册。我一直在为此寻找解决方案,但没有遇到过。
HTML
<input type="text" name="promo" required>
PHP
<?php
$promo_codes = ['code1', 'code2'];
if(in_array($_POST['promo'], $promo_codes) {
//in array, continue
} else {
//not in array, exit gracefully
}
基本上在 html 中为促销代码创建一个表单条目以及类似上面的内容来验证促销代码。
伪代码:
<form>
<input name="username" />
<input name="email" />
<input name="promo_code" id="promo" />
<input type="submit" value="Register" />
</form>
<script>
+ use jQuery to fire off an AJAX call with the value in the #promo input of the form
+ if a match is found in the database enable the form or the button on the form so that they can register
+ delete the promo code from the database once the registration takes place
</script>