silverstripe-frameworktest/code/recaptcha/RecaptchaTestPage.php

50 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2010-10-08 05:06:37 +02:00
<?php
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\Form;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPResponse;
2015-12-17 21:20:49 +01:00
class RecaptchaTestPage extends Page
{
2010-10-08 05:06:37 +02:00
}
2017-01-15 09:19:56 +01:00
class RecaptchaTestPage_Controller extends PageController
2015-12-17 21:20:49 +01:00
{
2017-01-15 09:19:56 +01:00
2015-12-17 21:20:49 +01:00
public function Form()
{
$fields = new FieldList(
new TextField('MyText')
);
if (class_exists('RecaptchaField')) {
$fields->push(new RecaptchaField('MyRecaptcha'));
} else {
$fields->push(new LiteralField('<p class="message error">RecaptchaField class not found</p>'));
}
2017-01-15 09:19:56 +01:00
2015-12-17 21:20:49 +01:00
$form = new Form(
$this,
'Form',
$fields,
new FieldList(
new FormAction('submit', 'submit')
),
new RequiredFields(array('MyText'))
);
2017-01-15 09:19:56 +01:00
2015-12-17 21:20:49 +01:00
return $form;
}
2017-01-15 09:19:56 +01:00
public function submit(array $data, Form $form): HTTPResponse
2015-12-17 21:20:49 +01:00
{
$form->sessionMessage('Hooray!', 'good');
2017-01-15 09:19:56 +01:00
2015-12-17 21:20:49 +01:00
return Director::redirectBack();
}
}