Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
1.4k views
in Plugins by
http://docs.question2answer.org/plugins/modules-event/

I am catching the event u_save and check the posted data.

If there is a wrong value, I want to show an error front end, but I could not find out yet, where to define the error. Seems that I cannot use: $event, $userid, $handle, $cookieid, $params
Q2A version: 1.8.0

1 Answer

0 votes
by
selected by
 
Best answer

That's because the event module is just a listener of something that happened. It can't get in the middle of the core's processing. For that to happen, you should use a filter module. Most precisely, implementing the filter_profile() function.

by
However, with a layer I added another profile field, which I was catching with the event module using qa_post_text('myfield'); which does not seem to work with filter_profile() anymore. –– Testing qa_db_usermeta_set($userid, 'customentry', $profile['myfield']); throws a mysql error.
by
The thing is that if you add a field in the layer, then it is not really a profile field, so it makes sense for the filter not to see it. You could catch the request in the layer and update the content array as necessary, performing any custom validation
by
Seems that I cannot use qa_post_text() in the layer to catch the posted field. Always NULL. With $this->request I only get 'account' but not the post state.
by
I can confirm qa_post_text() works in the layer. Make sure you are actually posting the value. $this->request is just the path of the URL and what you need is the content of the HTTP request, so it will not help you
by
Mhh, for me the layer dumps NULL. Example:

    public function header()
    {
        $myfield = qa_post_text('myfield');
        var_dump($myfield); // NULL

        // default
        qa_html_theme_base::header();
    }

I am posting from the /account page.
by
Try in a different method. Most likely, your theme or another layer is overriding that method and not calling the parent
by
I have already tried yesterday: initialize(), header(), head(), doctype() - it does definitely not work. The dump always shows NULL. – Same goes for the other form fields, I tried to get "email" for instance, it dumps NULL.

I also tried on the production server, just to be sure it's not a problem with localhost.
I removed all other plugins, same.
by
Got it. Not your problem, definitely. After taking a look at the account page, I noticed there is a REDIRECT for the 'profile-saved' that turns the POST into a GET and loses the request body with the POST params.

You need to take action before the redirect. What about using the filter_profile and access the POST elements from there?
by
With the filter_profile() I may access the POST but I cannot create the error message. That's why we need the layer. – The entire thing seems complicated now :)
...