By selimoezkan on
Hi all,
I am new to Drupal module development. What I am searching for, is a way,
to output my form submission results.
Of course I could manage with for example:
function form_example_submissions() {
drupal_set_message($form_state['values']['mytext']);
}
But I want to have an output I can theme. Is there a tutorial or
specific example on the drupal.org website? Couldn't
find something understandable when I looked at the
theme()-function.
Any help is greatly appreciated!
Thank you
Best wishes
Soezkan
Comments
What do you want the workflow
What do you want the workflow to be?
Contact me to contract me for D7 -> D10/11 migrations.
Thanks for the reply.
Thanks for the reply.
I want to do something like, the way it can be done with simple HTML and PHP.
But I want the output to be placed in a themed way.
Supposing my file is called myscript.php - it has a form
that sends the results to itself like this:
How can I do that with my drupal 7 module?
Many thanks.
Best wishes
Soezkan
What do you want the workflow
What do you want the workflow to be?
Edit: Workflow means, what page should the user start on? Where should they go when the form has been submitted? Any more details that follow that.
Contact me to contract me for D7 -> D10/11 migrations.
1. Page: User enters values
1. Page: User enters birthday (numbers in three input fields for example)
2. Submit
3. Calculations, save to database or similiar, and Output of the results (other than with drupal_set_message).
That's it.
Example:
Thanks for your help!
Do you want the form to be
Do you want the form to be visible with the themed results? And do you need to be able to link to the results page? The method changes according to your answers.
Contact me to contract me for D7 -> D10/11 migrations.
Hello Jaypan,
Hello Jaypan,
yes, it would be great to have such a way for doing this.
And it would also help me alot, if I knew the other way of doing so:
namely submitting the form, and getting the results on the result page
without the form.
Many thanks for your help.
Best wishes
Soezkan
Ok, here's a simple example:
Ok, here's a simple example:
Contact me to contract me for D7 -> D10/11 migrations.
Thank you very much.
Thank you very much.
Please allow me one more question.
You write:
function some_form() ist defined twice - is this a typo or the two versions of handling the results?
Many thanks!
Best wishes
Soezkan
Sorry, that was a typo. I've
Sorry, that was a typo. I've edited the code to fix it.
Contact me to contract me for D7 -> D10/11 migrations.
Hi Jaypan,
Hi Jaypan,
I don't understand the code. As it is not an example one can copy paste and try out
I tried with my small knowledge about module development, but failed :(
After trying to add hook_menu() withj an appropriate link (i.e. "some-form")
I get the form, but when I submit something nothing happens.
Very hard to understand for me.
Thank you.
Best wishes
Soezkan
What does your code look like
What does your code look like?
Contact me to contract me for D7 -> D10/11 migrations.
Hi Jaypan,
Hi Jaypan,
this is my module:
The results are printed out with $_POST['myowntext'] on the very top of the page, are not themed and even outside the HTML-Body.
My question: How can I place the $_POST['myowntext'] right below
the submitbutton of my form after submitting.
Many thanks
Soezkan
Well, you're getting close.
Well, you're getting close.
Note that in Drupal, we don't use $_POST data, as it is unsanitized, and therefore dangerous. The sanitized form values are stored in $form_state['values'], and these are what you should use. You can then store data in $form_state['storage'], and if you set $form_state['rebuild'] to TRUE, the values you saved in $form_state['storage'] will be available in your form definition:
Contact me to contract me for D7 -> D10/11 migrations.
Great - thank you!
Great - thank you!
Soezkan
Two other options could be:
Two other options could be:
placing the results above the form - this is something I think I will manage.
But what, if I want to output the results on a, let's call it "result page", without
showing the form?
Thank you.
Best wishes
Soezkan
First, I just noticed this:<
First, I just noticed this:
The above is incorrect. This is not a hook, and hook_form(), which existed in D6 (but not D7) was different. This is simply a form definition.
Anyways, regarding your second question, you can do this:
Contact me to contract me for D7 -> D10/11 migrations.
Many thanks for all your good
Many thanks for all your good advices.
Best wishes
Soezkan
Did alot of work on module
Did alot of work on module development so far.
I always output the results of my form submissions below the form, and automatically collapse it after submit with $form['myform']['#collapsed'] = TRUE;
The following code I use in my mymodule_form in order to search for firstname and lastname in my database:
My problem:
if I use the pager links, the results got lost, since the module (and hence the form) will be loaded again, without submission.How can I handle this with submission?
Many thanks for help!
Best wishes
Soezkan
In this case, you have to do
In this case, you have to do things differently. I actually just explained it in a different thread the other day, so please read through my explanations there: https://drupal.org/node/2183643
Contact me to contract me for D7 -> D10/11 migrations.
Thanks. I looked at your
Thanks. I looked at your other thread and I think I almost made it.
The only thing I don't know is how I could place my $searchterm
within the pager links. If I'd make that, I could pass the original
$searchterm to provide in mymodule_form($form, &$form_state)
and use it for the SQL-query.
Any idea?
I believe you'll have to
I believe you'll have to override theme_pager() to do that.
Contact me to contract me for D7 -> D10/11 migrations.
Thanks so far.
Thanks so far.
I output my search results with:
The easiest thing would be to append the last part of the call with $searchterm like this:
Where (what file) do I do the theme_pager()-override you suggest? And, what is it? I mean: how can I do such an override?
Many many thanks for more help on this!
Best wishes
Soezkan
An override means you take
An override means you take the original function, copy it to template.php in your theme folder, and make your edits there.
If your theme is named 'ninja', then you would copy theme_pager() to template.php in the ninja folder, and rename it to ninja_pager(). Then, you would check to see if $_GET['whatever'] is set, and add that to all the links if it is.
This is how you override theme functions.
But before you do that, are you accessing the form at a page (path) or in a block?
Contact me to contract me for D7 -> D10/11 migrations.
Thanks Jaypan! I will try
Hello Jaypan,
I will try this out later.
The form access takes place at a page.
Would it be much different with blocks?
When I do that as you suggested, could I then perform this call:
??
Many thanks!
Soezkan
If it's on a page, you don't
If it's on a page, you don't need to use $_GET queries. See my first example on that page I linked to. You will append your value onto the path.
So if the path to your form is /path/to/form and the selected value is 'ninja', you would redirect the user to /path/to/form/ninja
Your links should automatically pick this up, and you don't need to override theme_pager().
Contact me to contract me for D7 -> D10/11 migrations.
Hi Jaypan,
Hi Jaypan,
wow, so many ways to handle form submissions. Always good to
choose the shortest path to the solution. It works fine with your
suggestion!
I resolved it with exploding the $_GET['q'] by '/' and took the last
record of the array [2] to use it for my db-query-pager in my
mymodule_form().
Many thanks for your help.
Best wishes
Soezkan
Thanks
Thanks you saved my a lot of time...
@jaypan how would you use
@jaypan how would you use form storage if you have more than one value in your form, say you had field myowntext1,myowntext2 and myowntext3 ?
So nice example. correcting one TYPO.
Jaypan, Thank you for this example.
$form['#value']replaced with$element['#value'].Pushpinder Rana #pushpinderdrupal
Acquia Certified Drupal Expert
Thanks, I've gone in an
Thanks, I've gone in an edited the original code to fix the typo.
Contact me to contract me for D7 -> D10/11 migrations.
What about a file template?
Hi Jaypan,
if I define the block containing the results in a template on the file system in this way:
How can I change this code:
so that I can pass the arrays:
to the viewlogresults.tpl.php page?
Now I can see this template after the submission of the form, but the arrays variables['headers'] and variables['results'] are empty.
What is the difference between the "#value" variable and "variables" ?
Thank you very much
cld
I've solved in this way and
I've solved in this way and works:
During the form creation:
hi guys
Hi guys,
based on this solution is it possible to make something like this: (click to start)
http://www.reisswolf.net/services/physical-rms/reisswolf-abc/
User inputs 4 numbers and then get the results
So, can I make something like this based on your solution?
For Any Googlers
I wanted to return a fully themed page as part of a form submit. Since you can't really do this all that well, I have come up with this work around using theme functions.
The first part is my custom HTML I wanted to display within the confines of my theme. This was all calculated based on the results of form input (in this case, a quiz --- note this is not related to the contrib quizzler module).
The result of this is it takes the HTML in my quizzler-answer.tpl.php file and places it within my general page wrapper. This so I do not have to re-direct after the form is submitted. I hope this helps someone.