Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
malcomio CreditAttribution: malcomio commentedNot 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.
Comment #2
miteshmapI was saying that. there was a method with cck in drupal 6 to attach a cck field in our custom form. like.
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.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedHave you looked at the Field API documentation as suggested? Maybe using field_view_field() is what you want?
Comment #4
miteshmapYes, I checked that but its not helpfull. what i need is something like this.
Please let me know if its not clear.
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedhttp://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/func...
Comment #6
miteshmapI 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..........
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commentedThe entity is node. You stated it in your original post.
Comment #8
manjeet CreditAttribution: manjeet commentedfunction 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;
}
Comment #9
Dimetry CreditAttribution: Dimetry commented@manjeet Thanks! It works
Comment #10
sanju1092101 CreditAttribution: sanju1092101 commentedMarking it as fixed as per comment in #8.
Thanks
Comment #12
MarX CreditAttribution: MarX commentedThank you very much ;-)