PHP code example of thewebmen / silverstripe-ajaxforms
1. Go to this page and download the library: Download thewebmen/silverstripe-ajaxforms 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/ */
thewebmen / silverstripe-ajaxforms example snippets
use TheWebmen\Ajaxforms\AjaxForm;
use SilverStripe\Control\RequestHandler;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\RequiredFields;
class ExampleForm extends AjaxForm {
public function __construct(RequestHandler $controller = null)
{
$fields = new FieldList(array(
TextField::create('MyField', 'This is a field')
));
$actions = new FieldList(array(
FormAction::create('handle', 'Send')
));
$validator = new ExampleFormValidator(array(
'MyField'
));
parent::__construct($controller, 'MyField', $fields, $actions, $validator);
}
public function handle($data){
$response = new \TheWebmen\Ajaxforms\AjaxFormResponse();
return $response->redirect('http://www.google.nl');
}
}
class ExampleFormValidator extends RequiredFields {
public function php($data)
{
$valid = parent::php($data);
if($data['MyField'] != 'Test'){
$this->validationError(
'MyField',
'This field is only valid if the value is: Test',
'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.