By awan on
Hello guys,
I have read Forms API Quick Start Guide and some other stuff, but am unable to understand where to put this code. I have created a page under "Create Content --> Page", put some code to create a field in the body, selected PHP from Input format, but it does not work.
Could anybody tell me please where to put this code to create a personal form or to modify a form generated with webform.
Or point me to any link which explains in detail.
I will be thankful guys.
Comments
The key to getting the Forms
The key to getting the Forms API to work is calling drupal_get_form(). I hope you're using Drupal 5.x, because there were some critical changes made to it, and that's all I know how to explain.
In your page, you should have a function to construct and return the form array. Outside of that function, call
drupal_get_form('page_form');(page_form is whatever you named your function.) If you want to submit the form to the same page, you should also have a page_form_submit() function, and possibly a page_form_validate() function.Modifying an existing form really requires writing a module that implements hook_form_alter().
-----
Übercart -- One cart to rule them all.
Thanks Island Usurper for
Thanks Island Usurper for reply,
I am using Drupal 5.1.
I have copied the following code from "Forms API quickstart guide"
and pasted it to "body field" of a page.
But when I "Submit my page It does not display anything."
Am I missing something ??
The forms API is really meant to be used from a module
Functions defined in code inside a node body only exist if the node is veing viewed. For the form to do something you need a function to handle the submit (In your case it would be called ('test_form_submit'). This function needs to exist when the form is submitted or it is not called so it should exist within a module.
Thanks nevets, I have seen
Thanks nevets,
I have seen the handbook for writing a module. It is quite vast.
Do you think it is necessary to read all this to just use Forms API??
Or if somebody has some time to just explain me how to write a module (in some steps) to create a form with Forms API. It would be grateful.
I am using Windows XP, Easyphp 1.8 and Drupal 5.1
Thanks a lot
A bit late but...
Ran across this post while searching for some issues I'm having. I had a lot of similar questions and found the following helpful for creating a basic module which I could then edit with the code for a form:
http://drupal.org/node/84658
Got a problem with your example here ...
Hi Nevets,
I've got a problem with your example here http://drupal.org/node/68159, and have posted a reply there which is as follows:
-----------------------------------
When I tried to use the example (http://drupal.org/node/68159), I got the following error:
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'myform_sample' was given in ...\includes\form.inc on line 218.Any idea what I am doing wrong?
-----------------------------------
I am just hoping you'll see it soon and help. Thanks.
A guess, you are using Drupal 5?
The error would suggest you are using Drupal 5, the example is for 4.7 and there where some changes to the form API in Drupal 5. See http://drupal.org/node/64279#drupal-get-form for the details.