v4.x: remove first and last name from signup page

cr33p

Member
YetiShare User
YetiShare Supporter
May 8, 2016
33
2
8
hi
if i remove first and last name from signup page, will registration work ok ?
i mean, i don't need people to type in such details
thanks in advance.
 

cr33p

Member
YetiShare User
YetiShare Supporter
May 8, 2016
33
2
8
how can i disable first and last name ?
can i just comment in html ?
 

adam

Administrator
Staff member
Dec 5, 2009
2,034
106
63
Hi,

Yes you should be able to remove it. Try the following:

In:

"\themes\flow\templates\register.html"

Find and remove:

Code:
$title               = trim($_REQUEST['title']);
$firstname           = trim($_REQUEST['firstname']);
$lastname            = trim($_REQUEST['lastname']);
Also remove:

Code:
if (!strlen($title))
{
    notification::setError(t("please_enter_your_title", "Please enter your title"));
}
elseif (!strlen($firstname))
{
    notification::setError(t("please_enter_your_firstname", "Please enter your firstname"));
}
elseif (!strlen($lastname))
{
    notification::setError(t("please_enter_your_lastname", "Please enter your lastname"));
}
Change:

Code:
UserPeer::create($username, $newPassword, $emailAddress, $title, $firstname, $lastname);
to:

Code:
UserPeer::create($username, $newPassword, $emailAddress, 'Mr', '', '');
You'll need to edit the content for the register email as it uses the firstnae. In the script admin, languages section, search for and edit the content for 'register_user_email_content'.

Remove:

Code:
<div class="input-group"> <span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>
                <select class="form-control" autofocus="autofocus" tabindex="1" id="title" name="title">
                    <option disabled selected><?php echo t("title", "title"); ?></option>
                    <option value="Mr" <?php echo ($title == 'Mr') ? 'SELECTED' : ''; ?>><?php echo t('title_mr', 'Mr'); ?></option>
                    <option value="Ms" <?php echo ($title == 'Ms') ? 'SELECTED' : ''; ?>><?php echo t('title_ms', 'Ms'); ?></option>
                    <option value="Mrs" <?php echo ($title == 'Mrs') ? 'SELECTED' : ''; ?>><?php echo t('title_mrs', 'Mrs'); ?></option>
                    <option value="Miss" <?php echo ($title == 'Miss') ? 'SELECTED' : ''; ?>><?php echo t('title_miss', 'Miss'); ?></option>
                    <option value="Dr" <?php echo ($title == 'Dr') ? 'SELECTED' : ''; ?>><?php echo t('title_dr', 'Dr'); ?></option>
                    <option value="Pro" <?php echo ($title == 'Pro') ? 'SELECTED' : ''; ?>><?php echo t('title_pro', 'Pro'); ?></option>
                </select>
            </div>
            <div class="input-group"><span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>
                <input type="text" class="form-control" placeholder="<?php echo t("firstname", "firstname"); ?>" tabindex="1" value="<?php echo isset($firstname) ? validation::safeOutputToScreen($firstname) : ''; ?>" id="firstname" name="firstname">
            </div>
            <div class="input-group"><span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>
                <input type="text" class="form-control" placeholder="<?php echo t("lastname", "lastname"); ?>" tabindex="1" value="<?php echo isset($lastname) ? validation::safeOutputToScreen($lastname) : ''; ?>" id="lastname" name="lastname">
            </div>
That *should* do it. I've not tested it locally, but it should point you in the right direction.

Thanks,
Adam.
 
  • Like
Reactions: cr33p

Michplark

New Member
Jun 15, 2022
2
0
1
Hi,

Yes you should be able to remove it. Try the following:

In:

"\themes\flow\templates\register.html"

Find and remove:

Code:
$title               = trim($_REQUEST['title']);
$firstname           = trim($_REQUEST['firstname']);
$lastname            = trim($_REQUEST['lastname']);
Also remove:

Code:
if (!strlen($title))
{
    notification::setError(t("please_enter_your_title", "Please enter your title"));
}
elseif (!strlen($firstname))
{
    notification::setError(t("please_enter_your_firstname", "Please enter your firstname"));
}
elseif (!strlen($lastname))
{
    notification::setError(t("please_enter_your_lastname", "Please enter your lastname"));
}
Change:

Code:
UserPeer::create($username, $newPassword, $emailAddress, $title, $firstname, $lastname);
to:

Code:
UserPeer::create($username, $newPassword, $emailAddress, 'Mr', '', '');
You'll need to edit the content for the register email as it uses the firstnae. In the script admin, languages section, search for and edit the content for 'register_user_email_content'.

Remove:

Code:
<div class="input-group"> <span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>
                <select class="form-control" autofocus="autofocus" tabindex="1" id="title" name="title">
                    <option disabled selected><?php echo t("title", "title"); ?></option>
                    <option value="Mr" <?php echo ($title == 'Mr') ? 'SELECTED' : ''; ?>><?php echo t('title_mr', 'Mr'); ?></option>
                    <option value="Ms" <?php echo ($title == 'Ms') ? 'SELECTED' : ''; ?>><?php echo t('title_ms', 'Ms'); ?></option>
                    <option value="Mrs" <?php echo ($title == 'Mrs') ? 'SELECTED' : ''; ?>><?php echo t('title_mrs', 'Mrs'); ?></option>
                    <option value="Miss" <?php echo ($title == 'Miss') ? 'SELECTED' : ''; ?>><?php echo t('title_miss', 'Miss'); ?></option>
                    <option value="Dr" <?php echo ($title == 'Dr') ? 'SELECTED' : ''; ?>><?php echo t('title_dr', 'Dr'); ?></option>
                    <option value="Pro" <?php echo ($title == 'Pro') ? 'SELECTED' : ''; ?>><?php echo t('title_pro', 'Pro'); ?></option>
                </select>
            </div>
            <div class="input-group"><span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>
                <input type="text" class="form-control" placeholder="<?php echo t("firstname", "firstname"); ?>" tabindex="1" value="<?php echo isset($firstname) ? validation::safeOutputToScreen($firstname) : ''; ?>" id="firstname" name="firstname">
            </div>
            <div class="input-group"><span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>
                <input type="text" class="form-control" placeholder="<?php echo t("lastname", "lastname"); ?>" tabindex="1" value="<?php echo isset($lastname) ? validation::safeOutputToScreen($lastname) : ''; ?>" id="lastname" name="lastname">
            </div>
That *should* do it. I've not tested it locally, but it should point you in the right direction.

Thanks,
Adam.
What about V 5 ???
 

adam

Administrator
Staff member
Dec 5, 2009
2,034
106
63
For v5.x - I've not tested this, but it should point you in the right direction... In:

/themes/spirit/views/register.html.twig

Remove:

HTML:
<div class="col-md-4" style="display: none;">
    <select autofocus="autofocus" tabindex="1" id="title" name="title">
        <option value="" selected>{{ t("title", "title") }}</option>
        {% for value in titleOptions %}
            <option value="Mr" {{ (title == value) ? 'SELECTED' : '' }}>{{ t('title_'~value, value) }}</option>
        {% endfor %}
    </select>
</div>

<div class="col-md-6">
    <input name="firstname" id="firstname" type="text" placeholder="{{ t("firstname", "firstname")|title }}" autocomplete="off" value="{{ firstname }}"/>
</div>

<div class="col-md-6">
    <input name="lastname" id="lastname" type="text" placeholder="{{ t("lastname", "lastname")|title }}" autocomplete="off" value="{{ lastname }}"/>
</div>
In:

/app/controllers/IndexController.class.php

Find and remove:

PHP:
$title = trim($request->request->get('title'));
$firstname = trim($request->request->get('firstname'));
$lastname = trim($request->request->get('lastname'));
PHP:
if (!strlen($firstname)) {
    NotificationHelper::setError(TranslateHelper::t("please_enter_your_firstname", "Please enter your firstname"));
}
elseif (!strlen($lastname)) {
    NotificationHelper::setError(TranslateHelper::t("please_enter_your_lastname", "Please enter your lastname"));
}
else
I think that should be it from the register side.

You might need to do the same in the edit user side. Them files are:

/app/controllers/AccountSettingsController.class.php
/themes/spirit/views/account/account_edit.html.twig

Note that we can't offer support on custom code changes, so this guidance is provided as-is. You would need to work over any issues yourself.
 
  • Like
Reactions: Michplark