Welcome Guest, Not a member yet? Register   Sign In
Immediate server side validation with Codeigniter HTMX and Bootstrap
#3

(This post was last modified: 06-19-2023, 06:04 AM by FabriceL.)

Hello @dgvirtual ,

I'm working on a project with which I use HTMX/tailwindcss.
I don't use fragments like you do, but CI4 view.

[Image: Screenshot-24.png]
Form : 
PHP Code:
<?= form_open(route_to('customer-information'$customer->getIdentifierUUID()), [
                'id' => 'kt_customers_form_information',
                'hx-post' => route_to('customer-information'$customer->getIdentifierUUID()),
                'hx-target' => '#addaddress',
                'hx-ext' => "loading-states, event-header",
                'novalidate' => false,
                'data-loading-target' => "#loadingaddaddress",
                'data-loading-class-remove' => "hidden"
            ]); ?>
            <?= '' //csrf_field() ?>
            <input type="hidden" name="section" value="adresse" />

            <?= $this->include('Btw\Customer\Views\Admin\cells\form_cell_form_addresses'); ?>


            <?= form_close(); ?>

Vue : 
PHP Code:
view_cell('Btw\Core\Cells\InputCell::renderList', [
            'type' => 'text',
            'label' => lang('Form.general.alias'),
            'name' => 'alias',
            'value' => old('alias'$customer->alias),
            'lang' => false,
        ]); 
Controller : 
PHP Code:
$data $this->request->getPost();
                $validation service('validation');

                $validation->setRules([
                    'email' => 'required|valid_email|unique_email[' $customer->id ']',
                    'lastname' => 'permit_empty|string|min_length[3]',
                    'firstname' => 'permit_empty|string|min_length[3]',
                    'type' => 'required'

                ]);

                if (!$validation->run($data)) {
                    $this->response->triggerClientEvent('showMessage', ['type' => 'error''content' => $validation->getErrors()]);
                    return view($this->viewPrefix 'cells\form_cell_information', [
                        'customer' => $customer,
                        'validation' => $validation
                    
]);
                
Reply


Messages In This Thread
RE: Immediate server side validation with Codeigniter HTMX and Bootstrap - by FabriceL - 06-19-2023, 06:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB