--- title: "contact-02" description: "Centred long contact form: name, email and phone fields, a topic select, a radio group, a message and a terms checkbox." category: "Contact" --- # contact-02 Centred long contact form: name, email and phone fields, a topic select, a radio group, a message and a terms checkbox. ## Installation ```bash php artisan ui:add-block contact-02 ``` ## Dependencies - composer: `gehrisandro/tailwind-merge-laravel` - component: [button](https://laralcn-ui.abdulkadersafi.com/components/button.md) — the CLI installs it for you. - component: [checkbox](https://laralcn-ui.abdulkadersafi.com/components/checkbox.md) — the CLI installs it for you. - component: [input](https://laralcn-ui.abdulkadersafi.com/components/input.md) — the CLI installs it for you. - component: [label](https://laralcn-ui.abdulkadersafi.com/components/label.md) — the CLI installs it for you. - component: [radio](https://laralcn-ui.abdulkadersafi.com/components/radio.md) — the CLI installs it for you. - component: [select](https://laralcn-ui.abdulkadersafi.com/components/select.md) — the CLI installs it for you. - component: [textarea](https://laralcn-ui.abdulkadersafi.com/components/textarea.md) — the CLI installs it for you. ## Source `resources/views/components/ui/blocks/contact-02.blade.php` ```blade {{-- Every piece of content is a prop, so you can drive this block from a CMS. A field is ['name' =>, 'label' =>, 'type' =>, 'placeholder' =>, 'required' =>, 'width' =>, 'options' =>]. type is text, email, tel, textarea, select or radio (any other value is passed to the input as its type). width is full (default), half (half width at every size) or md:half (full on phones, half from md up). select and radio read 'options': plain strings or ['label' => ..., 'value' => ...]. Pass :terms="false" to drop the checkbox. method can be GET, POST, PUT, PATCH or DELETE; a @csrf field is added for anything but GET unless you pass :csrf="false". --}} @props([ 'tagline' => 'Tagline', 'heading' => 'Contact us', 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'action' => '#', 'method' => 'POST', 'csrf' => true, 'fields' => [ ['name' => 'first_name', 'label' => 'First name', 'width' => 'half'], ['name' => 'last_name', 'label' => 'Last name', 'width' => 'half'], ['name' => 'email', 'label' => 'Email', 'type' => 'email', 'width' => 'md:half', 'required' => true], ['name' => 'phone', 'label' => 'Phone number', 'type' => 'tel', 'width' => 'md:half'], [ 'name' => 'topic', 'label' => 'Choose a topic', 'type' => 'select', 'placeholder' => 'Select one...', 'options' => ['First topic', 'Second topic', 'Third topic'], ], [ 'name' => 'role', 'label' => 'Which best describes you?', 'type' => 'radio', 'options' => ['First choice', 'Second choice', 'Third choice', 'Fourth choice', 'Fifth choice', 'Other'], ], [ 'name' => 'message', 'label' => 'Message', 'type' => 'textarea', 'placeholder' => 'Type your message...', 'required' => true, ], ], 'terms' => 'I accept the', 'termsLink' => ['label' => 'Terms', 'href' => '#'], 'submitLabel' => 'Submit', ]) @php // A plain form only knows GET and POST; anything else is spoofed with _method. $verb = strtoupper($method); $formMethod = $verb === 'GET' ? 'GET' : 'POST'; @endphp
merge(['class' => 'bg-background px-[5%] py-16 text-foreground md:py-24 lg:py-28']) }}>
@if ($tagline)

{{ $tagline }}

@endif

{{ $heading }}

@if ($description)

{{ $description }}

@endif
@if ($formMethod === 'POST') @if ($csrf) @csrf @endif @if ($verb !== 'POST') @method($verb) @endif @endif
@foreach ($fields as $field) @php $type = $field['type'] ?? 'text'; $fieldName = $field['name'] ?? 'field_' . $loop->index; $fieldId = 'contact-02-' . $fieldName; $span = match ($field['width'] ?? 'full') { 'half' => 'col-span-1', 'md:half' => 'col-span-2 md:col-span-1', default => 'col-span-2', }; $options = array_map( static fn($option): array => is_array($option) ? $option + ['value' => $option['label'] ?? ''] : ['label' => $option, 'value' => $option], $field['options'] ?? [], ); @endphp @if ($type === 'radio')
{{ $field['label'] ?? '' }}
@foreach ($options as $option) {{ $option['label'] }} @endforeach
@else
{{ $field['label'] ?? '' }} @if ($type === 'textarea') @elseif ($type === 'select') @foreach ($options as $option) @endforeach @else @endif
@endif @endforeach
@if ($terms) @endif {{ $submitLabel }}
```