alternative for $this->action('xxx') ?

Permalink
Is there a alternative for
echo $this->action('xxx');

? I use this in the form action tag (block view). But the URL which is generated is not very nice.

Is there a way to post to the pretty-url and use the variables generated by "$this->action" in hidden fields or something like that?

Hope to hear from you soon.


Best wishes,

Marc

scalait
 
MadQuint replied on at Permalink Reply
unfortunately, it's a matter of editing two core files

First replace "&" to "&" in the action() method found in concrete/libraries/block_view.php. It should look like this:
public function action($task, $extraParams = null) {
         try {
            if (is_object($this->block)) {
               return $this->block->getBlockPassThruAction() . '&method=' . $task . $extraParams;
            }
         } catch(Exception $e) {}
      }


and second replace all "&" with "&" in the _getBlockAction() method (line 517) in concrete/models/block.php

Should look like this:
function _getBlockAction() {
         $cID = $this->getBlockCollectionID();
         $bID = $this->getBlockID();
         $arHandle = $this->getAreaHandle();
         $step = ($_REQUEST['step']) ? '&step=' . $_REQUEST['step'] : '';
         $valt = Loader::helper('validation/token');
         $token = $valt->generate();
         $str = DIR_REL . "/" . DISPATCHER_FILENAME . "?cID={$cID}&bID={$bID}&arHandle={$arHandle}" . $step . "&ccm_token=" . $token;
         return $str;
      }


cheers
Tony replied on at Permalink Reply
Tony
i sometimes just bypass action() completely since it doesn't work with hardcoded blocks, and instead use <?= View::url($c->getCollectionPath() )?> as the target. but then you have to manually add a token (lots of examples throughout the core), and have to get the block to know that the form submission is only intended for itself (by looking for a intval($bID) and perhaps a unique identifier for that block type, for when the block is hardcoded and there's no bID).
ScottC replied on at Permalink Reply
ScottC
Would posting to a php file that extends controller in the tools folder be something to consider? I have dual use forms, they can be brought up using facebox using a $.get, and they also exist and are mostly used in the dashboard, so having one unified place to post async or not to would be nice. So would using tools be a valid thing to do in your opinion?

Thanks,
Scott
jordanlev replied on at Permalink Reply
jordanlev
I understand that this is a subjective matter, but in my opinion I don't think that having ugly URL's on the page a form posts to is that bad, because the user rarely sees it.
When I was developing my own custom block/form, I was worried about this at first because after the form is submitted, it stays on that page with all of the ugly url cruft at the end, but I changed my controller code that responds to the form to redirect back to the original page upon successful completion of the form, so that the user would not see the ugly url (and this has the nice side-effect of not showing them the "Are you sure you want to post this data again" dialog in their browser if they hit refresh or the back button).
Note that in order to redirect back to the original page upon form completion, I had to put the original page's url in a hidden form field (because if the form is in a block, you never know what page it might be posted from because the user could put that block on any page in their site).

So now the only time the user sees the ugly url is if the form fails validation, but I considered this an acceptable trade-off (again, this is subjective so I understand if you don't even want that).

Hope that helps.

-Jordan