0

I've seen plenty of people ask a similar question but none of them are doing what I'm doing.

I have form function in my theme (mytheme_whatever_form()) with validation and submission handlers. I then put a placeholder in the body of a page like |my-placeholder| and a module I created there is a hook that parses the body of a node for anything with the pattern |whatever| and replaces hyphens with underscores and prefixes it with the theme name and executes that function if it exists (so it would execute mytheme_my_placeholder() from my example).

Inside mytheme_my_placeholder() I am rendering the output of mytheme_whatever_form() to place the form on my page.

When doing it this way I get the form on the page like I want and the validation and submission handlers work but no form_set_error or drupal_set_message calls return messages.

I can call whatever functions I want in the handlers and they execute as expected, except for anything that generates a status/error message.

This is very likely due to the way I'm loading the form but I can't find a good reason for it. form_set_error and drupal_set_message should both put a message into the system that is displayed via the page template and shouldn't care one bit what I'm doing with any other content on the page.

What am I overlooking and how can I get this to work?

14
  • Most likely the hook you're using is called too late for messages to be added. Inside which hook are you replacing the placeholders with the form? Also have you looked at custom text filters? See here
    – Beebee
    Jun 2, 2016 at 14:48
  • are you sure the form_set_error is being called? do you see the message in a dpm of $messages for example? if yes and you see the message in the dpm, then can try accessing and displaying the messages from inside the form instead of from the page, since the form is probably built/rebuilt after the page is created. Jun 2, 2016 at 14:55
  • @Beebee: hook_node_view()
    – Jason Gray
    Jun 2, 2016 at 15:14
  • @longboardnode: The validation function is being called and the conditional I wrapped around the form_set_error is validating to true. When I have the function die there it does. That leads me to believe that form_set_error is being executed. I would expect a WSoD if there was a problem with the function or a system log of the problem otherwise but I get neither. I also tried adding $form['#prefix'] .= theme('status_messages'); but still don't see messages.
    – Jason Gray
    Jun 2, 2016 at 15:20
  • hmmm weird! sounds like you're doing all the right things... can you try this: $form = drupal_get_form('your_form'); print theme('status_messages'); print drupal_render($form); and see if the messages display? Jun 2, 2016 at 20:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.