Registration Page with custom Field

I added new Register Page to my Panel, and need a new Field for REFERENCE CODE INVITE.
protected function getInviteCodeFormComponent(): Component
{
return Field::make('ref_code')
->label('Invite Code')
->helperText('Inout your invite code here.')
->exists(modifyRuleUsing: function (Exists $rule) {

$rule->where(function ($query, $value) {
// Check if the Invite Code exists
$search_owner = User::where('ref_code', $value)
->where('manager_level', 2)
->first();

if (!$search_owner) {
// If the invite code does not exist, show an error message
$query->fail('Invalid Manager Code.');
}

// If the invite code exists, then add the "$search_owner->id" to your "affiliate_id" user registration.
});

});
}
protected function getInviteCodeFormComponent(): Component
{
return Field::make('ref_code')
->label('Invite Code')
->helperText('Inout your invite code here.')
->exists(modifyRuleUsing: function (Exists $rule) {

$rule->where(function ($query, $value) {
// Check if the Invite Code exists
$search_owner = User::where('ref_code', $value)
->where('manager_level', 2)
->first();

if (!$search_owner) {
// If the invite code does not exist, show an error message
$query->fail('Invalid Manager Code.');
}

// If the invite code exists, then add the "$search_owner->id" to your "affiliate_id" user registration.
});

});
}
But causing this error when send submit.
No description
No description
7 Replies
DrByte
DrByte12mo ago
Can you post the FlareApp share URL from the error page? (Your screenshot of a bunch of error text is really hard to read; seeing the stack trace in Flare would be much easier to trace through)
No description
DrByte
DrByte12mo ago
And it would be helpful to see the code for your Register page and User model.
Skull™👻
Skull™👻OP12mo ago
How to capture the share link if error is from Filament Error in Modal Popup?
Skull™👻
Skull™👻OP12mo ago
<?php

namespace App\Filament\Affiliate\Pages\Auth;

use App\Models\User;
use Filament\Forms\Components\Component;
use Filament\Forms\Components\Field;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Auth\Register as AuthRegister;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Validation\Rules\Exists;

class Register extends AuthRegister
{
public function getTitle(): string | Htmlable
{
return 'Cadastro';
}

public function getHeading(): string | Htmlable
{
return 'Cadastro';
}

public function form(Form $form): Form
{
return $form
->schema([
$this->getInviteCodeFormComponent(),
$this->getNameFormComponent(),
$this->getDocumentFormComponent(),
$this->getPhoneFormComponent(),
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
])
->statePath('data');
}

protected function getDocumentFormComponent(): Component
{
return TextInput::make('document')
->label('CPF')
->mask('999.999.999-99')
->required()
->maxLength(14)
->unique($this->getUserModel())
->helperText('Seu CPF será usado para recebimentos dos pagamentos. 999.999.999-99');
}

protected function getPhoneFormComponent(): Component
{
return TextInput::make('phone')
->label('Telefone')
->mask('(99) 99999-9999')
->required()
->maxLength(15)
->unique($this->getUserModel())
->helperText('Informe o DDD e o número do seu telefone celular. (99) 99999-9999');
}

protected function getInviteCodeFormComponent(): Component
{
return Field::make('ref_code')
->label('Invite Code')
->helperText('Inout your invite code here.')
->exists(modifyRuleUsing: function (Exists $rule) {

$rule->where(function ($query, $value) {
// Check if the Invite Code exists
$search_owner = User::where('ref_code', $value)
->where('manager_level', 2)
->first();

if (!$search_owner) {
// If the invite code does not exist, show an error message
$query->fail('Invalid Manager Code.');
}

// If the invite code exists, then add the "$search_owner->id" to your "affiliate_id" user registration.
});

});
}

}
<?php

namespace App\Filament\Affiliate\Pages\Auth;

use App\Models\User;
use Filament\Forms\Components\Component;
use Filament\Forms\Components\Field;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Auth\Register as AuthRegister;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Validation\Rules\Exists;

class Register extends AuthRegister
{
public function getTitle(): string | Htmlable
{
return 'Cadastro';
}

public function getHeading(): string | Htmlable
{
return 'Cadastro';
}

public function form(Form $form): Form
{
return $form
->schema([
$this->getInviteCodeFormComponent(),
$this->getNameFormComponent(),
$this->getDocumentFormComponent(),
$this->getPhoneFormComponent(),
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
])
->statePath('data');
}

protected function getDocumentFormComponent(): Component
{
return TextInput::make('document')
->label('CPF')
->mask('999.999.999-99')
->required()
->maxLength(14)
->unique($this->getUserModel())
->helperText('Seu CPF será usado para recebimentos dos pagamentos. 999.999.999-99');
}

protected function getPhoneFormComponent(): Component
{
return TextInput::make('phone')
->label('Telefone')
->mask('(99) 99999-9999')
->required()
->maxLength(15)
->unique($this->getUserModel())
->helperText('Informe o DDD e o número do seu telefone celular. (99) 99999-9999');
}

protected function getInviteCodeFormComponent(): Component
{
return Field::make('ref_code')
->label('Invite Code')
->helperText('Inout your invite code here.')
->exists(modifyRuleUsing: function (Exists $rule) {

$rule->where(function ($query, $value) {
// Check if the Invite Code exists
$search_owner = User::where('ref_code', $value)
->where('manager_level', 2)
->first();

if (!$search_owner) {
// If the invite code does not exist, show an error message
$query->fail('Invalid Manager Code.');
}

// If the invite code exists, then add the "$search_owner->id" to your "affiliate_id" user registration.
});

});
}

}
DrByte
DrByte12mo ago
Does the same problem happen if you "only clone the Registration" class? ie: if you back out all the things you've added, does the problem continue? Researching that will help find out which field or code-change is triggering it.
Skull™👻
Skull™👻OP12mo ago
I didn't quite understand what said. My problem is that I want to enter another user's guest code and then associate the code owner's ID with this new record. understand? The registration system works, if I remove the "invite code" input required. however, I need this field for my project concept to work. and this is causing me problems because I can't find any way to make it work.
DrByte
DrByte12mo ago
You said the errors appear when you click Submit ... which is when Validation runs. If you remove the ->exists(....) logic from that InviteCode field, does it all work correctly? (obviously, except that it could allow a a fake code to be used). So: is the error in your custom validation rule?
Want results from more Discord servers?
Add your server