Page 1 of 1

Require first and last name

Posted: Tue Nov 26, 2024 3:21 pm
by michalhana99
Script URL:
Version of script:
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution:

Write your message below:

Hi,
first of all I would like to thank you for the work you do.

I would need the user to enter their first and last name when submitting a ticket, in previous versions I solved this using code, see link below.

viewtopic.php?f=13&t=6977&p=29010&hilit ... ame#p29010

But in the new version 3.5.1, it will obviously need to be edited elsewhere

Thanks

Re: Require first and last name

Posted: Tue Nov 26, 2024 4:27 pm
by Klemen
It's a bit more complicated because customer accounts have been introduced.

Do you plan on using customer accounts or keeping them disabled?

Re: Require first and last name

Posted: Wed Nov 27, 2024 7:16 am
by michalhana99
Hi, we would like to use customer accounts.

Re: Require first and last name

Posted: Fri Nov 29, 2024 8:03 pm
by Klemen
You will need to force full names at registration time then.

In register.php, just below

Code: Select all

$name = hesk_input(hesk_POST('name'));
add

Code: Select all

if ( ! strpos($name, ' ')) {
$hesk_error_buffer['name'] = 'Please enter your full name';
}
(similar, but not same code as before)

Re: Require first and last name

Posted: Wed Dec 04, 2024 2:01 pm
by shddcit
And can I use the following code after the line?

Code: Select all

$name = hesk_input(hesk_POST('name'));

Code: Select all

function space_word_count($str)
{
    return count(preg_split('/\s+/', $str)); 
}
if ( ! strpos($tmpvar['name'], ' ')) {
    $hesk_error_buffer['name'] = $hesklang['enter_your_full_name'];
} 
else
if (space_word_count($tmpvar['name'])<3) {
$hesk_error_buffer['name'] = $hesklang['enter_your_full_name'];
}
else
if ( ! strpos($tmpvar['name'], '.') !==true) {
    $hesk_error_buffer['name'] = $hesklang['enter_your_full_name'];
}
Or would this be a more accurate option?

Code: Select all

function space_word_count($str)
{
    return count(preg_split('/\s+/', $str));
}

if (strpos($name, ' ') === false || space_word_count($name) < 3 || strpos($name, '.') !== false) {
    $hesk_error_buffer['name'] = $hesklang['enter_your_full_name']; // $hesklang['enter_your_full_name'] it is necessary to add to your translation text file so that the message is displayed
}

P.S. That's it, my second option actually gave me the ability to restrict registration without using my conditions.

Re: Require first and last name

Posted: Wed Dec 04, 2024 4:44 pm
by Klemen
Depending on how much you wish to complicate your customer's life :)

Use whatever works for you. It can be as simple as checking that there is an empty space in the name, or as complex as verifying the number of words, their length, composition, ...