I have asked this question but posted it incorrectly.
The following code redirects people to a custom page:
function possibly_redirect(){
global $pagenow;
if( 'wp-login.php' == $pagenow ) {
wp_redirect('https://www.mydomain.co.za/custom-page/');
exit();
}
}
I have added a custom login plugin but don't want it to pop up on registration negating the custom page. Is there a way to make the initial redirect happen first and prevent the registration form from loading?
<form method="post" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" class="wp-user-form">
<?php _e('Username'); ?>:
<input type="text" name="user_login" value="<?php echo esc_attr(stripslashes($user_login)); ?>" size="20" id="user_login" tabindex="101" />
<?php _e('Your Email'); ?>:
<input type="text" name="user_email" value="<?php echo esc_attr(stripslashes($user_email)); ?>" size="25" id="user_email" tabindex="102" />
<?php _e('Your pwd'); ?>:
<input type="text" name="user_pass" value="<?php echo esc_attr(stripslashes($user_pass)); ?>" size="25" id="user_pass" tabindex="103" />
<?php do_action('register_form'); ?>
<input type="submit" name="user-submit" value="<?php _e('Sign up!'); ?>" class="user-submit" tabindex="104" />
<?php $register = $_GET['register']; if($register == true) { echo '<p>Check your email for the password!</p>'; } ?>
<input type="hidden" name="redirect_to" value="<?php bloginfo('url') ?>?register=true" />
<input type="hidden" name="user-cookie" value="1" />
</form>
Related
I made a group of fields of type Checkbox to be able to select several options using ACF | Advanced Custom Fields, these fields are added to the profile of the user in the WP dashboard, I want to edit them from the front end using a custom form.
Fields created:
Fields in user profile:
Form in front page
I need when you select any option / checkbox on the page of the frontpage that is saved and also updated in the user's profile.
The code that I have in the from template is this:
account_page.php
<form id="your-profile" class="nice" action="<?php echo the_permalink() ?>" method="POST" />
<div>
<p>Please check the email newsletters you wish to receive.<br>Unchecking a box will unsubscribe you from future emails.</p>
</div>
<fieldset>
<input name="_wp_http_referer" value="<?php echo home_url('account') ?>" type="hidden">
<input name="from" value="profile" type="hidden">
<input name="action" value="update" type="hidden">
<input name="user_id" id="user_id" value="<?php echo $current_user->ID ?>" type="hidden">
<input name="checkuser_id" value="<?php echo get_current_user_id(); ?>" type="hidden">
<input name="nickname" value="<?php echo $current_user->user_email ?>" type="hidden">
<input name="user_email" value="<?php echo $current_user->user_email ?>" type="hidden">
<input name="phone" value="<?php echo $current_user->phone; ?>" type="hidden">
<input name="first_name" value="<?php echo $current_user->first_name ?>" type="hidden">
<input name="last_name" value="<?php echo $current_user->last_name ?>" type="hidden">
<input name="address" value="<?php echo $current_user->address ?>" type="hidden">
<input name="address2" value="<?php echo $current_user->address2 ?>" type="hidden">
<input name="city" value="<?php echo $current_user->city; ?>" type="hidden">
<input name="state" value="<?php echo $current_user->state; ?>" type="hidden">
<input name="zip_code" value="<?php echo $current_user->zip_code; ?>" type="hidden">
<input name="country" value="<?php echo $current_user->country; ?>" type="hidden">
<?php
//Get all items from newslwtter
$newsletter = get_field('newsletter_preferences', $current_user);
$id = get_the_ID();
$field = get_field_objects($current_user);
$field_name = $field["newsletter_preferences"]["name"];
if( $field ){
foreach ( $field["newsletter_preferences"]['choices'] as $key => $value) {
if ( in_array( $key, $newsletter ) ) {
$checked = 'checked';
}else{
$checked = '';
}
echo '<p class="field"><input type="checkbox" '.$checked.' name="'.$field_name.'" value="'.$key.'">'.$value.'</p>';
}
}
?>
</fieldset>
<div>
<input class="btn btn-primary" name="Update E-mail Preferences" value="Update E-mail Preferences" type="submit">
<?php wp_nonce_field( 'update-user' ) ?>
<input name="action" type="hidden" id="action" value="update-user">
</div>
</form>
And in the functions.php
function update_extra_profile_fields($user_id) {
if ( isset( $_POST['newsletter_preferences'] ) )
update_user_meta( $user_id, 'newsletter_preferences',
$_POST['newsletter_preferences'] );
}
add_action('personal_options_update','update_extra_profile_fields');
But don't work, dont save anything, help me please. Thank you
Solved creating :
function update_extra_profile_fields($user_id) {
if ( isset( $_POST['state'] ) )
$state = update_user_meta( $user_id, 'state', $_POST['state'] );
.
.
.
//all fields to save
}
add_action('personal_options_update', __NAMESPACE__ . '\\update_extra_profile_fields');
In my custom Wordpress theme, I have custom login form:
<form method="post" action="<?php bloginfo('url') ?>/wp-login.php" name="login">
<div class="login-form-container resp-hidden">
<div class="login-form-container-inner">
<h3 class="form-title"><?php echo __('Login', 'louise'); ?></h3>
<label for="user_login">
<?php echo __('User name or e-mail', 'louise'); ?>: </label>
<input class="para-content" type="text" name="log" placeholder="" value="<?php echo esc_attr(stripslashes($user_login, $user_email)); ?>" size="20" id="user_login" tabindex="11" required>
<label for="user_pass">
<?php echo __('Password', 'louise'); ?>: </label>
<input class="para-content" type="password" name="pwd" value="" size="20" id="user_pass" tabindex="12" required/>
<label for="rememberme"> </label>
<div class="buttons">
<?php do_action('login_form'); ?>
<input type="submit" name="user-submit" value="<?php echo __('Log in', 'louise'); ?>" tabindex="14" class="signupbtn" />
<input type="hidden" name="redirect_to" value="<?php echo icl_get_home_url() ; ?>" />
<input type="hidden" name="user-cookie" value="1" />
</div>
</div>
</div>
</form>
It gets the job done, but problem appears when I am trying to log in from different than default language. Login redirects to the front-page leaving with inactive URL: http://test.com/?lang=en/wp-login.php I am using WPML plugin for two languages, default one is lt_LT and en_US as additional.
I was digging threw all the weekend, but found no valid solution. To make it clear, I don't get if I have to translate core WP wp-login.php page, o is there a shortcut to bypass wp-login.php and redirect user straight to home page?
Many thanks for all possible help and suggestions.
Looking forward,
First change the form action to
<?php echo $_SERVER['REQUEST_URI']; ?>
and use this PHP after the form
if (isset($_POST['user-submit'])) {
login_auth($_POST['log'], $_POST['pwd']);
}
and add this function to functions.php
function login_auth( $username, $password ) {
global $user;
$current_cookie = esc_attr( $_COOKIE['_icl_current_language'] );
$url = '/'.$current_cookie;
$login_page = site_url($url);
$creds = array();
$creds['user_login'] = $username;
$creds['user_password'] = $password;
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) ) {
echo $user->get_error_message();
}
if ( !is_wp_error($user) ) {
wp_redirect($login_page);
}
}
After all, here is my solution that worked in my case. Seems, that the problem was language parameter set by WPML plugin. It is possible to check if current link has ?lang=en/ and change it with default wp-login url.
<?php
if($login = strstr($_SERVER['REQUEST_URI'], "?lang=en")) {
$login = wp_login_url();
} else {
$login = wp_login_url();
}?>
<form method="post" action="<?php echo $login?>"
<div class="login-form-container resp-hidden">
<div class="login-form-container-inner">
<h3 class="form-title"><?php echo __('Login', 'louise'); ?></h3>
<label for="user_login">
<?php echo __('User name or e-mail', 'louise'); ?>: </label>
<input class="para-content" type="text" name="log" placeholder="" value="<?php echo esc_attr(stripslashes($user_login || $user_email)); ?>" size="20" id="user_login" tabindex="11" required>
<label for="user_pass">
<?php echo __('Password', 'louise'); ?>: </label>
<input class="para-content" type="password" name="pwd" value="" size="20" id="user_pass" tabindex="12" required/>
<label for="rememberme"> </label>
<div class="buttons">
<?php do_action('login_form'); ?>
<input type="submit" name="user-submit" value="<?php echo __('Log in', 'louise'); ?>" tabindex="14" class="signupbtn" />
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
<input type="hidden" name="user-cookie" value="1" />
</div>
</div>
</div>
</form>
If the above title looks confusing then here is the description....
I have a template page where I have placed the wordpress default registration form. Now what exactly I want is to add few extra fields on that form.
The wordpress registration will go on as it is. I mean the username and email and password gets stored on the database but along with that new fields or extra details like phone/address/age etc etc gets emailed to a specific email id.
<form method="post" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" class="wp-user-form">
<div class="username">
<label for="user_login"><?php _e('Username'); ?>: </label>
<input type="text" name="user_login" value="<?php echo esc_attr(stripslashes($user_login)); ?>" size="20" id="user_login" tabindex="101" />
</div>
<div class="password">
<label for="user_email"><?php _e('Your Email'); ?>: </label>
<input type="text" name="user_email" value="<?php echo esc_attr(stripslashes($user_email)); ?>" size="25" id="user_email" tabindex="102" />
</div>
<div class="login_fields">
<?php do_action('register_form'); ?>
<input type="submit" name="user-submit" value="<?php _e('Sign up!'); ?>" class="user-submit" tabindex="103" />
<?php $register = $_GET['register']; if($register == true) { echo '<p>Check your email for the password!</p>'; } ?>
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>?register=true" />
<input type="hidden" name="user-cookie" value="1" />
</div>
</form>
**Note:- The new fields aren't added here.
Is it possible? If yes, then how? Should I add a second form below this form which fires the email? Kindly please suggest an appropriate solution for this.
I want add changing on category page, I customize page websitelink.com/components\com_virtuemart\themes\default\templates\browse\browse_3.php
I add code
<div class="addtocart_buttonList">
<?php
$button_lbl = $VM_LANG->_('PHPSHOP_CART_ADD_TO');
$button_cls = 'addtocart_button';
if( CHECK_STOCK == '1' && ( $product_in_stock < 1 ) ) {
$button_lbl = $VM_LANG->_('VM_CART_NOTIFY');
$button_cls = 'notify_button';
$notify = true;
} else {
$notify = false;
}
?>
<form action="<?php echo $mm_action_url ?>index.php" method="post" name="addtocart" id="addtocart<?php echo $i ?>" class="addtocart_form" <?php if( $this->get_cfg( 'useAjaxCartActions', 1 ) && !$notify ) { echo 'onsubmit="handleAddToCart( this.id );return false;"'; } ?>>
<input type="submit" class="<?php echo $button_cls ?>" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
<input type="hidden" name="category_id" value="<?php echo #$_REQUEST['category_id'] ?>" />
<input type="hidden" name="product_id" value="<?php echo $product_id ?>" />
<input type="hidden" name="prod_id[]" value="<?php echo $product_id ?>" />
<input type="hidden" name="page" value="shop.cart" />
<input type="hidden" name="func" value="cartadd" />
<input type="hidden" name="Itemid" value="<?php echo $sess->getShopItemid() ?>" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="set_price[]" value="" />
<input type="hidden" name="adjust_price[]" value="" />
<input type="hidden" name="master_product[]" value="" />
</form>
</div>
After adding this line add to cart button appear on list items, but than i click on add to cart button error will come
Please enter a valid quatity for this item
How i can solve this?
You need to specify a quantity as an input field, hidden or otherwise. We only wanted the customer to be able to order one of an item, so added this code:
<input type="hidden" value="1" name="quantity">
Having that named input field satisifed the Virtuemart validation.
I'm using the Mingle plugin for Wordpress for users to register, so they can post on a Mingle Forum.
The signup process works, but I want to redirect the user to the forum page once they have submitted their details, rather than just staying on the signup page.
I've tried adding <input type="hidden" name="redirect_to" value="<?php echo bloginfo('url'); ?>" /> to the code so that the page redirects (as it worked on the login form), but doesn't seem to work with signup form.
I've tried using the "action" function in the form details too; this redirects the page, but doesn't submit the data.
The page's code is below - would really appreciate a solution, if possible! Thanks.
<form name="registerform" id="registerform" method="post">
<input type="hidden" id="mngl-process-form" name="mngl-process-form" value="Y" />
<input type="hidden" name="redirect_to" value="http://creativespotlights.com/forum" action="http://creativespotlights.com/forum" />
<p>
<label><?php _e('Username', 'mingle'); ?>*:<br />
<input type="text" name="user_login" id="user_login" class="input mngl_signup_input" value="<?php echo $user_login; ?>" size="20" tabindex="200" /></label>
</p>
<p>
<label><?php _e('E-mail', 'mingle'); ?>*:<br />
<input type="text" name="user_email" id="user_email" class="input mngl_signup_input" value="<?php echo $user_email; ?>" size="25" tabindex="300" /></label>
</p>
<?php if(isset($mngl_options->field_visibilities['signup_page']['name'])) { ?>
<p>
<label><?php _e('First Name', 'mingle'); ?>:<br />
<input type="text" name="user_first_name" id="user_first_name" class="input mngl_signup_input" value="<?php echo $user_first_name; ?>" size="20" tabindex="400" /></label>
</p>
<p>
<label><?php _e('Last Name', 'mingle'); ?>:<br />
<input type="text" name="user_last_name" id="user_last_name" class="input mngl_signup_input" value="<?php echo $user_last_name; ?>" size="20" tabindex="500" /></label>
</p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['signup_page']['url'])) { ?>
<p>
<label><?php _e('Website', 'mingle'); ?>:<br />
<input type="text" name="mngl_user_url" id="mngl_user_url" value="<?php echo $mngl_user_url; ?>" class="input mngl_signup_input" size="20" tabindex="600"/></label>
</p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['signup_page']['location'])) { ?>
<p>
<label><?php _e('Location', 'mingle'); ?>:<br />
<input type="text" name="mngl_user_location" id="mngl_user_location" value="<?php echo $mngl_user_location; ?>" class="input mngl_signup_input" size="20" tabindex="700" /></label>
</p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['signup_page']['bio'])) { ?>
<p>
<label><?php _e('Bio', 'mingle'); ?>:<br />
<textarea name="mngl_user_bio" id="mngl_user_bio" class="input mngl-growable mngl_signup_input" tabindex="800"><?php echo wptexturize($mngl_user_bio); ?></textarea></label>
</p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['signup_page']['sex'])) { ?>
<p>
<label><?php _e('Gender', 'mingle'); ?>*: <?php echo MnglProfileHelper::sex_dropdown('mngl_user_sex', $mngl_user_sex, '', 900); ?></label>
</p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['signup_page']['password'])) { ?>
<p>
<label><?php _e('Password', 'mingle'); ?>:<br/>
<input type="password" name="mngl_user_password" id="mngl_user_password" class="input mngl_signup_input" tabindex="1000"/></label>
</p>
<p>
<label><?php _e('Password Confirmation', 'mingle'); ?>:<br />
<input type="password" name="mngl_user_password_confirm" id="mngl_user_password_confirm" class="input mngl_signup_input" tabindex="1100"/></label>
</p>
<?php } else { ?>
<p id="reg_passmail"><?php _e('A password will be e-mailed to you.', 'mingle'); ?></p>
<?php } ?>
<?php if($mngl_options->signup_captcha) { ?>
<?php
$captcha_code = MnglUtils::str_encrypt(MnglUtils::generate_random_code(6));
?>
<p>
<label><?php _e('Enter Captcha Text', 'mingle'); ?>*:<br />
<img src="<?php echo MNGL_SCRIPT_URL; ?>&controller=captcha&action=display&width=120&height=40&code=<?php echo $captcha_code; ?>" /><br/>
<input id="security_code" name="security_code" style="width:120px" type="text" tabindex="1200" />
<input type="hidden" name="security_check" value="<?php echo $captcha_code; ?>">
</p>
<?php } ?>
<?php do_action('mngl-user-signup-fields'); ?>
<br class="clear" />
<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="mngl-share-button" value="<?php _e('Sign Up', 'mingle'); ?>" tabindex="60" />
</p>
</form>
Try this
<?php
if (isset($_POST['wp-submit']))
{
header('Location: http://site/result.php');
}
?>
in the top of your code
OR you can try to do it by javascript with onsubmit="window.location.href='result.php';"
You can use :
header('Location: http://yoursite.com/location.php');
But you have to get a clean output (no html before the header).
Doc here.
Something like this should work:
if (isset($_POST['user_login']))
{
(your redirect code here)
}
After a form has been successfully submitted you should perform a 303 redirect to the same page. Doing this will prevent resubmitting the form if the user happens to press F5 or some other form or reloading the page.
wp_redirect("/path/to/my/script", 303);
You will need to substitute /path/to/my/script with the URL where your form lives.