I have my own content type made in my module. It has text and image fields.
I now want to add a form fields like radio box and a submit button so that when the node is rendered the user can give their input. I unable to do this.
1) My first try failed when I tried adding a radio box when creating my content type.
simplequiz_radio11' => array(
'field_name' => 'simplequiz_radio11,
**'type' => 'radio',**
What do I write in the type field besides text and image. I will like to mention again that the radio box needs to take the user input when the node is rendered not in edit mode.
2) I tried using drupal_get_forms and I am able to attach a form and its elements to the node using drupal_get_forms but my node has many images(fields) and I need a form element for each image so its not practical to use it this way. Below is my code:
function simplequiz_node_view($node, $view_mode, $langcode)
{
$f = drupal_get_form('simplequiz_form', $node);
$f['#weight'] = 100;
$node->content['data_collection_form'] = $f;
}
This works fine but how can I do this for say 10 image fields ? It seems the first option is better but I can't seem to get the right field type.
// I managed to solve it as my logic was wrong I need to work with the formater and not the fields in drupal.
function simplequiz_field_formatter_info() {
return array(
'simplequiz_example_field' => array(
'label' => t('radio button on node'),
'field types' => array('text'),
),
'simplequiz_btn_field' => array(
'label' => t('button on node'),
'field types' => array('text'),
),
);
}
/**
* Implements hook_field_formatter_view().
*/
function simplequiz_field_formatter_view($object_type, $object, $field, $instance,
$langcode, $items, $display) {
switch ($display['type']) {
case 'simplequiz_example_field':
$element[0]['#type'] = 'markup';
$element[0]['#markup'] = theme('simplequiz_example_field', array('value' => $items[0]
['safe_value']));
break;
case 'simplequiz_btn_field':
$element[0]['#type'] = 'markup';
$element[0]['#markup'] = theme('simplequiz_btn_field', array('value' => $items[0]
['safe_value']));
break;
}
return $element;
}
/**
* Theme the example field.
*/
function theme_simplequiz_example_field($variables) {
return '<form><input type="radio" name="type" value="silver">Gold'
.$variables['value']. ' </br> <input type="radio" name="type" value="Gold"> Silver </br>
</form>'
;
}
function theme_simplequiz_btn_field($variables) {
return '<input type="submit" class="form-submit" value="Submit" name="op" id="edit-
submit--2">'
;
}
Cheers, Vishal