Magento Custom User Registration - php

I have already created a custom layout for my Magento theme which works fine. The only issue I have so far is that my registration does absolutely nothing. I have tried searching but only seem to come up with results on how to add new fields to a registration page. My current code is as follows:
<div id="user-login">
<span class="log-head loginfield">
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
<h2>You Already Have An Account</h2>
<p>Please login with your e-mail and password</p>
<span>
<label>Enter your E-mail address:</label>
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
</span>
<span>
<label>Enter your password:</label>
<input type="password" name="login[password]" class="input-text required-entry validate-password" id="pass" title="<?php echo $this->__('Password') ?>" />
</span>
<input class="submit" type="submit" value="Submit">
</form>
</span>
<span class="log-head registerfield">
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
<input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
<input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>" />
<h2>You Don't Have An Account</h2>
<p>Please enter your information and create an account</p>
<span>
<label>Email Address:</label>
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
</span>
<span>
<label>Enter your password:</label>
<input type="password" name="password" id="password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" />
</span>
<span>
<label>Re-Enter your password:</label>
<input type="password" name="confirmation" title="<?php echo $this->__('Confirm Password') ?>" id="confirmation" class="input-text required-entry validate-cpassword" />
</span>
<input class="submit" type="submit" value="Create Account">
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('form-validate', true);
<?php if($this->getShowAddressFields()): ?>
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
<?php endif; ?>
//]]>
</script>
</span>
</div><!--/user-login -->
I combined the registration and login page to fit my design. The input fields are taken directly from the base theme. After I try to test and create a user the page just refreshes and the user is never created. The same goes if I create a user from the backend and try to login the page refreshes but never logs me in.
Any help will definitely be appreciated.

The reason you are have issue is because both forms are pointing to the same form action (assuming that the input names are the same as default magento)
action="<?php echo $this->getPostActionUrl()
This should Fix your issue
Change this (I not sure which block type you are using so i'm going to change both action)
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
to
<form action="<?php echo Mage::helper('customer')->getLoginPostUrl() ?>" method="post" id="login-form">
Change this
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
to
<form action="<?php echo Mage::helper('customer')->getRegisterPostUrl() ?>" method="post" id="form-validate">
If this doesn't work then view page source and look where both form action is pointed (see below for location where they should point). Try changing the action to
<?php echo Mage::getUrl() . '/customer/account/loginPost/'; ?> and <?php echo Mage::getUrl() . /customer/account/createpost/ ?>
Reason for Issue
By default magento sperate the registration and login form into 2 different pages which uses two different block
see /app/design/frontend/default/contempospace/layout/customer.xml (customer_account_create and customer_account_login)
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
Both block have a method getPostActionUrl() which point to different url /customer/account/loginPost/ and /customer/account/createpost/
See
/app/code/core/Mage/Customer/Block/Form/Login.php
/app/code/core/Mage/Customer/Block/Form/Register.php
You may want take a look at How Blocks And PHTML Work Together

Try to use:
<input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
And you should use the same name to field from origin's one.

<input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
<input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">

Everyone was super helpful with this ( I had the same problem ). Took me a bit, but this surfaced after a recent upgrade. The issue was that the registration form didn't have the formkey field in it, simply add the line below to the form and it started working properly for me.
<?php echo $this->getBlockHtml('formkey')?>

Related

Form action WordPress Plugin

I am creating a specialized WordPress plugin, and its not for use outside of this singular case for the rest of the question we will refer to the wordpress plugin folder as plug-folder. Inside the plug-folder I have multiple files, a file named form_submit.php and a file named form_template.php. form_template.php is registered as a page template that can be applied to any post or page through the WordPress dashboard. The issue is because the form_submit.php file is inside the plugin folder how do I map my form action to post the data to the file? Simply listing it as
<form action="form_submit.php" method="post" >
Will not work as I need because it will be looking for the form_submit.php in the root directory of the site not the plugin folder and trying to map out the URL scheme for it in the plugin folder like
<form action="wp-content/plugins/plug-folder/form_submit.php" method="post" >
Doesn't work either, does a method exist that I am not thinking of?
Edit: After switching to use plugins_url() as suggested its working in one of the two instances where I am using forms. My register form (attached below) is not working, comes back error loading page.
<form action="<?php echo plugins_url( 'register_submit.php', __FILE__ ); ?>" method="post" autocomplete="off">
<?php if($_GET['error'] == 'username'){ ?>
<div class="error_message">
Uh oh! That username is already taken.
</div>
<?php }else if($_GET['error'] == 'email'){ ?>
<div class="error_message">
Uh oh! That email is already in use.
</div>
<?php }else if($_GET['error'] == 'email_invalid'){ ?>
<div class="error_message">
Uh oh! Make sure to enter a valid email.
</div>
<?php }else if($_GET['error'] == 'signup_blank'){ ?>
<div class="error_message">
Uh oh! Make sure to fill in all the fields.
</div>
<?php } ?>
<input type="text" name="first_name" class="signup_input" id="first_name_input" placeholder="First Name" value="<?= $_GET['first_name']; ?>" required>
<input type="text" name="last_name" class="signup_input" id="last_name_input" placeholder="Last Name" value="<?= $_GET['last_name']; ?>" required>
<input type="text" name="email" class="signup_input" placeholder="Email" value="<?= $_GET['email']; ?>" required>
<input type="password" name="password" class="signup_input" placeholder="Password" required>
<input type="radio" name="gender" value="Female" required> <font color="#FFF">Female</font>
<input type="radio" name="gender" value="Male" required> <font color="#FFF">Male </font>
<input type="submit" name="submit" class="btn btn-default" value="Sign Up" style="margin-left: 15px;">
</form>
But my login form works.
<form action="<?php echo plugins_url( 'login_submit.php', __FILE__ ); ?>" method="post" autocomplete="off">
<div class="list-block">
<ul>
<span class="ti-user"></span>
<div class="item-input">
<input type="text" name="email" placeholder="E-Mail">
</div>
<div class="item-content margin-top-15">
<span class="ti-lock"></span>
<div class="item-input">
<input type="password" name="password" placeholder="Password">
</div>
</ul>
</div>
<div class="log-in-btn margin-top-15 margin-bottom-30" >
<input type="submit" name="submit" class="btn btn-default">
</div>
</form>
I am confused as to what the difference is that would cause this.
Use plugins_url()
<form action="<?php echo plugins_url( 'form_submit.php', __FILE__ ); ?>" method="post" >
Codex Reference https://codex.wordpress.org/Function_Reference/plugins_url.
Edit: Please check in wordpress settings. I think you do not have registration enabled.
Hope it helps.

Warning: No match for E-Mail Address and/or Password-opencart 2

I have problem in my code,when i am successfully registered and click on continue then it goes to login form.I'm enter my "email" and "password" then it gives me error like
"Warning: No match for E-Mail Address and/or Password."
Below is my login.tpl code
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label" for="input-email"><?php echo $entry_email; ?> </label>
<input type="text" name="email" value="<?php echo $email; ?>" placeholder="<?php echo $entry_email; ?>" id="input-email" class="form-control" />
</div>
<div class="form-group">
<label class="control-label" for="input-password"><?php echo $entry_password; ?></label>
<input type="password" name="password" value="<?php echo $password; ?>" placeholder="<?php echo $entry_password; ?>" id="input-password" class="form-control" />
<?php echo $text_forgotten; ?>
</div>
<input type="submit" value="<?php echo $button_login; ?>" class="btn btn-primary" />
<?php if ($redirect) { ?>
<input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
<?php } ?>
</form>
After registration i go to admin panel:customer then i click on edit and there again i put password and confirm and save it after that i logged in to my account .How to fix this error?
check your admin panel first that is the customer is registered or not. If customer is not registered then check your error log for errors. you must be having issue in your controller or model. The issue can also be occur if you are using any third party modules based on Vqmod or OCmod.
Go to Opencart admin panel: System > tools > Error Logs
Clear your error log then do the same registration process and then check for errors or you can share it her with me.

how can I change placeholder text depend on language

Hello I am newbie and I would like to ask how is it possible to change the placeholder depend on language?. I have a multilingual wordpress site and I wrote this code on a .php file :
<form class="search" id="searchform" action="<?php echo home_url(); ?>/" method="get">
<fieldset>
<span class="text"><input name="s" id="s" type="text" value="" placeholder="<?php echo __('Search', 'alora'); ?>" />
</span>
</fieldset>
</form> `
I also tried this:
<form class="search" id="searchform" action="<?php echo home_url(); ?>/" method="get">
<fieldset>
if (get_locale() == "en_US") {
<span class="text"><input name="s" id="s" type="text" value="" placeholder="<?php echo __('Search', 'alora'); ?>" />
</span>
}
else {
<span class="text"><input name="s" id="s" type="text" value="" placeholder="<?php echo __('Search_el', 'alora'); ?>" />
</span>
}
</fieldset>
</form>
But with no luck. Can anyone please help me?.
I also read this post Change text depending on language, but I couldn't figure it out.
<?php echo _e('Search_el', 'alora'); ?>" />
Please use this..
if above code not working than use..
printf(__('Search_el', 'alora'));

Wordpress Custom Login Form which stores the data as well as emails the field values

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.

multiple forms on a single PHP page

Im having issues with a ''profile'' page where users will be able to change their username, email, name, password and so on but it seems to have conflicts when i have more than 1 form on the page as they all work individually?
I could be missing something obvious so if anyone could help id much appreciate it.
Base
<?php
require 'core/init.php';
include 'includes/overall/header.php';
?>
<h1><p>Hello <?php echo escape($user->data()->username); ?></a>!</p></h1>
<h4><p>You joined the MMOunition community <?php echo escape($user->data()->joined); ?></a></p></h4>
<alert_banner>
<?php
if(Session::exists('home')) {
echo '<p>', Session::flash('home'), '</p>';
}
?>
</alert_banner>
<br />
<form action="changeusername.php" method="post">
<div class="field">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php echo escape($user->data()->username); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
<br />
<form action="changepassword.php" method="post">
<div class="field">
<label for="password_current">Current password:</label>
<input type="password" name="password_current" id="password_current">
</div>
<div class="field">
<label for="password_new">New password:</label>
<input type="password" name="password_new" id="password_new">
</div>
<div class="field">
<label for="password_new_again">New password again:</label>
<input type="password" name="password_new_again" id="password_new_again">
<input type="submit" value="Change">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
</br>
<form action="changename.php" method="post">
<div class="field">
<label for="name">Name:</label>
<input type="text" name="name" id="name" value="<?php echo escape($user->data()->name); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
<br />
<form action="changeemail.php" method="post">
<div class="field">
<label for="email">Change email address:</label>
<input type="text" name="email" id="email" value="<?php echo escape($user->data()->email); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
<?php
include 'includes/overall/footer.php';
?>
Hello You haven't mentioned what problem you actualy facing but this seems like the problem is the unique identification of a form at server side
Please see this post
Multiple HTML Forms on One Page
Hope this will help ;)
Have each form action set to the current page, and use hidden inputs to determine what action is being taken. Using this method will prevent the user from being dropped onto a different page, and puts the action being taken into a variable that you can use or manipulate.
If you want to have separate PHP scripts for actual functions, use includes or requires.
<form action="" method="post">
<div class="field">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php echo escape($user->data()->username); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<input type="hidden" name="action" value="changeUsername">
</div>
</form>
Then the PHP script gets the action from the POST and uses a switch to determine which functions to call.
if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
switch ($action) {
case "changeUsername":
changeUsername();
break;
case "changePassword":
...
As mentioned, if you want to have these functions in separate php files, you can use include or require.
This conveniently drops the user right back on the same page when they update information, so that they can make additional updates.

Categories