By blond_and_stupid on
The following code puts up a simple form correctly, but when I press 'submit', the page just refreshes instead of executing the code in the _submit function. What have I done wrong? (I'm running Drupal 5.1)
$output = drupal_get_form('my_function');
echo "$output";
function my_function() {
$form['test'] = array (
'#type' => 'fieldset',
'#title' => t('testing...'),
);
$form['test']['param'] = array (
'#type' => 'textfield',
'#title' => t('my param'),
);
return $form;
}
function test_submit($form_id,$form_values) {
...
}
Comments
Wrong name for submit function
By default if your form function is 'my_function', the submit function should be 'my_function_submit'.
still a problem with the form API submit function
Thanks, I'm aware of that. I wrote a test script that calculates your Body Mass Index. It does not work either for the same reason. After clicking the submit button, the script just seems to refresh the page without entering the submit function. I'm very grateful if someone can point out what I'm doing wrong!
From the code I suspect you placed this in a node
From the code I suspect you placed this in a node in which case it will not work as 'bmi_submit' does not exist except when the page is being used. Normally the form api is used from within a module.
Remember that forms always redirect
Remember that forms always redirect after submission unless the redirect flag is set to false. So your "echo" statement is never seen. Change your "echo" to "drupal_set_message()" and it should be displayed after the redirect.
Chris.
http://www.trailheadinteractive.com
--- Featured Projects ---
http://www.montanakitesports.com
http://www.cmrussell.org
http://www.tdandh.com
http://www.cccsmt.org
http://www.universalsemensales.com
http://www.trailheadinteractive.com
Similar problem
i have a similar problem with the form submit..
i have a function as tasks_create_grid_form, theme_tasks_create_grid_form, tasks_create_grid_form_validate and tasks_create_grid_form_submit
upto validate everything works fine but after that it never calls _submit function.. what might be the problem??
i'm using this inside a module as well.. so the _submit has to be called
hehe silly mistakes..
use type as submit instead of 'button' :-)
I dont know where i did wrong on the submit
Hi,
I'm creating a new module and i've done the layout of the form and i want to submit the values so i can get it saved.
After i press submit button, it just refresh my screen on to the same page.
Please help me .. let me know where i did wrong..
Thanks
I manage to get another way round ...
i added " '#redirect' => drupal_get_form('kit_submit')," to make it call my submit function. and i also change to use $_POST for the value..
Probably not the best approach
It is not the best idea to use $_POST directly as it bypasses some of the features of the form API.
You do not show how you are invoking the form in your example but I am guessing it looks like
in which case your submit function would be called 'kit_form_submit'.
again take care
about api compliant names!
if form's name is:
then the submit for SHOULD BE:
Cheers guys
Hi nevets,
yeah i using drupal_get_form('kit_form').
Hi ilo,
Thanks so much.. now i know why it didnt work in the 1st place.. coz my function name..
Thanks alot guys,
Queenie
Also have a similar problem
I am also unable to get form_submit working right. In my module nodes are validated regarding some custom properties using a call to hook_nodeapi | case 'submit'. After a node is submitted and processed a custom error message is displayed back to the user which includes a form (using a call to:
Then I have the following functions:
All that works fine but it seems that my call to 'submit' is never reached:
I have no idea why this is happening and have read through all the postings I could find. I believe my code is properly constructed and I am following the correct FAPI names. Could this have to do with the fact that the form is constructed after nodeapi / submit has been called?
Any help is greatly appreciated
Thanks
- j
Context and URL?
In what context does
run? What actual displays the message?
And is this really an "error" message? By the time you reach the node be submitted it is a bit late for errors (should be done during validation),
And as always, a URL showing the form in action would be useful (saves a lot of guessing)
hi, thanks for replying on
hi,
thanks for replying on this ! I ended up changing my code. Perhaps I was trying to do something impossible. My site did this:
* create a custom event that contains some cck fields
* prior to event submission (node_api), check for conflicts with other events
* if conflicts, show event, after it has been saved and display some messages
So ideally I wanted to show the form right after the messages and allow users to make notes about the event that has just been submitted and then submit that form. The form itself only updates a piece of CCK content on the event...
Is that totally backwards?
I have figured out an alternative option, by just redirecting them to a separate page on the node which contains a menu to submit the form...
Thanks
- j
Some questions
If I understand correctly someone adds a new event and when they submit the event you check to see if it conflicts with any existing events.
If the event conflicts you want to display a form (which contains a message) so they can if they wish add a note to the other event.
By default after submitting the event you will be placed on the page showing the new event. Is this the behaviour you want?
Do you want the message/form above or below the new event?
Have you though about what happens if there is more than one event that already conflicts? (this makes displaying the form somewhat more challanging).
hi, yes that is the plan for
hi,
yes that is the plan for now. I am still adding some final touches to my code to handle conflicts on repeating events and multiple event conflicts... If there are multiple conflicts each one will be displayed in sequence, but the user still has 1 form at the end of that sequence to put in his or her comments...
- j
Can't Submit Form with Javascript or "other" buttons?
I have problems with forms that don't use a "submit" button to submit the form.
In one case, I have several buttons that are all '#type' => submit. In the other case, there are some hyperlinks in the form that call some javascript that eventually does a
<form-name>.submit().The form's validate function is called, but the submit function is never called -- even if it validates correctly. I'm returned to the form, with the fields filled in (the form's build function is called on submit as well as the validate function), but none of the form's submit actions are done.
I've traced it through with PhpED's debugger but didn't go into the bowels of the form.inc code.
Is there something I need to set so the form module processes these "different" submits as real submits?
Thanks,
m
Can't Explain Why
But I had a problem similar to this as well. I wanted to create a one-field autocomplete form with no submit button, but apparently drupal requires the submit button. My work around was to create the submit element as usual but add #attributes => array('style' => 'display: none') to the element. It now calls both the submit and validate hooks.
Formm doesnt work, help please. thanks
[Edited to add <code> and </code> tags; nevets]
If this is a real request
If this is a real request for support a) it should have been posted as new issue, b) you need to state the problem you are having. Note that your form is completely non-standard as Drupal forms go so it might help if you stated what you are trying to achieve.
I got a same problem,but I
I got a same problem,but I fixed it by guided this post:
http://www.ubercart.org/forum/development/3949/after_theme_form_tapir_dr...
the problem is due to form theming.
"
I think in themeing forms you need to output:
drupal_render($form);
at the end of your form.
Just try inserting that at the end of your theme function. It does some sort of voodoo and tells the magic form pixies to make the form work.
I've never fully understood it.
So try:
function remove_theme_tapirtest_example_6_form($form) {
$output = '
'. tapir_get_table('tapirtest_example_table_6', $form)
. drupal_render($form['submit']) .'
';
$output .= drupal_render($form);
return $output;
}
"
I added " $output .= drupal_render($form['form_id']);
$output .= drupal_render($form['form_token']);" above "return $output",then it works!