1

I have a form, and want to generate a list of the form's field-names. Here is how I currently do it:

$fieldnames = array();  
foreach ($form as $key=>$val){
    if (substr($key, 0, 6) === 'field_'){ 
      $fieldnames[] = $key;
    }
}

Is there a better way to do this?

UPDATE: Just to clarify ... I am wondering whether there is a less "kludgey" way of doing this. For example, does the content module provide an api function that loops through fields. (I couldn't find one.)

moondog
  • 1,537
  • 5
  • 22
  • 34

2 Answers2

0

the field that you added by cck...or from UI field system are begin with "field_" and this fields are usually in the nodes...so if you are talkin about nodes form and fields that added by cck....you are in the correct way... but if this fields are added programmatically....so you are in the wrong way

maged adel
  • 794
  • 5
  • 11
  • Hi Maged, I now realize my question was not clear. I modified the question to clarify what I am looking for. Thanks. – moondog Aug 27 '11 at 22:32
0

sorry im not 100% sure but i don't think you can get all the fields that added programatically..but if you added this fields from cck or from '/admin/content/node-type/stores/fields' where {stores} is your content type that you are working with then you can get this fields name from {content_node_field_instance} table as the following

$result_handle = db_query("select field_name from {content_node_field_instance} where 
`type_name` = '%s'","yourContentTypeName") ;
while($result_object = db_fetch_object($result_handle)){
 $fields[] = result_object->field_name ; 
}

now you have the array $fields which hav all the fields of your content type...i hope that will help you

maged adel
  • 794
  • 5
  • 11