PHP code example of iainheng / form

1. Go to this page and download the library: Download iainheng/form 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/ */

    

iainheng / form example snippets


'providers' => [
        //...
        'AdamWathan\Form\FormServiceProvider'
    ],

'aliases' => [
        //...
        'Form' => 'AdamWathan\Form\Facades\Form',
    ],

$builder = new AdamWathan\Form\FormBuilder;

// <input type="text" name="email" value="[email protected]" uired(); 

// <form method="POST">
<?= $builder->open(); 

// <input type="text" name="email">
<?= $builder->text('email'); 

// <textarea name="bio" rows="5" cols="50"></textarea>
<?= $builder->textarea('bio')->rows(5); 

// <input type="checkbox" name="terms" value="1">
<?= $builder->checkbox('terms'); 

// <select name="birth_year"></select>
<?= $builder->select('birth_year'); 

// <button type="button">Click Me</button>
<?= $builder->button('Click Me'); 

// <input type="hidden" name="secret" value="my-secret-value">
<?= $builder->hidden('secret')->value('my-secret-value'); 

// <label>Email</label>
<?= $builder->label('Email'); 

// <label>Email<input type="text" name="email"></label>
<?= $builder->label('Email')->before($emailElement); 

// Attributes can be set with attribute(...)
// <input type="text" name="foobar" min="4">
<?= $builder->text('foobar')->attribute('min', 4); 

$builder->setOldInputProvider($myOldInputProvider);

$builder->setErrorStore($myErrorStore);

// Check if the form has an error for an element
$builder->hasError('email');

// Retrieve the error message for an element
$builder->getError('email');

 if ($builder->hasError('email')): 

<?= $builder->getError('email', '<span class="error">:message</span'); 

<?= $builder->token(); 

$model->first_name = "John";
$model->last_name = "Doe";
$model->email = "[email protected]";
$model->date_of_birth = new DateTime('1985-05-06');

<?= $builder->open();