--- title: "contact-10" description: "Contact form with name, email, phone, topic select, radio group, message and terms checkbox, beside email, phone and office details." category: "Contact" --- # contact-10 Contact form with name, email, phone, topic select, radio group, message and terms checkbox, beside email, phone and office details. ## Installation ```bash php artisan ui:add-block contact-10 ``` ## 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-10.blade.php` ```blade {{-- Contact form beside the contact details. Every piece of content is a prop. A field is ['type' => ..., 'name' => ..., 'label' => ...] where type is text, email, tel, select, radio, textarea or checkbox. Add 'placeholder', 'required' => true, 'options' (select and radio: a list of labels, or value => label pairs) and 'width' => 'half' (always half a row) or 'half-md' (half a row from md up). A checkbox takes an optional 'link' => ['label' => ..., 'href' => ...] printed after its label. Set any of email, phone or address to null to hide that item. --}} @props([ 'id' => 'contact-10', 'tagline' => 'Tagline', 'heading' => 'Contact us', 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'action' => '#', 'method' => 'POST', 'csrf' => true, 'fields' => [ ['type' => 'text', 'name' => 'first_name', 'label' => 'First name', 'width' => 'half'], ['type' => 'text', 'name' => 'last_name', 'label' => 'Last name', 'width' => 'half'], ['type' => 'email', 'name' => 'email', 'label' => 'Email', 'width' => 'half-md'], ['type' => 'tel', 'name' => 'phone', 'label' => 'Phone number', 'width' => 'half-md'], [ 'type' => 'select', 'name' => 'topic', 'label' => 'Choose a topic', 'placeholder' => 'Select one...', 'options' => ['First topic', 'Second topic', 'Third topic'], ], [ 'type' => 'radio', 'name' => 'role', 'label' => 'Which best describes you?', 'options' => ['First choice', 'Second choice', 'Third choice', 'Fourth choice', 'Fifth choice', 'Other'], ], ['type' => 'textarea', 'name' => 'message', 'label' => 'Message', 'placeholder' => 'Type your message...'], [ 'type' => 'checkbox', 'name' => 'terms', 'label' => 'I accept the', 'link' => ['label' => 'Terms', 'href' => '#'], 'required' => true, ], ], 'submitLabel' => 'Submit', 'emailTitle' => 'Email', 'emailDescription' => 'Lorem ipsum dolor sit amet.', 'email' => 'email@example.com', 'phoneTitle' => 'Phone', 'phoneDescription' => 'Lorem ipsum dolor sit amet.', 'phone' => '+1 (555) 000-0000', 'addressTitle' => 'Office', 'address' => '123 Sample St, Sydney NSW 2000 AU', 'directionsLabel' => 'Get Directions', 'directionsHref' => null, ]) @php $options = static fn(array $field): array => collect($field['options'] ?? []) ->mapWithKeys(fn($label, $value) => [is_int($value) ? $label : $value => $label]) ->all(); $span = static fn(array $field): string => match ($field['width'] ?? null) { 'half' => 'col-span-1', 'half-md' => 'col-span-2 md:col-span-1', default => 'col-span-2', }; $tel = $phone ? 'tel:' . preg_replace('/[^\d+]/', '', $phone) : null; $directions = $directionsHref ?? ($address ? 'https://www.google.com/maps/search/?api=1&query=' . urlencode($address) : null); @endphp
merge(['class' => 'w-full bg-background px-[5%] py-16 text-foreground md:py-24 lg:py-28']) }}>
@if ($tagline)

{{ $tagline }}

@endif

{{ $heading }}

@if ($description)

{{ $description }}

@endif
@if ($csrf && strtoupper($method) !== 'GET') @csrf @endif @if (!in_array(strtoupper($method), ['GET', 'POST'], true)) @method($method) @endif @foreach ($fields as $field) @php $type = $field['type'] ?? 'text'; $name = $field['name'] ?? 'field_' . $loop->index; $fieldId = $id . '-' . $name; $required = !empty($field['required']); @endphp @if ($type === 'radio')
{{ $field['label'] ?? '' }}
@foreach ($options($field) as $value => $label) {{ $label }} @endforeach
@elseif ($type === 'checkbox')
{{ $field['label'] ?? '' }} @isset($field['link']) {{ $field['link']['label'] ?? '' }} @endisset
@else
{{ $field['label'] ?? '' }} @if ($type === 'select') @isset($field['placeholder']) @endisset @foreach ($options($field) as $value => $label) @endforeach @elseif ($type === 'textarea') @else @endif
@endif @endforeach
{{ $submitLabel }}
@if ($email)

{{ $emailTitle }}

@if ($emailDescription)

{{ $emailDescription }}

@endif {{ $email }}
@endif @if ($phone)

{{ $phoneTitle }}

@if ($phoneDescription)

{{ $phoneDescription }}

@endif {{ $phone }}
@endif
@if ($address)

{{ $addressTitle }}

{{ $address }}
@if ($directionsLabel && $directions) {{ $directionsLabel }} @endif
@endif
```