Hello,
I am using version 6.10 and have created a form on one of my pages, but I have the following issues for which the tutorial and documentation that I could find do not help:
1) After creating my _form method and _page method, what am I supposed to do get the form to be shown? I am currently calling the print method on the results of _page method, but the tutorial mentions nothing of this or something else that must be done. The call to print shows the form correctly.
2) How are the _validate and _submit methods called? When I press my submit button, neither is called. I am assuming the naming convention of all the methods is so that callbacks can be called.
3) I am getting the following error out and was wondering if any fix existed for it or if it is the source of the above issues.
Invalid argument supplied for foreach() in /var/www/drupal/includes/form.inc on line 1197.
I can post the code if necessary...
Jason
Comments
A link to the tutorial
A link to the tutorial would help to understand the approach you have taken.
It sounds though instead of creating a module you have placed the code in the body field of some content type.
The tutorial used
I used the quickstart tutorial:
http://api.drupal.org/api/file/developer/topics/forms_api.html
Jason
Are you creating a module
Are you creating a module (the code you reference belongs in a module).
Forms must be in modules?
Can you describe how or point me to the docs that describe how to package the form as a module. I am going only by the tutorial mentioned and it gives me no references to placing the form in a module.
Here is a very simple example
Here is a very simple example of how you can create a form in a node:
You will need to install the php_filter module, and use the php_filter input filter in order for this to work. If you are doing it in a module, then the method will be slightly different from what I have shown.
note: code not tested, so there may be typos.
Contact me to contract me for D7 -> D10/11 migrations.
Ok, so I am on track, but...
Thanks a bunch for the example. My code is pretty much as you show and the form does get printed out so the question then arises as to why the _submit and _validate methods do not get called. The names of the methods are:
workshopbooking_form
workshopbooking_form_validate
workshopbooking_form_submit
and this would appear to follow the naming convention so I am a bit confused. Suggestions?
As per the last comments in your post and in the other post, does this php code have to be submitted specially? I am simply submitting it as the body of my page and then modifying the page attributes from the same edit page to indicate that php processing of the page is allowed.
Lets see your code.
Lets see your code.
Contact me to contract me for D7 -> D10/11 migrations.
The code...
Attached is the code for which the _submit and _validate methods are not working. The second set of eyes is MUCH appreciated.
Trying the above code results in:
Fatal error: Cannot use string offset as an array in /var/www/includes/form.inc on line 976
Working partially in 6.10 with different error than you see...
Thanks for trying out the code. I don't get the error you are seeing, but do see the error that I posted at the top of the message:
Invalid argument supplied for foreach() in /var/www/drupal/includes/form.inc on line 1197.
Otherwise the code shows the form for me, but does not hit validate or submit when I hit the submit button. It also doesn't show the checkboxes, but that is another issue.