Specific fields not recorded by front-end registration form

Hi everyone,

I’m setting up a registration form in my frontend web app.
My new user is well created (name, email and password).
But impossible to get the firstname or lastname fields stored…
And so getting them setting in the corresponding fields of the panel.
Any idea please?
Many thanks !

Here is my controller code :

Here is my “register” controller’s code :

<?php

	return function ($site, $kirby) {

		//if($kirby->user()) go('/');

		$error = null;
		$success = null;

		if( $kirby->request()->is('POST') and get('register') ) {
			//if(!empty(get('website'))) {
			//go('login');
			//exit;
			//}

			try {
				$password = esc(get('password'));
				$confirm = esc(get('password_confirm'));

				if(v::same($password, $confirm)) {

					// Le nom d'utilisateur sera l'adresse courriel avec la ponctuation supprimée.
					// Les utilisateurs finaux ne l'utiliseront pas, nous avons juste besoin d'un ID unique pour le compte.
					//$username = str::slug(get('email'),'');

					$user = $kirby->users()->create([
						'name' => esc(get('name')),
						'firstname' => strip_tags(get('firstname')),
						'lastname' => strip_tags(get('lastname')),
						'email' => esc(get('email')),
						'password' => esc(get('password')),
						'language' => 'fr',
						'role' => 'wanted_role'
					]);

					$success = 'Compte créé : veuillez vérifier votre boîte email !';

					// Build the email text
					$to = $user->email();
					$from = 'myemail@email.com';
					$subject = 'Création de votre compte';
					
					$kirby->email([
						'to' => $to,
						'from' => $from,
						'subject' => $subject,
						'template' => 'register',
						'data' => [
							'name' => $user->name(),
							'email' =>  $user->email(),
							'text' => 'Thank you for registering on the link below to activate your account and choose your password.'
						]
                	]);

				} else {
					$error = 'Les mots de passe doivent être identiques !';
				}
		
			} catch(Exception $e) {
				$error = true;
			}
		}

		return compact('error', 'success');

	};

The form part of my registrer template page :

<div class="row">
	<div class="form-group col-md-6 mb-4">
		<label for="firstname" class="fw-bold">Prénom</label>
		<input name="firstname" id="firstname" type="text" class="form-control form-control-lg" value="<?= get('firstname') ?>" required />
</div>
	<div class="form-group col-md-6 mb-4">
		<label for="lastname" class="fw-bold">Nom</label>
		<input name="lastname" id="lastname" type="text" class="form-control form-control-lg" value="<?= get('lastname') ?>" required />
	</div>
</div>

Content fields need to go into the content array:

$user = $kirby->users()->create([
  'name' => esc(get('name')),
  'email' => esc(get('email')),
  'password' => esc(get('password')),
  'language' => 'fr',
  'role' => 'wanted_role',
  'content' => [
    'firstname' => strip_tags(get('firstname')),
    'lastname' => strip_tags(get('lastname')),
  ],

]);
1 Like

Thanks again and again for your help and solutions @texnixe :pray: !
Kirby’s so gorgeous !!!

Hello @SimTheGeek , would you have the code a bit more complete to see exactly how you did it?

In particular the template?