Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

A user, across different Drupal installs, is generally the same concept. To be more basic, every user has an email address, username, and password. Let's say I write a module that works with users and manipulates these fields in some way. I can, in the majority of cases, assume this will be standard across different Drupal websites and safely distribute this module. If I wanted to provide the module the ability to manipulate other optional fields that might be added to a profile, such as first name, last name, favorite bubble-gum, etc., how could I do this? One thing that comes to mind is an optional text box (on the system settings side) that takes multi-line input, each line dictating what new field to manipulate. Is this the best way to accomplish this?

For example, let's say you add the profile fields "Hobby, Telephone #, favorite food." I write a module that populates a block with a varying number of profile fields. The number of fields depends on how many chosen in the configuration of the module; I could choose to provide a block to edit a user's "Hobby" and "Favorite Food" by entering those two lines in a text box separated by a new line. This could be done with a multivalue select box, as well, but if I want to attach other information to each field, I think the textbox allows for greater flexibility.

This could be applied for any other module, as well. Let me know if I need to abstract the question further, please.

share|improve this question
1  
Could you be more specific? What do you mean by "the ability to manipulate other optional fields that might be added to a profile" do you mean give other users the ability to edit this data through forms or do you mean the ability to programmatically update custom fields? – LSU_JBob Oct 14 '11 at 22:08
I added a bit more info. Sorry for the vagueness. – mrryanjohnston Oct 17 '11 at 11:43
Could you simplify your explanation? You want to add custom form elements to the register form, then add those values to a user profile? then allow the user to edit these values in the future? – LSU_JBob Oct 17 '11 at 17:10

3 Answers

Have you ever seen the Features module? Essentially, when you have some settings on one site, a feature can allow you to move it to another. These can be very broad, like "add these 5 fields to all user profiles", or very granular, like "these 5 features each expose a new field on a user profile".

Basically, you do the config once, and then you can carry around field settings, permissions, views, menu items, just no content - it's not designed to move content around.

share|improve this answer
Indeed I have! Thanks for the input. However, I think my problem is still a bit fuzzy. I'll try to clarify a bit more in the future. – mrryanjohnston Oct 17 '11 at 15:23

D6 answer: I'd iterate through $form array or node (using nodeapi) looking for anything that begins with field_ which will give you a list of all the inputs available on that particular form.

so (not tested and I'm sure is not correct names or array structure)

foreach ($form as $a => $b) {
  if($b == 'field_*') {
    // do code here
  }
}
share|improve this answer

If I get you right, you are looking for a way to ad a different number of properties to different instances of the same node type. In this case http://drupal.org/project/properties could Be something for you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.