How to display data from an external database in Drupal?
I am creating a custom module that will allow my users to make a simple query against an MS SQL database. I created a form using hook_form () and got a confirmation to work.
I am planning on fetching data from hook_form_submit (), but once I have done that, how do I add it below the form? It doesn't look like I have access to $ output from hook_form_submit (). I don't know what to do next.
thanks
Dana
a source to share
The problem when trying to output data in the hook_form () method is that the method is called twice, which clears the post values a second time. Throw dpm ($ form_state) into the hook_form () function and you will see two datasets to post. One with meanings and one without.
So, after analyzing the built-in search module, which pretty much works exactly how I want my form to work, I figured out how to do it. Well, at least one way to do it.
Which lookup module takes the values from $ form_state to hook_form_submit () and injects them into the url, then it sets $ form_state ['redirect'] to this new url, effectively storing those variables in the url and changing the POST to GET ...
Now, in the callback, they fetch these values from the url, search them, THEN they call drupal_get_form (), add the results to the end, and return them.
There's another solution HERE where they use SESSION to store the values until the second pass. Strange, but it works.
a source to share
When rendering the form, you should check $ form_state ['values'] to see if the user has already submitted the form while rendering the form. Then you can draw the results of the shape in the same step as drawing the shape.
The first time the user loads the form page, the $ form_state variable will not contain the provided form information, so you can display an empty results table.
There's a nice illustration of the Drupal Form API workflow on Drupal.org here: The look and feel of the API API workflow
a source to share