1. Go to this page and download the library: Download selcukmart/spider-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/ */
selcukmart / spider-form example snippets
use SpiderForm\V2\Builder\FormBuilder;
use SpiderForm\V2\Translation\FormTranslator;
use SpiderForm\V2\Translation\Loader\PhpLoader;
// Setup translator (optional)
$translator = new FormTranslator('en_US');
$translator->addLoader('php', new PhpLoader());
$translator->loadTranslationFile(__DIR__ . '/translations/forms.en_US.php', 'en_US', 'php');
FormBuilder::setTranslator($translator);
// Build form with CSRF protection (automatic!)
$form = FormBuilder::create('contact_form')
->setAction('/contact/send')
->setMethod('POST')
->setCsrfTokenId('contact_form') // Automatic CSRF protection
->addText('name', 'form.label.name') // Translated automatically
->
use SpiderForm\V2\Builder\FormBuilder;
use SpiderForm\V2\Form\Form;
use SpiderForm\V2\Validation\Constraints\Callback;
// Create address sub-form
$addressForm = new Form('address');
$addressForm->add('street', FormBuilder::text('street', 'Street'));
$addressForm->add('city', FormBuilder::text('city', 'City'));
$addressForm->add('zipcode', FormBuilder::text('zipcode', 'ZIP Code'));
// Create user form with nested address
$form = FormBuilder::create('user_registration')
->setCsrfTokenId('register')
->addText('username', 'Username')
->irm')
->addViolation();
}
}));
// Validate and handle errors
$form->submit($_POST);
if ($form->isValid()) {
// Process data
} else {
$errors = $form->getErrorList(deep: true);
}