I'm developing a custom element for D6 FAPI (phone number, verified by SMS code), so I initially have a complex tree element with an input field and an ajax button to get the verification code.
I use this tutorial to make my button AHAH enabled "true way". Also I'd like to validate the phone at this step, so I have a function attached to textfield '#element_validate'. It works, and even more - if I enter wrong number, my textfield becomes red (having class 'error').
But the question is: how do I properly show the error message to user when the phone validation fails without page reload? And how can I prevent this message being displayed to user after page reload which will occur?


Jaypan’s picture

You'll need to return the messages (retrieved with drupal_get_messages()), and ideally the phone form element (otherwise it won't show as red), in your AHAH callback function. If returning the phone form element isn't particularly feasible, then you should make sure you at least return the messages in your ahah callback, as this will at least tell the user that they have a problem.

Checkout my Japan podcasts.
Victor Safronov’s picture

Solved by prepending output by theme('status_messages')