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

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

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