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.
Related
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 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>
<?php
include 'includes/connectie.php';
$product_id=$_GET['id'];
$sql = "SELECT * FROM `producten` WHERE product_id='$product_id'";
$sql_result = $dbh->query($sql);
foreach($sql_result as $row)
{
$prijs=$row['prijs'];
$product_naam=$row['product_naam'];
$product_categorie=$row['product_categorie'];
$product_specificaties=$row['product_specificaties'];
$foto=$row['foto'];
$product_id=$row['product_id'];
$product_soort=$row['product_soort'];
echo "Product id nummer:", $product_id;
}
//$_SESSION['prijs'] = $prijs;
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if (!empty($product_naam) && !empty($product_specifcaties) && !empty($product_categorie) &&
!empty($prijs)
&& !empty($product_soort)) {
print "Product aangepast!";
$sql = "UPDATE producten
SET prijs='$prijs', product_naam='$product_naam',
product_specificaties='$product_specificaties',
product_categorie='$product_categorie', product_soort='$product_soort'
WHERE product_id='$product_id'";
$query = $db->prepare( $sql );
$result = $query->execute();
exit();
}
}
?>
<html>
<form name="admin" action="producten_echt_aanpassen.php" method="POST" id="adminform" enctype="multipart/form-data">
<p>
<label for 'product_naam'>Naam: </label><br>
<input type="text" name="product_naam" value="<?php print $product_naam; ?>"/>
</p>
<p> <label for 'product_specificaties'>Specificaties: </label><br>
<textarea rows= "4" cols="50" name="product_specificaties"><?php print $product_specificaties; ?>
</textarea>
</p>
<p>
<label for 'prijs'>Prijs: </label><br>
<input type="text" name="prijs" value="<?php print $prijs; ?>"/>
</p>
<p>
<label for 'product_categorie'>Iphone: </label><br>
<input type="text" name="product_categorie" value="<?php print $product_categorie; ?>"/>
</p>
<p>
<label for 'product_soort'>Soort: </label><br>
<input type="text" name="product_soort" value="<?php print $product_soort; ?>"/>
</p>
<br/>
<label for 'uploadfile'>Kies foto <img src="<?php print $foto; ?>"></label><br>
<input type="file" name="file" ><br><br>
<input type="submit" name="submit" value="Submit">
</form>
</html>
the variable is loaded in a form in which product details can be changed. the form links to this page with the code above. but whenever I submit the form and try to change te detail i get an error of an undefined index. which is what the $_GET does in line 5. The foreach loop needs the index to be defined but whenever the form is submitted, the index in the URL is gone so the loop doesnt produce the variables that need to go to the database. I hope this makes sense. Can anybody help me out please?
Your html does not include a field named id.
You are sending the form as POST not GET, so after you add the correct field in the HTML you need to refer to it as $product_id = $_POST['id'];
No need for enctype="multipart/form-data", it will only be helpful when you are uploading files. Otherwise it can cause you problems.
<p>
<label for 'product_naam'>Naam: </label><br>
<input type="text" name="product_naam" value="<?php print $product_naam; ?>"/>
</p>
<p> <label for 'product_specificaties'>Specificaties: </label><br>
<textarea rows= "4" cols="50" name="product_specificaties"><?php print $product_specificaties; ?>
</textarea>
</p>
<p>
<label for 'prijs'>Prijs: </label><br>
<input type="text" name="prijs" value="<?php print $prijs; ?>"/>
</p>
<p>
<label for 'product_id'>Product ID: </label><br>
<input type="text" name="id" value="<?php print $product_id; ?>"/>
</p>
<p>
<label for 'product_categorie'>Iphone: </label><br>
<input type="text" name="product_categorie" value="<?php print $product_categorie; ?>"/>
</p>
<p>
<label for 'product_soort'>Soort: </label><br>
<input type="text" name="product_soort" value="<?php print $product_soort; ?>"/>
</p>
<br/>
<label for 'uploadfile'>Kies foto <img src="<?php print $foto; ?>"></label><br>
<input type="file" name="file" ><br><br>
<input type="submit" name="submit" value="Submit">
Hope this helps!
The script for handling the action of my form redirects to the form page if the values are not in proper format. I want to fill the textfields and textarea with the faulty data the user entered on redirect to the form page. I have written the following script which redirects the page on wrong value submission, but does not fill the fields thereafter.
script on form page:
<?php
if(session_id('stat')=="true")
{
$isbn=$_SESSION['var1'] ;
$name=$_SESSION['var2'] ;
$author=$_SESSION['var3'] ;
$publisher=$_SESSION['var4'];
$price=$_SESSION['var5'];
$descrip=$_SESSION['var6'];
$status=$_SESSION['stat'];
}
else
{
$isbn="";
$name="";
$author="";
$publisher="";
$price="";
$descrip="";
$status=false;
}
?>
The html part of the form:
<form action="scripts/addscript.php" method="POST" enctype="multipart/form-data" name="form1" id="form1">
<label for="isbn">ISBN</label>
<input type="text" name="isbn" id="isbn" value="<?php $isbn ?>"/>
<p>
<label for="name">Name</label>
<input type="text" name="name" id="name" value="<?php echo $name; ?>"/>
</p>
<p>
<label for="author">Author</label>
<input type="text" name="author" id="author" value="<?php echo $author; ?>"/>
</p>
<p>
<label for="publisher">Publisher</label>
<input type="text" name="publisher" id="publisher" value="<?php echo $publisher; ?>"/>
</p>
<p>
<label for="price">Price</label>
<input type="text" name="price" id="price" value="<?php echo $price;?>"/>
</p>
<p>
<label for="description">Description</label>
<textarea name="description" id="description" cols="45" rows="5"><?php echo $descrip; ?></textarea>
</p>
<p>
<label for="img">Select an image for the book:
<input type="file" name="img" id="img" />
</label>
<input type="submit" name="submit" id="submit" value="Submit"/>
</p>
</form>
The redirecting script on addscript.php to which the form values are submitted:
<?php
// Get values from form
$isbn=$_POST['isbn'];
$name=$_POST['name'];
$author=$_POST['author'];
$publisher=$_POST['publisher'];
$price=$_POST['price'];
$descrip=$_POST['description'];
$_SESSION['var1'] = $isbn;
$_SESSION['var2'] = $name;
$_SESSION['var3'] = $author;
$_SESSION['var4'] = $publisher;
$_SESSION['var5'] = $price;
$_SESSION['var6'] = $descrip;
if(strlen($isbn)==0||strlen($name)==0||strlen($author)==0||strlen($publisher)==0||strlen($price)==0)
{
$_SESSION['stat']="true";
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
Please telll me where is the problem and how can I solve the issue?
Thanks in advance.
session_start() must be called at the top of your PHP script to use the $_SESSION variable.