Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 44ba55a

Browse files
committedOct 12, 2023
add Form with empty POST test
1 parent 90c804f commit 44ba55a

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed
 

‎demos/_unit-test/form-empty.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Atk4\Ui\Demos;
6+
7+
use Atk4\Ui\Form;
8+
use Atk4\Ui\Js\JsToast;
9+
10+
/** @var \Atk4\Ui\App $app */
11+
require_once __DIR__ . '/../init-app.php';
12+
13+
$form = Form::addTo($app);
14+
15+
$form->onSubmit(static function (Form $form) {
16+
return new JsToast('Post ' . ($form->getApp()->getRequest()->getParsedBody() === [] ? 'ok' : 'unexpected'));
17+
});

‎src/Form.php

+1
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ public function setupAjaxSubmit(): void
521521
'on' => 'submit',
522522
'url' => $this->cb->getJsUrl(),
523523
'method' => 'POST',
524+
'contentType' => 'application/x-www-form-urlencoded; charset=UTF-8', // remove once https://github.com/jquery/jquery/issues/5346 is fixed
524525
'serializeForm' => true,
525526
], $this->apiConfig));
526527

‎tests-behat/form.feature

+5
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,8 @@ Feature: Form
8484
When I click using selector "//label[text()='I am a developer']"
8585
Then I should not see "Check all language that apply"
8686
Then I should not see "Css"
87+
88+
Scenario: empty POST
89+
Given I am on "_unit-test/form-empty.php"
90+
When I press button "Save"
91+
Then Toast display should contain text "Post ok"

0 commit comments

Comments
 (0)