By modul on
I have a very basic module, myforms.module :
<?php
// $Id: myforms.module
// something
function myforms_form_alter($form_id, &$form) {
print_r("This is the form id: " . $form_id);
if ($form_id == 'some_form') {
echo "Hi there<br>";
}
This module does its amazing stuff :-)
But now I would like to add some PHP code to be executed upon submission of some_form . And for one reason or the other, I can't get it to work. How? How? How??? Could someone give me a working example just issuing an "echo" thingy upon submission? One limitation: upon submitting, things are saved (by Drupal, not by my own code). Obviously, that saving should still be done. I just want to issue an extra "echo". How do I do that? And where do I put this extra submit code?
Using Drupal 5.x
Comments
You can add your own submit
You can add your own submit handler (a function that runs when a form is submitted) using the form api: http://drupal.org/node/58689.
If the form being submitted is a node form, you can also use hook_nodeapi when $op=presave or $op=insert (see http://api.drupal.org/api/function/hook_nodeapi/6).
Thanks, MarcVanGend and
Thanks, MarcVanGend and MTSanford, I "feel" I'm getting there, but not quite...
This is myforms.module:
And then in a .php file which contains my other readily available goodies, I added:
BUT:
- my submit button is no longer there...
- and the echo from my special submit function is (well, obviously) not seen, i.e. I can't get to my function
I admit, Drupal forms are still, after sooooo many months, one big labyrinth to me. But if you guys could help me out of this one...
Look closely at the
Look closely at the documentation on http://drupal.org/node/58689, it seems as if you didn't do exactly what it says. Pay attention to the difference between $form['submit'] and $form['#submit']. Make sure that you add a handler to the $form['#submit'] array instead of completely overriding it.
Again, if this is a node form your editing, hook_nodeapi might be better/easier. Try this for instance:
You made my day, MarcVan
You made my day, MarcVan Gend... I finally have it working. Obviously, I messed up by overriding the entire submit thingy. Thanks for your most generous help!!
You're welcome. Thanks for
You're welcome. Thanks for the feedback, I like making days :-)
It looks like you're writing
It looks like you're writing *OVER* your submit button, not altering it (which is the point of hook_form_alter)
Probably just something like this
... which would add a submit
... which would add a submit function for the button,
or probably better:
Which would add a submit function for the entire form.
Thanks, MTSanford, your help
Thanks, MTSanford, your help also meant a great relief for me! I'm starting to see a litttttle clearer now.
http://api.drupal.org/api/fil
http://api.drupal.org/api/file/developer/topics/forms_api_reference.html...