admin管理员组文章数量:1395367
I am writing a code to match form input data with user table in wp, but its not working proper, either condition is true or false, its giving same message. please help me to resolve it.
function email_form_code() {
echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
echo '<p>';
echo '<p>';
echo 'Your Email (required) <br />';
echo '<input type="email" name="email" value="' . ( isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p><input type="submit" name="submit" value="Send"/></p>';
echo '</form>';
}
function checkpoint_email() {
global $wpdb;
if(isset($_POST['submit'])){
$email = sanitize_email($_POST['email']);
if(!is_email($email)) {
echo '<div class="error"><p>Invalid e-mail!</p></div>';
}
$datum = $wpdb->get_results("SELECT COUNT(*) FROM wp8p_users WHERE $current_user->user_email = $email");
if($datum < 0) {
echo "Email Verified";
}
else {
echo "Email Not Verified";
}
}
}
function ec_shortcode() {
ob_start();
checkpoint_email();
email_form_code();
return ob_get_clean();
}
add_shortcode( 'av_email_cform', 'ec_shortcode' );
?>
I am writing a code to match form input data with user table in wp, but its not working proper, either condition is true or false, its giving same message. please help me to resolve it.
function email_form_code() {
echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
echo '<p>';
echo '<p>';
echo 'Your Email (required) <br />';
echo '<input type="email" name="email" value="' . ( isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p><input type="submit" name="submit" value="Send"/></p>';
echo '</form>';
}
function checkpoint_email() {
global $wpdb;
if(isset($_POST['submit'])){
$email = sanitize_email($_POST['email']);
if(!is_email($email)) {
echo '<div class="error"><p>Invalid e-mail!</p></div>';
}
$datum = $wpdb->get_results("SELECT COUNT(*) FROM wp8p_users WHERE $current_user->user_email = $email");
if($datum < 0) {
echo "Email Verified";
}
else {
echo "Email Not Verified";
}
}
}
function ec_shortcode() {
ob_start();
checkpoint_email();
email_form_code();
return ob_get_clean();
}
add_shortcode( 'av_email_cform', 'ec_shortcode' );
?>
Share
Improve this question
edited Mar 19, 2020 at 10:21
Amar Verma
asked Mar 18, 2020 at 12:14
Amar VermaAmar Verma
134 bronze badges
9
|
Show 4 more comments
1 Answer
Reset to default 0Your conditional check is the wrong way around, it should be >
not <
.
But more importantly, why are you doing a raw SQL query at all, just use the standard functions, e.g. get_user_by
:
$user = get_user_by( 'email', $email );
if ( !$user ) {
// there is no user with that email
}
Also, submit
is an incredibly generic name for a form input to check, use something more specific, like av_email_cform_submit
.
You can also replace your action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '"
with action=""
. You also have a double <p><p>
in your form.
本文标签: pluginsCustom Formdata matching with user table
版权声明:本文标题:plugins - Custom Formdata matching with user table 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744657421a2618049.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$_POST
data coming from? Have you checked the values of$_POST['email']
and the current user email to confirm they have the expected values? Is the user logged in? – Tom J Nowell ♦ Commented Mar 18, 2020 at 16:44