PHP code example of hyderkamran / laravel-form-builder

1. Go to this page and download the library: Download hyderkamran/laravel-form-builder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hyderkamran / laravel-form-builder example snippets


return [
    'storage_disk'             => 'public',        // disk for file uploads
    'export_format'            => ['csv', 'xlsx', 'pdf'],
    'enable_notifications'     => true,
    'notification_recipients'  => [],              // fallback emails
    'admin_middleware'         => ['web'],          // add 'auth' to protect
    'cache_ttl'                => 3600,            // seconds; 0 = disabled
    'upload' => [
        'max_size_kb'   => 10240,
        'allowed_mimes' => ['jpeg', 'png', 'pdf', 'docx', ...],
    ],
];

use Hyderkamran\FormBuilder\Models\Form;
use Hyderkamran\FormBuilder\Models\FormField;
use Hyderkamran\FormBuilder\Enums\FieldType;

$form = Form::create([
    'title'       => 'Contact Us',
    'slug'        => 'contact-us',
    'description' => 'We would love to hear from you.',
    'is_active'   => true,
]);

FormField::create([
    'form_id'          => $form->id,
    'label'            => 'Full Name',
    'name'             => 'name',
    'type'             => FieldType::Text->value,
    'is_ed' => true,
    'order'       => 2,
    'options'     => [
        'choices' => ['pk' => 'Pakistan', 'us' => 'United States', 'uk' => 'United Kingdom'],
    ],
]);

use Hyderkamran\FormBuilder\Enums\FieldType;

FieldType::Rating->label();   // "Star Rating"
FieldType::Rating->icon();    // "bi-star"
FieldType::Rating->group();   // "Special"
FieldType::grouped();         // ['Basic' => [...], 'Choice' => [...], ...]

FormField::create([
    // ... other attributes
    'options' => [
        'logic' => [
            'field'    => 'country',   // watch this field
            'operator' => '=',         // =, !=, >, <
            'value'    => 'pk',        // match this value
            'action'   => 'show',      // 'show' or 'hide'
        ],
    ],
]);

FormField::create([
    'form_id' => $form->id,
    'label'   => 'Work Experience',
    'name'    => 'experience',
    'type'    => FieldType::Repeater->value,
    'options' => [
        'fields' => [
            ['name' => 'company', 'label' => 'Company', 'type' => 'text',   '

use Hyderkamran\FormBuilder\Services\FormExporter;

// By slug or ID:
FormExporter::toCSV('contact-us');
FormExporter::toExcel('contact-us');
FormExporter::toPdf('contact-us');

$form->update([
    'settings' => [
        'enable_notifications'     => true,
        'notification_recipients'  => ['[email protected]'],
        'webhook_enabled'          => true,
        'webhook_url'              => 'https://hooks.example.com/form',
    ]
]);

use Hyderkamran\FormBuilder\Traits\HasForms;

class Contact extends Model
{
    use HasForms;
}

// Attach a form to any model via polymorphic relation:
$contact->forms()->attach($form->id);