DrupalBin
Submit Code
About
Recent Posts
Code
Fix for Fix for Code
Fix for Code
Code
Node type whitelist
an axe coach accessories
coach purses married
Fix for de las ghd alturas
de las ghd alturas
Code
more
User login
Log in using OpenID:
What is OpenID?
Username:
*
Password:
*
Log in using OpenID
Cancel OpenID login
Create new account
Request new password
Tags
CCK
drupal
fapi
jquery
menu
module
php
simpletest
taxonomy
test
theme
views
more tags
Home
Fix for Fix for Fix for Code
View
Fix
April 3, 2010 - 10:41pm — Anonymous
<?php
function
test_menu
(
)
{
$items
[
'test1'
]
=
array
(
'title'
=
>
'test1'
,
'page callback'
=
>
'drupal_get_form'
,
'page arguments'
=
>
array
(
'test_1_form'
)
,
'type'
=
>
MENU_NORMAL_ITEM
,
'access callback'
=
>
TRUE
,
)
;
$items
[
'test2'
]
=
array
(
'title'
=
>
'test2'
,
'page callback'
=
>
'drupal_get_form'
,
'page arguments'
=
>
array
(
'test_2_form'
)
,
'type'
=
>
MENU_NORMAL_ITEM
,
'access callback'
=
>
TRUE
,
)
;
return
$items
;
}
function
test_get_values
(
)
{
$values
=
array
(
)
;
$values
[
0
]
=
new
stdClass;
$values
[
0
]
-
>
uuid
=
'001'
;
$values
[
0
]
-
>
name
=
'aaa'
;
$values
[
0
]
-
>
image
=
theme_image
(
'http://drupal.org/sites/all/themes/bluebeach/logos/drupal.org.png'
,
t
(
'No picture available'
)
,
t
(
"picture"
)
,
NULL
,
FALSE
)
;
$values
[
1
]
=
new
stdClass;
$values
[
1
]
-
>
uuid
=
'002'
;
$values
[
1
]
-
>
name
=
'bbb'
;
$values
[
1
]
-
>
image
=
theme_image
(
'http://drupal.org/sites/all/themes/bluebeach/logos/drupal.org.png'
,
t
(
'No picture available'
)
,
t
(
"picture"
)
,
NULL
,
FALSE
)
;
return
$values
;
}
function
test_1_form
(
)
{
$values
= test_get_values
(
)
;
$form
=
array
(
)
;
$form
[
'test1'
]
=
array
(
'#type'
=
>
'fieldset'
,
'#title'
=
>
t
(
'test'
)
,
)
;
$i
=
0
;
foreach
(
$values
as
$value
)
{
++
$i
;
$field_name
=
'model_'
.
$i
;
$form
[
'test1'
]
[
$field_name
]
=
array
(
'#type'
=
>
'fieldset'
,
'#title'
=
>
$value
-
>
name
,
'#collapsible'
=
>
FALSE
,
'#collapsed'
=
>
FALSE
,
)
;
$attributes
=
(
$i
== 1
)
?
array
(
'checked'
=
>
'true'
)
:
array
(
)
;
$form
[
'test1'
]
[
$field_name
]
[
'uuid'
]
=
array
(
'#type'
=
>
'radio'
,
'#value'
=
>
$value
-
>
uuid
,
'#attributes'
=
>
$attributes
,
)
;
$form
[
'test1'
]
[
$field_name
]
[
'picture'
]
=
array
(
'#type'
=
>
'item'
,
'#value'
=
>
$value
-
>
image
,
)
;
}
$form
[
'submit'
]
=
array
(
'#type'
=
>
'submit'
,
'#value'
=
>
'go!!!'
)
;
return
$form
;
}
function
test_1_form_submit
(
$form
,
&
$form_state
)
{
drupal_set_message
(
'<pre>'
.
print_r
(
$form_state
,
true
)
.
'</pre>'
)
;
}
function
test_2_form
(
)
{
$values
= test_get_values
(
)
;
$form
=
array
(
)
;
$form
[
'test2'
]
=
array
(
'#type'
=
>
'fieldset'
,
'#title'
=
>
t
(
'test'
)
,
)
;
$options
=
array
(
)
;
$i
=
0
;
foreach
(
$values
as
$value
)
{
++
$i
;
$field_name
=
'model_'
.
$i
;
$options
[
$field_name
]
=
array
(
'#type'
=
>
'fieldset'
,
'#title'
=
>
$value
-
>
name
,
'#collapsible'
=
>
FALSE
,
'#collapsed'
=
>
FALSE
,
)
;
$attributes
=
(
$i
== 1
)
?
array
(
'checked'
=
>
'true'
)
:
array
(
)
;
$options
[
$field_name
]
[
'uuid'
]
=
array
(
'#type'
=
>
'radio'
,
'#value'
=
>
$value
-
>
uuid
,
'#attributes'
=
>
$attributes
,
)
;
$options
[
$field_name
]
[
'picture'
]
=
array
(
'#type'
=
>
'item'
,
'#value'
=
>
$value
-
>
image
,
)
;
}
$form
[
'test2'
]
[
'models'
]
=
array
(
'#type'
=
>
'radios'
,
'#options'
=
>
$options
,
)
;
$form
[
'test'
]
=
array
(
'#type'
=
>
'radios'
,
'#options'
=
>
array
(
'aaa'
=
>
'aaa'
,
'bbb'
=
>
'bbb'
)
,
)
;
$form
[
'submit'
]
=
array
(
'#type'
=
>
'submit'
,
'#value'
=
>
'go!!!'
)
;
return
$form
;
}
function
test_2_form_submit
(
$form
,
&
$form_state
)
{
drupal_set_message
(
'<pre>'
.
print_r
(
$form_state
,
true
)
.
'</pre>'
)
;
}
Forms
radio
Submit Fix
Summary:
Tags:
Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Show summary in full view
<?php function test_menu() { $items['test1'] = array( 'title' => 'test1', 'page callback' => 'drupal_get_form', 'page arguments' => array('test_1_form'), 'type' => MENU_NORMAL_ITEM, 'access callback' => TRUE, ); $items['test2'] = array( 'title' => 'test2', 'page callback' => 'drupal_get_form', 'page arguments' => array('test_2_form'), 'type' => MENU_NORMAL_ITEM, 'access callback' => TRUE, ); return $items; } function test_get_values() { $values = array(); $values[0] = new stdClass; $values[0]->uuid = '001'; $values[0]->name = 'aaa'; $values[0]->image = theme_image( 'http://drupal.org/sites/all/themes/bluebeach/logos/drupal.org.png', t('No picture available'), t("picture"), NULL, FALSE ); $values[1] = new stdClass; $values[1]->uuid = '002'; $values[1]->name = 'bbb'; $values[1]->image = theme_image( 'http://drupal.org/sites/all/themes/bluebeach/logos/drupal.org.png', t('No picture available'), t("picture"), NULL, FALSE ); return $values; } function test_1_form() { $values = test_get_values(); $form = array(); $form['test1'] = array( '#type' => 'fieldset', '#title' => t('test'), ); $i = 0; foreach ($values as $value) { ++$i; $field_name = 'model_'.$i; $form['test1'][$field_name] = array( '#type' => 'fieldset', '#title' => $value->name, '#collapsible' => FALSE, '#collapsed' => FALSE, ); $attributes = ($i == 1) ? array('checked' => 'true') : array(); $form['test1'][$field_name]['uuid'] = array( '#type' => 'radio', '#value' => $value->uuid, '#attributes' => $attributes, ); $form['test1'][$field_name]['picture'] = array( '#type' => 'item', '#value' => $value->image, ); } $form['submit'] = array( '#type' => 'submit', '#value' => 'go!!!' ); return $form; } function test_1_form_submit($form, &$form_state) { drupal_set_message('<pre>'.print_r($form_state, true).'</pre>'); } function test_2_form() { $values = test_get_values(); $form = array(); $form['test2'] = array( '#type' => 'fieldset', '#title' => t('test'), ); $options = array(); $i = 0; foreach ($values as $value) { ++$i; $field_name = 'model_'.$i; $options[$field_name] = array( '#type' => 'fieldset', '#title' => $value->name, '#collapsible' => FALSE, '#collapsed' => FALSE, ); $attributes = ($i == 1) ? array('checked' => 'true') : array(); $options[$field_name]['uuid'] = array( '#type' => 'radio', '#value' => $value->uuid, '#attributes' => $attributes, ); $options[$field_name]['picture'] = array( '#type' => 'item', '#value' => $value->image, ); } $form['test2']['models'] = array( '#type' => 'radios', '#options' => $options, ); $form['test'] = array( '#type' => 'radios', '#options' => array( 'aaa' => 'aaa', 'bbb' => 'bbb' ), ); $form['submit'] = array( '#type' => 'submit', '#value' => 'go!!!' ); return $form; } function test_2_form_submit($form, &$form_state) { drupal_set_message('<pre>'.print_r($form_state, true).'</pre>'); }
Syntax highlighting mode:
ActionScript
ColdFusion
Diff
Drupal 5
Drupal 6
HTML
INI
Javascript
MySQL
PHP
Python
robots.txt
SQL
Text
Select the syntax highlighting mode to use.
See Also:
Order
Title:
URL:
-1
0
1
Title:
URL:
-1
0
1
Any links you'd like to have associated with the post (Drupal.org issue, Wikipedia article, etc).
File attachments
Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.
Attach new file:
The maximum upload size is
1 MB
. Only files with the following extensions may be uploaded:
jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp phps
.