Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc5034e6

Browse files
committed
[Form] add 'force_submit' option
closes#16491.Add a `force_submit` option to BaseType with default false,to submit the form even if its name is not among submitteddata keys in request handlers.
1 parent6fb9fee commitc5034e6

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

‎src/Symfony/Component/Form/Extension/Core/Type/FormType.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ public function configureOptions(OptionsResolver $resolver)
172172
'action' =>'',
173173
'attr' =>array(),
174174
'post_max_size_message' =>'The uploaded file was too large. Please try to upload a smaller file.',
175+
// Allow submission in request handlers if the form name does not belong
176+
// to submitted data key, see https://github.com/symfony/symfony/issues/16491
177+
'force_submit' =>false,
175178
));
176179

177180
$resolver->setAllowedTypes('label_attr','array');

‎src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function handleRequest(FormInterface $form, $request = null)
5858
// For request methods that must not have a request body we fetch data
5959
// from the query string. Otherwise we look for data in the request body.
6060
if ('GET' ===$method ||'HEAD' ===$method ||'TRACE' ===$method) {
61-
if ('' ===$name) {
61+
if ('' ===$name ||$form->getConfig()->getOption('force_submit')) {
6262
$data =$request->query->all();
6363
}else {
6464
// Don't submit GET requests if the form's name does not exist
@@ -89,7 +89,7 @@ public function handleRequest(FormInterface $form, $request = null)
8989
return;
9090
}
9191

92-
if ('' ===$name) {
92+
if ('' ===$name ||$form->getConfig()->getOption('force_submit')) {
9393
$params =$request->request->all();
9494
$files =$request->files->all();
9595
}elseif ($request->request->has($name) ||$request->files->has($name)) {

‎src/Symfony/Component/Form/NativeRequestHandler.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function handleRequest(FormInterface $form, $request = null)
6666
// For request methods that must not have a request body we fetch data
6767
// from the query string. Otherwise we look for data in the request body.
6868
if ('GET' ===$method ||'HEAD' ===$method ||'TRACE' ===$method) {
69-
if ('' ===$name) {
69+
if ('' ===$name ||$form->getConfig()->getOption('force_submit')) {
7070
$data =$_GET;
7171
}else {
7272
// Don't submit GET requests if the form's name does not exist
@@ -102,7 +102,7 @@ public function handleRequest(FormInterface $form, $request = null)
102102
$fixedFiles[$fileKey] =self::stripEmptyFiles(self::fixPhpFilesArray($file));
103103
}
104104

105-
if ('' ===$name) {
105+
if ('' ===$name ||$form->getConfig()->getOption('force_submit')) {
106106
$params =$_POST;
107107
$files =$fixedFiles;
108108
}elseif (array_key_exists($name,$_POST) ||array_key_exists($name,$fixedFiles)) {

‎src/Symfony/Component/Form/Tests/AbstractRequestHandlerTest.php‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ public function testDoNoSubmitSimpleFormIfNameNotInRequestAndNotGetRequest($meth
117117
$this->requestHandler->handleRequest($form,$this->request);
118118
}
119119

120+
/**
121+
* @dataProvider methodProvider
122+
*/
123+
publicfunctiontestForceSubmitSimpleFormIfNameNotInGetRequest($method)
124+
{
125+
$form =$this->getMockForm('param1',$method,false,true);
126+
127+
$submittedData =array('test');
128+
129+
$this->setRequestData($method,$submittedData);
130+
131+
$form->expects($this->once())
132+
->method('submit')
133+
->with($submittedData);
134+
135+
$this->requestHandler->handleRequest($form,$this->request);
136+
}
137+
120138
/**
121139
* @dataProvider methodExceptGetProvider
122140
*/
@@ -361,7 +379,7 @@ abstract protected function getRequestHandler();
361379

362380
abstractprotectedfunctiongetMockFile($suffix ='');
363381

364-
protectedfunctiongetMockForm($name,$method =null,$compound =true)
382+
protectedfunctiongetMockForm($name,$method =null,$compound =true,$forceSubmit =false)
365383
{
366384
$config =$this->getMock('Symfony\Component\Form\FormConfigInterface');
367385
$config->expects($this->any())
@@ -370,6 +388,10 @@ protected function getMockForm($name, $method = null, $compound = true)
370388
$config->expects($this->any())
371389
->method('getCompound')
372390
->will($this->returnValue($compound));
391+
$config->expects($this->any())
392+
->method('getOption')
393+
->with('force_submit')
394+
->will($this->returnValue($forceSubmit));
373395

374396
$form =$this->getMock('Symfony\Component\Form\Test\FormInterface');
375397
$form->expects($this->any())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp