2017-03-02 03:24:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace SilverStripe\Control\Tests\RequestHandlingTest;
|
|
|
|
|
2022-10-17 06:58:20 +02:00
|
|
|
use SilverStripe\Control\HTTPRequest;
|
|
|
|
use SilverStripe\Control\HTTPResponse;
|
2017-03-02 03:24:38 +01:00
|
|
|
use SilverStripe\Forms\FormRequestHandler;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for
|
|
|
|
* @see TestForm
|
|
|
|
*/
|
|
|
|
class TestFormHandler extends FormRequestHandler
|
|
|
|
{
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $url_handlers = [
|
2017-03-02 03:24:38 +01:00
|
|
|
'fields/$FieldName' => 'handleField',
|
2019-02-23 13:05:18 +01:00
|
|
|
"POST /" => "handleSubmission",
|
|
|
|
"GET /" => "handleGet",
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2017-03-02 03:24:38 +01:00
|
|
|
|
|
|
|
// These are a different case from those in url_handlers to confirm that it's all case-insensitive
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $allowed_actions = [
|
2017-03-02 03:24:38 +01:00
|
|
|
'handlesubmission',
|
|
|
|
'handlefield',
|
|
|
|
'handleget',
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2017-03-02 03:24:38 +01:00
|
|
|
|
|
|
|
public function handleField($request)
|
|
|
|
{
|
|
|
|
return $this->form->Fields()->dataFieldByName($request->param('FieldName'));
|
|
|
|
}
|
|
|
|
|
2022-10-17 06:58:20 +02:00
|
|
|
public function handleSubmission(HTTPRequest $request): HTTPResponse
|
2017-03-02 03:24:38 +01:00
|
|
|
{
|
2022-10-17 06:58:20 +02:00
|
|
|
return HTTPResponse::create()->setBody("Form posted");
|
2017-03-02 03:24:38 +01:00
|
|
|
}
|
|
|
|
|
2022-10-17 06:58:20 +02:00
|
|
|
public function handleGet(HTTPRequest $request): HTTPResponse
|
2017-03-02 03:24:38 +01:00
|
|
|
{
|
2022-10-17 06:58:20 +02:00
|
|
|
return HTTPResponse::create()->setBody("Get request on form");
|
2017-03-02 03:24:38 +01:00
|
|
|
}
|
|
|
|
}
|