From 649d2569abc10bac43e98ca98db474dd3d6603ca Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 21 Dec 2018 14:30:49 -0500 Subject: [PATCH] Bump version to 3.0.123 --- wire/core/ProcessWire.php | 2 +- wire/modules/Inputfield/InputfieldForm.module | 86 +++++++++++++++++++ .../InputfieldImage/InputfieldImage.scss | 1 + 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/wire/core/ProcessWire.php b/wire/core/ProcessWire.php index c427a566..7d56501c 100644 --- a/wire/core/ProcessWire.php +++ b/wire/core/ProcessWire.php @@ -44,7 +44,7 @@ class ProcessWire extends Wire { * Reversion revision number * */ - const versionRevision = 122; + const versionRevision = 123; /** * Version suffix string (when applicable) diff --git a/wire/modules/Inputfield/InputfieldForm.module b/wire/modules/Inputfield/InputfieldForm.module index d94d093b..25378529 100644 --- a/wire/modules/Inputfield/InputfieldForm.module +++ b/wire/modules/Inputfield/InputfieldForm.module @@ -127,6 +127,15 @@ class InputfieldForm extends InputfieldWrapper { } else { $tokenField = ''; } + + /* @todo 3.0.125 + $name = $this->getAttribute('name'); + if(!empty($name)) { + $name = $this->wire('sanitizer')->entities($name); + $class = $this->className(); + $tokenField .= ""; + } + */ $out = "
" . @@ -457,5 +466,82 @@ class InputfieldForm extends InputfieldWrapper { return $matches; } + /** + * Is this form submitted? + * + * This should only be called after the form has been completely built and submit buttons added to it. + * When using this option it is preferable (though not required) that your form has been given a name attribute. + * Optionally provide the name (or instance) of the submit button you want to check. + * + * - Returns boolean false if not submitted. + * - Returns boolean true if submitted, but submit button not known or not used. + * - Returns clicked/submitted InputfieldSubmit object instance when known and available. + * + * @param string|InputfieldSubmit $submitName Name of submit button or instance of InputfieldSubmit + * @return bool|InputfieldSubmit + * @todo 3.0.125 + * + public function isSubmitted($submitName = '') { + + $method = strtoupper($this->attr('method')); + $input = $this->wire('input'); + $submit = false; + $formName = $this->getAttribute('name'); + $submitNames = array(); + + // if the current request method is not the same as the forms, exit early + if(!$input->requestMethod($method)) return false; + + if(!empty($submitName)) { + // given a specific submit button to check + if($submitName instanceof InputfieldSubmit) { + $submitName = $submitName->attr('name'); + } + if(is_string($submitName)) { + $submitNames[] = $submitName; + } + } + + if(empty($submitNames)) { + // no specific submit button, so check all known submit button names + $submitNames = InputfieldSubmit::getSubmitNames(); + } + + if(!empty($formName)) { + // this form has a name attribute, so we can add that to our checks + $key = '_' . $this->className(); + $value = $method === 'GET' ? $input->get($key) : $input->post($key); + if($value !== $formName) { + // submitted form name does not match this form + return false; + } + // at this point we know this form as submitted + $submit = true; + } + + // find out which submit button was clicked if possible + foreach($submitNames as $name) { + $value = $method === 'GET' ? $input->get($name) : $input->post($name); + // if value not present in input for this submit button then skip it + if($value === null) continue; + // value was submitted for button name + $f = $this->getChildByName($name); + // if value submitted is not the same as value on the button, skip it + if(!$f || $f->val() !== $value) continue; + // we found our submit button + $submit = $f; + break; + } + + // if submitted and CSRF protection in place, check that token is valid + if($submit && $this->getSetting('protectCSRF') && $method === 'POST') { + $csrf = $this->wire('session')->CSRF(); + if(!$csrf->hasValidToken()) $submit = false; + } + + return $submit ? $submit : false; + } + */ + } diff --git a/wire/modules/Inputfield/InputfieldImage/InputfieldImage.scss b/wire/modules/Inputfield/InputfieldImage/InputfieldImage.scss index cbc8df12..edd04947 100755 --- a/wire/modules/Inputfield/InputfieldImage/InputfieldImage.scss +++ b/wire/modules/Inputfield/InputfieldImage/InputfieldImage.scss @@ -5,6 +5,7 @@ $gridMargin: 0 0.6em 0.6em 0; $itemPadding: 0.4em; $focusPointCircleSize: 40px; + .InputfieldImage { .InputfieldHeader { .InputfieldImageListToggle {