0

How is it possible to detect if the page, in which the form is, is refreshed and to detect if only the form is refreshed?

I tell you the whole thing: I'm building a module. The form in this module has ajax-ed elements. When the form is first loaded (or when the page containing the form is refreshed) a database query is executed (filling up the form), that is the thing i want. But when an ajax-ed element is triggered the query is executed again, and i don't want that.

How is it possible to stop the execution of this query when an ajax callback is executed?
The form is in an .inc file and called by the .module file via drupal_get_form().

1 Answer 1

1

You can use $form_state['triggering_element'] to find out if and by which element a form was submitted.

That said, I am not sure if what you want to do is possible. When rebuilding the form, you will have to provide all valid form elements and options for them again.

If that query is slow, you might be able to use the caching system instead (That is, unless these options are personalized for the current user).

But maybe I didn't exactly get what you meant, so try it..

1
  • I don't think it is possible too! When a form is requested or called-back the whole form is rebuilt passing over all hooks functions ... But there's nothing impossible in programming in my opinion, so I'll keep trying. If you find anything related, please share :)
    – Peter
    May 29, 2011 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.