Radio button implementation
-
I am trying to use register form and have two radio buttons which will define the role for the user on the site. The radio choice is required. I am able to add the radio buttons, but I am not able to validate the radio selection or save it. I have added the theme-my-login-custom.php in the plugins folder with relevant code. I read thru the documentation and follow it, but in vain. Please, help me. I am new to PHP and wordpress.
Here is the radio choice added –
<p> <label for="user_role1<?php $template->the_instance(); ?>_m">I am a </label> <label><input type="radio" name="user_role" id="joinasr1<?php $template->the_instance(); ?>" class="input" value="<?php if ( $_POST['user_role'] ) echo 'checked="checked"'; ?>" /> Role1</label> <label><input type="radio" name="user_role" id="joinasr2<?php $template->the_instance(); ?>" class="input" value="<?php if ( $_POST['user_role'] ) echo 'checked="checked"'; ?>" /> Role2</label> </p>
theme-my-login-custom.php has this –
<?phpfunction tml_registration_errors( $errors ) { if ( empty( $_POST['user_roles'] ) ) $errors->add( 'empty_user_role', '<strong>ERROR</strong>: Please select a role.' ); return $errors; } add_filter( 'registration_errors', 'tml_registration_errors' );
I am not sure how to save, this is what I have got so far –
</strong>
function tml_user_register( $user_role ) {
if ( !empty( $_POST[‘user_role’] ) )
update_user_meta( $user_role, ‘Role’, $_POST[‘user_role’] );}
add_action( ‘user_register’, ‘tml_user_register’ );`Please help me. I am trying to get it right for past two days but in vain :(. Really appreciate and thankful for any help.
- The topic ‘Radio button implementation’ is closed to new replies.