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)}

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 30 2025 00:47:22
Script start
Timing: Jan 30 2025 00:47:22
Module start 'layout'
Timing: Jan 30 2025 00:47:22
Module start 'content'
Timing: Jan 30 2025 00:47:23
Module end 'content'
Timing: Jan 30 2025 00:47:23
Script end

Main resources:

Total runtime1.2302 sec
Peak memory usage4,096.0000 KB
Database Queries65

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 588.2656151.2266
Module start 'layout' 0.00580.0026 739.492236.6875
Module start 'content' 0.00841.2209 776.1797563.3047
Module end 'content' 1.22930.0009 1,339.484415.8125
Script end 1.2302  1,355.2969 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00290.2372160.0002
Check MTime0.00120.1006160.0001
Mysql Total
Database connection0.00060.048810.0006
Mysqli_queries1.181096.0007650.0182
Looping result0.00060.0480630.0000
Template Total1.189796.720.5949
Template load0.00160.133220.0008
Template processing1.188196.574420.5940
Template load and register function0.00010.010210.0001
states
state_id_array0.00160.127310.0016
state_identifier_array0.00170.135020.0008
Override
Cache load0.00140.1165480.0000
Sytem overhead
Fetch class attribute can translate value0.00040.034930.0001
Fetch class attribute name0.00100.081370.0001
XML
Image XML parsing0.00280.226830.0009
class_abstraction
Instantiating content class attribute0.00000.001290.0000
General
dbfile0.00330.2719230.0001
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
9content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
5content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ol.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ol.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 36
 Number of unique templates used: 8

Time used to render debug report: 0.0001 secs