I have been working on a project where I will have to call a method(that accepts user id as an input) from a click of a submit button(Accept button).
I have been trying all the ways but the real challenge I am facing is how to get the user id in the front end and pass it to the method.
My method updates the user meta of that particular user.
Html code:
<div id="modal">
<div class="modalconent">
<h3 align=center>GDPR</h3>
<p>This is a GDPR Pop Up</p><br><br><br>
<form>
<input name="accept" type="checkbox" value="Gdpr" required/>I accept the GDPR
<input type="submit" id="accept-button" value="Accept">
</form>
</div>
</div>
<script>
window.onload = function () {
document.getElementById('accept-button').onclick = function () {
document.getElementById('modal').style.display = "none"
};
};
</script>
At present, my Accept button when clicked is only displaying none. I want to call the method along with display:none;
My PHP code:
function updateHasReadFlag($user) {
// I added support for using this function either with user ID or user object
if ( $user && is_int( $user ) ) {
$user_id = $user;
} else if ( ! empty( $user->ID ) ) {
$user_id = $user->ID;
} else {
return;
}
return update_user_meta( $user_id, 'META_KEY', true );
}
The form code generated :
<form method="post" action="<?php echo esc_url( home_url() ); ?>">
<input name="accept" type="checkbox" value="Gdpr" required=""> I accept the GDPR
<input type="submit" id="accept-button" value="Accept">
<!--?php wp_nonce_field( 'accept-gdpr', 'accept_gdpr_nonce' ); ?-->
</form>
I do not understand why nonce field is commented. This is exactly what the code got generated, I have not edited anything in the code.