Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By haroon373 on
I am a newbie in drupal module development. I created a form using form api. Now i want to get all the posted argument and query database with these arguments. And at last i want to show query results.
Please guide me how can i do this
Many thanks in advance
Comments
You mean once you have filled
You mean
once you have filled your field and send them to server with submit button, you want to "view" your content?
If yes then take a look at hook_load, who is responsible to load the content of your nodes, and maybe hook_view to render your node on your own way or use a template file.
neil.sonaron
Thank you very much neil.sonaron for considering my question.
But i am at the very beginning stage where i can't understand typical terms.
Let me explain more of my question.
I created a custom module for custom advance search. this search will work for specific content type.
My cutom module using these functions.
1. advsearch_menu() // to link my module
2. advsearch_page() // to display form on page.
3. advsearch_form() //to create the form
4. advsearch_form_validate($form, &$form_state) // validating form
5. advsearch_form_submit($form, &$form_state) //submit form
I just walk through a tutorial to do this.
After this, i want to query the database with all arguments posted by form, and at last display the result of the query in tables or whatever.
now please tell me what function will do this for me...?
Is there any need to create new custom module to show the data?
or i can show data in my same current custom module and wipe out (hide) the form.
Just like in conventional php programming
I hope I succeeded to explain my question...
Please take a look again.
haroon373, did you ever get
Did you ever get an answer to your question? If so, please post.
The structure for form
The structure for form genaration function is:
The name of the function is to be passed on drupal_get_form() function (e.g. drupal_get_form('mymodule_form') ).
$form_state is an array where the key 'post' contains the array of post values.
Example:
I'm having some problems with this!
I'm having some problems with this.
Please review my code and explain how to output results back to the page.
Its a single text field which searches through a table and returns a single result (Or that's what I would like it to do).
The form displays and it looks like its submitting but is not firing the submit function
Similar Newbie Situatoin
On the bright side (for me) its nice to know I'm not the only one having issues displaying results from a form submission.
In my case, the _submit function definitely runs... if I do a "print $output;" from there it prints the string to a blank page with my correct query results. My code is very similar to IS_NUMERIC's.
If I just leave it "return $output;" it ignores it and re-displays my original form.
I was expecting it to print the $output string (built successfully using the query results) in the main content block like the form does (basically replacing the form with the output string)... but it doesn't. Pretty sure I'm missing something very basic.
Any suggestions would be really appreciated.
===================
Edited to add:
I have some success using joeycbulk's method above doing the query processing in the hook_form function rather than hook_submit but it looks like $form_state['values'] isn't available in the _form hook function?? but $form_state['post'] is. Shouldn't I be able to return data from the hook_submit function where $form_state['values'] *is* available... Pretty much like IS_NUMERIC is trying to do?
The form builder type "value" (for other newbies thats sort of like a hidden field but not rendered to the form) isn't being passed in $form_state['post'] and I'd really like to use it like I can with $form_state['values'] in the _submit function.
Any suggestions would still be really appreciated. ;)
Sample Module with Report Page
Hi,
I have a simple "proof of concept" module located here. It's a simple module that demonstrates an add form, validation and submit handlers, and a report page.
The user submits the add form, if valid , the system displays the report page (which includes the newly added value).
Thank you lorinpda
Thanks for the link and the time/comments. What you are doing makes perfect sense.
What I was hoping to do... what I expected I'd be able to do is use the submit function (or a call to another function from _submit) to produce the report... rather than redirect to another page. I'll do the redirect if that's what is necessary but it seems that I should be able to get that $output string back into the _form function (into $form['result'] or something)... no? Hmmm.... Or maybe the callback function that calls drupal_get_form since drupal_get_form looks like it resets some values (like "submitted").... I'll have to play with that.
It seems to me that this would be a more common topic. ;) Also, I found this --> http://www.lullabot.com/articles/drupal-5-making-forms-that-display-thei... (for D5) but that's still driving the work from _form.
I'm sure in the end I'll be doing it the way you suggest. ;) Thanks again!
Edited to add:
This method -> http://www.ferolen.com/blog/how-to-create-multistep-form-in-drupal-6-tut... leads me to what I wanted to do but in the "else" statement of _myform I assigned $form['result'] to "$form_state['storage']['results']" where I dumped $output to in the _submit function. Hope this helps anyone else traveling this road or at least doesn't lead them further astray!
Something like this:
Do you simply want to display a form under a list report?
Hi,
Often, an "Add New" form or link is displayed above or below a list report. Is that what you are trying to do? All you do is append lorinpda's listing so that the last line looks something like:
return theme_table($header, $rows).'<br/>'.drupal_get_form("YOUR_FORM_ID");
List from form
Hi...
no... what I wanted was to show the form (for search selections) then on submit display the search results without redirecting. I figured that is what the _submit hook should be for. ;)
Anyway, I'm happy with it and have made significant progress past that point, including result pagination with pager_query and theme(pager). Go me! lol (what a newbie...sheesh... lol)
quiet, thank you for your
quiet, thank you for your code.
I just think that here is a little mistake:
It is:
if (empty($form_state['storage']['values'])) {
It must be:
if (empty($form_state['storage']['results'])) {
Still dont get it
I am completely stuck with this. I expect to be able to build and display a page within my _submit callback.
My code is similar to yours, but still I dont get any output where I expect to get it
Any help please?
function nounousearch_submit(&$form, &$form_state) {
if (empty($form_state['storage']['values']['canton'] )) {
// if there is no previous values redraw for second step
$nounoustage = "First stage" ;
$form_state['storage']['values'] = $form_state['values'];
// Trying several things here , it doesnt make a difference
// $form_state['rebuild'] = true;
} else {
$nounoustage = "Second stage" ;
// Form is on the second step, process the data here…
$form_state['storage']['values'] = $form_state['values'];
$nounoutype = $form_state['storage']['values'][‘nounoutype’];
$canton = $form_state['storage']['values'][‘canton’];
$commune =$form_state['storage']['values'][‘commune’];
$output = nounou_showresults( $type, $canton, $commune ) ;
// >>>> Doing the same as "quit" in http://drupal.org/comment/reply/542646/3149380#comment-3149380
// >>>> But nothing is displayed
$form_state['storage']['results'] = $output ;
}
drupal_set_message(t($nounoustage));
// This shows the results the way I want "before" the page is built, outside of the template
// just to confirm that $output contains what I want
print $output ;
return ;
}
Submit functions do not
Submit functions do not provide a means for display of data. You can return data, but it will not be printed to the screen. If you want to print data from your submit function to the screen, store it in $form_state['storage'], set the form to be rebuilt, and then print it in your form definition.
no db transaction
How is this accomplished without a db transaction? I can't seem to be able to pass $form_state into any other function.
Since your form function is
Since your form function is 'engineers_formfields', you should use 'engineers_formfields_submit' for the name of the submit function.
did you get the form to load..?
Hey am trying something similar and used the example given by you but the results would simply not load. Not sure why ? looks like I might be missing something simple here.
Please let me know if your example worked for the search?
Thanks
Srinidhi