Forums / Developer / How to send POST parameters into another module?

How to send POST parameters into another module?

Author Message

Karol Radziuk

Tuesday 30 November 2010 7:00:25 am

Hi

After reading some posts, I couldn't find satisfactory solution. I have a form:

<form method="post" action={"myModule/action"|ezurl}>

and if there is some ill-filled box, my extension should send back (POST) error message, and correctly entered data, that the user does not have to enter them again.

To achieve this goal, I tried:

  1. return $Module->redirect( 'content', 'view', array( 'full', 59 ), null, $params );
    But there will be to many view parameters. I don't want any.
  2. $http->setPostVariable( 'errormessages', $errormessages );<span class="short_text"><span>
    </span></span>return $Module->redirect( 'content', 'view', array( 'full', 59 ) );
    It doesn't work. Why?
  3. $tpl->setVariable( 'errormessages', $errormessages );
    return $Module->redirect( 'content', 'view', array( 'full', 59 ) );
    It also does not work
  4. $http->setSessionVariable( 'errormessages', $errormessages );
    return $Module->redirect( 'content', 'view', array( 'full', 59 ) );
    It works, but there is big problem with cache (with ezhttp() template operator I must allways clear the cache), and secondly I must disable this variable after use. Please help me, how to do it cleverly?
  5. include('HTTP/Request.php');
    $req = &new HTTP_Request('/content/view/full/59');
    $req->setMethod(HTTP_REQUEST_METHOD_POST);
    $req->addPostData('errormessages', '$errormessages');
    $req->sendRequest();
    $response1 = $req->getResponseBody();
    echo($response1);
    Also in this case I can not manage the cache (clearing is still needed)

I believe that the transmission parameters message in the eZ is welcome. Why you have not created such a possibility? Security risk?

And please help, some idea...

{$me|attribute(show,1)}

Jérôme Vieilledent

Tuesday 30 November 2010 7:58:12 am

Hi Karol

Why do you want to send your user to another module ? The best approach would be to handle your form validation in the first one, and if all data is valid, then do redirect, wouldn't it ?

Marco Rogers

Tuesday 30 November 2010 2:47:30 pm

This is a problem we run into sometimes with our client builds. You can't easily do custom validation on POSTs from content pages. What we've done is the following:

Instead of submitting the form to your module, resubmit to the same content page.

Setup a custom template operator that you call at the top of the page with the form. The code behind the operator will check if it's a form POST, do your validation and return any errors. If the validation is successful, you can redirect from there: return $Module->redirect(...)

Or, you can set up client-side javascript validation. If it's not too complex and you don't need any server-side data. Then when the form is submitted you can be reasonably sure you won't need to reject it. You should probably do this in addition to your server-side validation.

Finally, instead of trying to redirect back to the content page, you will need your module to be able to re-display the form in the case where the submission is rejected. If your form is in a separate template include, you can re-use it and pass in the same validation error data that you did with the template operator.

Hope this makes sense.

:Marco

Karol Radziuk

Wednesday 01 December 2010 12:30:41 am

Thank you both, you are very helpful. These methods are new for me and this morning, with a fresh mind I will certainly try it.

Regards.

{$me|attribute(show,1)}

Karol Radziuk

Wednesday 01 December 2010 6:14:38 am

I created new template operator, like Marco said. But I am still struggling with cache.

{def $validation_result = entry_validator()}

In this variable I have error info. I read about:

<span class="line">CachedViewPreferences[full]=mysetting;</span>

But I don't understand how to apply it, that this one variable is not cached?

I guess:

{set-block scope=global variable=cache_ttl}0{/set-block}

is not best idea...

{$me|attribute(show,1)}

eZ debug

Timing: Jan 29 2025 13:37:56
Script start
Timing: Jan 29 2025 13:37:56
Module start 'content'
Timing: Jan 29 2025 13:37:56
Module end 'content'
Timing: Jan 29 2025 13:37:56
Script end

Main resources:

Total runtime0.1564 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0064 588.0625180.8203
Module start 'content' 0.00640.0061 768.8828102.1641
Module end 'content' 0.01250.1438 871.0469532.3594
Script end 0.1563  1,403.4063 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00332.1398200.0002
Check MTime0.00130.8055200.0001
Mysql Total
Database connection0.00080.524310.0008
Mysqli_queries0.111871.48931410.0008
Looping result0.00110.71811390.0000
Template Total0.143491.710.1434
Template load0.00080.509710.0008
Template processing0.142691.183310.1426
Override
Cache load0.00050.334410.0005
Sytem overhead
Fetch class attribute can translate value0.00050.300510.0005
XML
Image XML parsing0.00030.163810.0003
General
dbfile0.00613.8935200.0003
String conversion0.00000.005030.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs