style: 优化表单样式并提升表单性能
This commit is contained in:
@@ -57,6 +57,36 @@ function itstudio_join_otp_random_code() {
|
||||
return (string) wp_rand(100000, 999999);
|
||||
}
|
||||
|
||||
function itstudio_join_otp_email_exists_in_form($form_id, $field_id, $email) {
|
||||
global $wpdb;
|
||||
|
||||
$form_id = absint($form_id);
|
||||
$field_id = absint($field_id);
|
||||
$email = itstudio_join_otp_normalize_email($email);
|
||||
if ($form_id <= 0 || $field_id <= 0 || $email === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$items_table = $wpdb->prefix . 'frm_items';
|
||||
$metas_table = $wpdb->prefix . 'frm_item_metas';
|
||||
$count = $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
"SELECT COUNT(1)
|
||||
FROM {$metas_table} AS meta
|
||||
INNER JOIN {$items_table} AS item ON item.id = meta.item_id
|
||||
WHERE item.form_id = %d
|
||||
AND item.is_draft = 0
|
||||
AND meta.field_id = %d
|
||||
AND LOWER(TRIM(meta.meta_value)) = %s",
|
||||
$form_id,
|
||||
$field_id,
|
||||
$email
|
||||
)
|
||||
);
|
||||
|
||||
return (int) $count > 0;
|
||||
}
|
||||
|
||||
function itstudio_join_otp_json_error($message_cn, $message_en, $status = 400, $extra = array()) {
|
||||
wp_send_json_error(
|
||||
array_merge(
|
||||
@@ -85,6 +115,10 @@ function itstudio_join_otp_send_ajax() {
|
||||
itstudio_join_otp_json_error('请输入有效的邮箱地址。', 'Please enter a valid email address.', 400);
|
||||
}
|
||||
|
||||
if (itstudio_join_otp_email_exists_in_form($config['form_id'], $config['email_field_id'], $email)) {
|
||||
itstudio_join_otp_json_error('该邮箱已经报名,无需重复提交。', 'This email has already been used to apply.', 409);
|
||||
}
|
||||
|
||||
$ip = itstudio_join_otp_get_client_ip();
|
||||
$otp_key = itstudio_join_otp_key($email, $config['form_id']);
|
||||
$existing = get_transient($otp_key);
|
||||
|
||||
Reference in New Issue
Block a user