I have added a field to my login form with the login_form action hook as below
add_action('login_form','select_contest_field');
function select_contest_field(){
//Output your HTML
?>
<p class="tml-user-pass-wrap">
<label for="contest">Select Contest</label>
<select class="form-control input-lg" id="contest" name="contest" required>
<option value="uppa" >UPPA 2017</option>
<option value="ypa">Young Photographer Award</option>
</select>
</p>
<?php
}
I have a login_redirect filter to redirect users on login depending on certain conditions and which option they choose.
function my_login_redirect( $redirect_to, $request, $user ) {
//set variables
global $wpdb;
$contests_table = $wpdb->prefix.'photocontests';
$user_meta_table = $wpdb->prefix.'usermeta';
$site_url = get_site_url();
$my_info_url = $site_url.'/my-information/';
if (isset($_POST['contest']) && $_POST['contest'] = "ypa"){
$contest_page = $site_url.'/young-photographers-award-2017/young-photographers-award-2017-upload-submit/';
}
if (isset($_POST['contest']) && $_POST['contest'] = "uppa") {
$contest_page = $site_url.'/uganda-press-photo-award-2017/uganda-press-photo-award-2017-upload-submit/';
}
global $current_user;
get_currentuserinfo();
$userID = $user->ID;
$user_info_updated = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM $user_meta_table WHERE user_id = %d AND meta_key = 'userinfo_updated' ", $userID) );
//check if user has updated information
//is there a user to check?
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'administrator', $user->roles ) ) {
// redirect them to the default place
return $redirect_to;
} else {
if ($user_info_updated != 1){
return $my_info_url;
} else {
return $contest_page;
}
}
} else {
return $my_info_url;
}
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
When a user logins in and selects an option on the login form, they are always redirected to the $contest_page second option no matter what option is selected, in this case,
if (isset($_POST['contest']) && $_POST['contest'] = "uppa") {
$contest_page = $site_url.'/uganda-press-photo-award-2017/uganda-press-photo-award-2017-upload-submit/';
}
How can I make sure the right value for $contest_page is selected? Is the login form passing the selected option to the function properly? Basically, someone help me!