By soezkan on
My form shall be used with preset values, such as
name=Johnny Winter,
street=66 Summerstreet
city=Autumnville 99999
I build my form with the forms.api and call it through
drupal_get_form(contact).
So for my example it went like this:
drupal_get_form(contact);
function contact() {
// Name
$form['contact']['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#value' => 'Johnny Winter',
'#required' => TRUE,
);
// Street
$form['contact']['street'] = array(
'#type' => 'textfield',
'#title' => t('Street'),
'#value' => '66 Summerstreet',
'#required' => TRUE,
);
// City
$form['contact']['city'] = array(
'#type' => 'textfield',
'#title' => t('City'),
'#value' => 'Autumnville 99999',
'#required' => TRUE,
);
...
...
...
}
The best it would be I could pass an array with all form-fields like:
drupal_get_form(contact, $formfields);
If someone could help me with this, I would appreciate a lot!
Thank you,
Soezkan
Comments
Hi Soezkan,
Hi Soezkan,
Very simple: in your function call, you can insert whatever parameters you want (well, I assume there is a limit, but for all practical purposes, there isn't. And then in the actual function, you can use these parameters just as you would in any other function: you can show them, make them editable, etc., and finally, you can toss them in the Submit function. For instance, I have a form which sends a bunch of mail messages. I construct the various parameters (subject, receivers, some interesting url etc.), and then call my function like this:
In the function, it goes like this:
Thank you so much for the
Thank you so much for the great help!
All the best,
Soezkan
It should be mentioned that
It should be mentioned that the first argument of the function to be called by drupal_get_form must be &$form_state (or whatever you like it to call).
Not sure I'm following you
Not sure I'm following you here, perforator. Maybe that &$form_state thing is the case in Drupal 6.x? To my knowledge, it's at least Not the case in Drupal 5.x.
Yes, only for 6.x.
Yes, only for 6.x.
Thanks
Thanks for this. That little clarification was really helpful.
thanx
thanx for this.. :)
Thanks!
Thank you for that perforator, I just spent about 3 hours trying to figure out why my function wasn't reading the page arguments from my hook_menu callback correctly. Added in &$form_state as the first parameter for my function and it works like a charm.
You miss the $form and $form_state
Incase of the below statement
The function, will be like this:
THANK YOU VERY MUCH!!!
I was trying to figure this out, you solved it!! :D