How to disable the validation of some fields in Joomla 3 registration
Asked Answered
M

2

5

I'm building the website based on Joomla 3. I need to disable the validation of the fields: name, username, password1 (the second, because the first is password2) and email2 and use email1 as username (I installed the plugin Email for user authorization).

I have tried to remove these fields in file components/com_users/models/forms/registration.xml but the validation is still remaining. If I don't remove them but only change the rows required="true" to false for these fields the registration doesn't work at all and any user stored in the DB. How can I disable these fields?

Mouse answered 21/1, 2014 at 20:38 Comment(4)
Apart from don't hack core files. What exact version of Joomla 3 are you using?Sweeping
I hope you mean change the validation not remove it, because allowing people to put whatever they want would be extremely dangerous. For this reason some minimal things are enforced. It sounds like what you really want to do is to make a new registration component and stop using the core one. Then you'd use a plugin to force redirection if anyone ever tried to go to the core one. In core joomla you must have a username, password and email address and they must be saved separately although you can work it so that the user name and the email are the same by using a plugin.Falls
You will need some changes in com_users component, but you can make it update proof without modifying main files.Ruscio
Some useful answers here: joomla.stackexchange.com/questions/7392/…Athanor
R
7

It's not an easy workaround, and you will need some basic knowledge of Joomla and PHP, but I'll try to explain it to you as simple as i can.

>>> Creating view template override

First of all you will need to create your Registration view template override (to keep it Joomla update proof). To do so, create folder /templates/YOUT_TEMPLATE/html/com_users/registration and copy /components/com_users/views/registration/tmpl/default.php file there.

From now on you can modify registration output in your template folder.

>>> Modifying registration form output

By default Joomla takes all fields from form file /components/com_users/models/forms/registration.xml, where they are defined, and outputs them in a view. But if we don't want to use ALL the fields, we need to output fields manually. My example code only output E-mail and Password fields for registration. Here's a sample code to do so: (default.php file)

<?php
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
?>
<div class="grid_8" id="register_block">
<div class="content_block">
<h1>Registracija</h1>
<div class="login<?php echo $this->pageclass_sfx?>">
<form id="member-registration" action="<?php echo JRoute::_('index.php?option=com_users&task=registration2.register'); ?>" method="post" enctype="multipart/form-data">
<div>
<div class="login-fields">
<label id="jform_email1-lbl" for="jform_email1">E-mail:</label>
<input type="text" name="jform[email1]" id="jform_email1" value="" size="30">
</div>
<div class="login-fields">
<label id="jform_password1-lbl" for="jform_password1">Password:</label>
<input type="password" name="jform[password1]" id="jform_password1" value="" autocomplete="off" size="30">
</div>
<button type="submit" class="button"><?php echo JText::_('JREGISTER');?></button>
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="registration2.register" />
<?php echo JHtml::_('form.token');?>
</div>
</form>
</div>
</div>
</div>

Please note, that I've also replaced task value from registration.register to registration2.register, I did this to bypass some of validation rules using my own controller.

>>> Creating controller override

Locate file /components/com_users/controllers/registration.php and create a copy of it called registration2.php in same folder.

Open file registration2.php and change It's class name from UsersControllerRegistration to UsersControllerRegistration2

From now on Joomla registration form will use this class to create a new user.

Find a method called register and find this line:

$requestData = JRequest::getVar('jform', array(), 'post', 'array');

This is where Joomla get's registration form data. Add the following lines:

$requestData['name'] = $requestData['email1'];
$requestData['username'] = $requestData['email1'];
$requestData['email2'] = $requestData['email1'];
$requestData['password2'] = $requestData['password1'];

It will add missing registration info, and help you pass validation.

NOTE: This is a sample code, to show the main logic. If anyone has a better solution, I'd be more than happy to hear it.

Ruscio answered 22/1, 2014 at 10:27 Comment(0)
S
1

Following same idea, a simpler solution might be just including hidden inputs with values in com_users\views\registration\tmpl\default.php above

<button type="submit" class="btn btn-primary validate"><?php echo JText::_('JREGISTER');?></button>

add

<input type="hidden" id="jform[username]" name="jform[username]" value="username" />
<input type="hidden" id="jform_name" name="jform[name]" value="name" />

It would pass the validation and you would no longer need to override controllers etc.

Summerlin answered 24/6, 2015 at 16:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.