Commit 86f38d7f1179a2924ce9ab5fa8bd1c8da92b99da
1 parent
b90eb89c
Don't hard-code "action" as the event variable in forms. Inherit it
from the dispatcher, if given. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5868 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
20 additions
and
7 deletions
lib/dispatcher.inc.php
| ... | ... | @@ -56,6 +56,10 @@ class KTDispatcher { |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | function redispatch($event_var, $action_prefix = null) { |
| 59 | + $previous_event = KTUtil::arrayGet($_REQUEST, $this->event_var); | |
| 60 | + if ($previous_event) { | |
| 61 | + $this->persistParams(array($this->event_var)); | |
| 62 | + } | |
| 59 | 63 | $this->event_var = $event_var; |
| 60 | 64 | if ($action_prefix) { |
| 61 | 65 | $this->action_prefix = $action_prefix; |
| ... | ... | @@ -212,12 +216,11 @@ class KTDispatcher { |
| 212 | 216 | // handle the case where action is passed in already. |
| 213 | 217 | } |
| 214 | 218 | } |
| 215 | - | |
| 216 | - | |
| 217 | 219 | // if it isn't already set |
| 218 | - if ((!array_key_exists('action', $aQuery)) && (!empty($event))) { | |
| 219 | - $aQuery['action'] = urlencode($event); | |
| 220 | + if ((!array_key_exists($this->event_var, $aQuery)) && (!empty($event))) { | |
| 221 | + $aQuery[$this->event_var] = urlencode($event); | |
| 220 | 222 | } |
| 223 | + var_dump($aQuery); | |
| 221 | 224 | |
| 222 | 225 | if ($asArray) { |
| 223 | 226 | return $aQuery; | ... | ... |
lib/widgets/forms.inc.php
| ... | ... | @@ -21,6 +21,7 @@ class KTForm { |
| 21 | 21 | var $_validators; // validators |
| 22 | 22 | var $_submitlabel; // what is the "submit" button called |
| 23 | 23 | var $_action; // where does the success message go |
| 24 | + var $_event; // where does the success message go | |
| 24 | 25 | var $_extraargs; // various extra arguments |
| 25 | 26 | var $_failaction; // should this error out, which action handles it |
| 26 | 27 | var $_failurl; // if we don't have a failaction, try this url |
| ... | ... | @@ -66,6 +67,15 @@ class KTForm { |
| 66 | 67 | $this->_failurl = KTUtil::arrayGet($aOptions, 'fail_url'); |
| 67 | 68 | $this->_submitlabel = KTUtil::arrayGet($aOptions, 'submit_label', |
| 68 | 69 | _kt('Submit')); |
| 70 | + | |
| 71 | + $this->_event = KTUtil::arrayGet($aOptions, 'event'); | |
| 72 | + if (empty($this->_event)) { | |
| 73 | + if (!is_null($context)) { | |
| 74 | + $this->_event = $context->event_var; | |
| 75 | + } else { | |
| 76 | + $this->_event = "action"; | |
| 77 | + } | |
| 78 | + } | |
| 69 | 79 | |
| 70 | 80 | // cancel |
| 71 | 81 | // there are a few options here: |
| ... | ... | @@ -86,7 +96,7 @@ class KTForm { |
| 86 | 96 | } else { |
| 87 | 97 | // give it a try using addQSSelf |
| 88 | 98 | $this->_cancelurl = KTUtil::addQueryStringSelf( |
| 89 | - sprintf('action=%s', $cancel_action)); | |
| 99 | + sprintf('%s=%s', $this->_event, $cancel_action)); | |
| 90 | 100 | } |
| 91 | 101 | |
| 92 | 102 | |
| ... | ... | @@ -275,7 +285,7 @@ class KTForm { |
| 275 | 285 | |
| 276 | 286 | // remove inner "action" var from extraargs |
| 277 | 287 | // if its there at all. |
| 278 | - unset($this->_extraargs['action']); | |
| 288 | + unset($this->_extraargs[$this->_event]); | |
| 279 | 289 | $this->_extraargs['_kt_form_name'] = $this->_kt_form_name; |
| 280 | 290 | |
| 281 | 291 | // now do the render. | ... | ... |
templates/ktcore/forms/outerform.smarty
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | {if !empty($context->sDescription)}<p class="descriptiveText">{$context->sDescription}</p>{/if} |
| 6 | 6 | |
| 7 | 7 | {* hidden, "extra" args *} |
| 8 | - <input type="hidden" name="action" value="{$context->_action}"> | |
| 8 | + <input type="hidden" name="{$context->_event}" value="{$context->_action}"> | |
| 9 | 9 | {foreach from=$context->_extraargs item=v key=k} |
| 10 | 10 | <input type="hidden" name="{$k}" value="{$v}"> |
| 11 | 11 | {/foreach} | ... | ... |