Tuesday 30 November 2010 4:00:25 pm - 4 replies
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:
return $Module->redirect( 'content', 'view', array( 'full', 59 ), null, $params );But there will be to many view parameters. I don't want any.
$http->setPostVariable( 'errormessages', $errormessages );<span class="short_text"><span> </span></span>return $Module->redirect( 'content', 'view', array( 'full', 59 ) );It doesn't work. Why?
$tpl->setVariable( 'errormessages', $errormessages ); return $Module->redirect( 'content', 'view', array( 'full', 59 ) );It also does not work
$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?
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...
Tuesday 30 November 2010 11: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
Modified on Wednesday 01 December 2010 8:48:14 pm by Marco Rogers
Wednesday 01 December 2010 3:14:38 pm
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...
You must be logged in to post messages in this topic!