Skip to content

Commit c250df5

Browse files
committed
added Form::isMethod()
1 parent 247debf commit c250df5

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

src/Bridges/FormsLatte/Runtime.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static function renderFormBegin(Form $form, array $attrs, $withTags = TRU
3333
$el = $form->getElementPrototype();
3434
$el->action = (string) $el->action;
3535
$el = clone $el;
36-
if (strcasecmp($form->getMethod(), 'get') === 0) {
36+
if ($form->isMethod('get')) {
3737
$el->action = preg_replace('~\?[^#]*~', '', $el->action, 1);
3838
}
3939
$el->addAttributes($attrs);
@@ -48,7 +48,7 @@ public static function renderFormBegin(Form $form, array $attrs, $withTags = TRU
4848
public static function renderFormEnd(Form $form, $withTags = TRUE)
4949
{
5050
$s = '';
51-
if (strcasecmp($form->getMethod(), 'get') === 0) {
51+
if ($form->isMethod('get')) {
5252
foreach (preg_split('#[;&]#', parse_url($form->getElementPrototype()->action, PHP_URL_QUERY), NULL, PREG_SPLIT_NO_EMPTY) as $param) {
5353
$parts = explode('=', $param, 2);
5454
$name = urldecode($parts[0]);

src/Forms/Controls/UploadControl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct($label = NULL, $multiple = FALSE)
4444
protected function attached($form)
4545
{
4646
if ($form instanceof Nette\Forms\Form) {
47-
if ($form->getMethod() !== Nette\Forms\Form::POST) {
47+
if (!$form->isMethod('post')) {
4848
throw new Nette\InvalidStateException('File upload requires method POST.');
4949
}
5050
$form->getElementPrototype()->enctype = 'multipart/form-data';

src/Forms/Form.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ public function getMethod()
209209
}
210210

211211

212+
/**
213+
* Checks if the request method is the given one.
214+
* @param string
215+
* @return bool
216+
*/
217+
public function isMethod($method)
218+
{
219+
return strcasecmp($this->getElementPrototype()->method, $method) === 0;
220+
}
221+
222+
212223
/**
213224
* Cross-Site Request Forgery (CSRF) form protection.
214225
* @param string
@@ -473,7 +484,7 @@ public function validate(array $controls = NULL)
473484
/** @internal */
474485
public function validateMaxPostSize()
475486
{
476-
if (!$this->submittedBy || strcasecmp($this->getMethod(), 'POST') || empty($_SERVER['CONTENT_LENGTH'])) {
487+
if (!$this->submittedBy || !$this->isMethod('post') || empty($_SERVER['CONTENT_LENGTH'])) {
477488
return;
478489
}
479490
$maxSize = ini_get('post_max_size');

src/Forms/Rendering/DefaultFormRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function renderBegin()
163163
$control->setOption('rendered', FALSE);
164164
}
165165

166-
if (strcasecmp($this->form->getMethod(), 'get') === 0) {
166+
if ($this->form->isMethod('get')) {
167167
$el = clone $this->form->getElementPrototype();
168168
$query = parse_url($el->action, PHP_URL_QUERY);
169169
$el->action = str_replace("?$query", '', $el->action);

0 commit comments

Comments
 (0)