Hello,

I have created a custom field on node with field system from manage fields. How can i use the same field with custom form. ?? Like, we can use "Add existing field" to add already created field but how can i use that with my custom form. Please help me with this I am not figure out what functions / parameter i should use. ?

Regards,
Mitesh

Comments

malcomio’s picture

Not really sure what you're trying to achieve, but if you're working with forms, you should read http://drupal.org/node/751826

If you want to change values based on the form submission, then you can work with the Field API in your form submit handler.

miteshmap’s picture

I was saying that. there was a method with cck in drupal 6 to attach a cck field in our custom form. like.

$field = content_fields('field_name');  // field_name is cck field (text_field,text_Area,image_field anything.)
$form['#field_info'][$name] = $field; 
$form += content_field_form($form, $form_state, $field); 

So how can i do the same with drupal 7 ?? I had a form and i want to use the field that i created for a node type.

Anonymous’s picture

Priority: Critical » Normal
Issue tags: -addfield

Have you looked at the Field API documentation as suggested? Maybe using field_view_field() is what you want?

miteshmap’s picture

Yes, I checked that but its not helpfull. what i need is something like this.

function drupal_form(){

 $form['field'] = array(
     '#type' => 'textfield',
     '#title' => t('Name'),
);

$form['field_name'] = some_function('existing_field_name'); // "exiting_field_name" is the field that i created on a node_type and this code should return the field structure like form api.so it can be rendered as form element.

$form['submit'] = array( 
   '#type' => 'submit',
   '#value' =>  t('submit'),
)

return $form;

}

Please let me know if its not clear.

Anonymous’s picture

miteshmap’s picture

I also tried this . but it didn't work as i don't have any "$entity" to pass in function, also the view mode should be form to display it like a form element which is not supported here. i guess..........

Anonymous’s picture

The entity is node. You stated it in your original post.

manjeet’s picture

Issue summary: View changes

function drupal_form(){
.
.
.
module_load_include('inc', 'field_ui', 'field_ui.admin');
$entity_type = 'node';
$field_name = 'field_name';

$field = field_info_field($field_name);
$instance = field_info_instance($entity_type, $field_name, $node->type);
$form += field_ui_default_value_widget($field, $instance, $form, $form_state);

.
.
return $form;
}

Dimetry’s picture

@manjeet Thanks! It works

sanju1092101’s picture

Status: Active » Fixed

Marking it as fixed as per comment in #8.

Thanks

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

MarX’s picture

Thank you very much ;-)