Prepopulating fields from user profiles on new event creation

Events happening in the community are now at Drupal community events on www.drupal.org.
ruess's picture

Hi All,

I have a scenario that is baffling me and would like some help on how to tackle this with regard to Drupal 7

I have user role for which I want regular authenticated users to be able to schedule them for appointments (role = service providers). I want to have a field on the Service Provider's account profile in which the Service Provider (SP) can enter their hourly rate. Also, I have created a content type called "appointment" with a date field (based on the date module) so that anonymous users can schedule appointments with the Service Providers.

Right now I have a user reference setup so that when an anonymous user clicks a "create appointment" link on the Service Provider's page, it it aware of the Service Provider for which the appointment is being created. What I need to figure out is how do I fetch or extract the field "hourly rate" from the Service Provider's user profile and populate it on the same type of field of the new appointment content type?

Firstly, are there any modules or settings that I should be aware of that might help with this? Secondly, if not, how should I proceed with a coded solution?

Thanks so much!

kevin

Comments

follow...

davemurphy's picture

follow...

you don't need to do that to

frob's picture

you don't need to do that to follow any more.

profile_user_load

hook_node_presave

vmi's picture

Not sure if this would be the best solution to meet your needs since the drawback here would be the end user wouldn't see the rate applied until after the node's been submitted to be saved but one solution might be to use hook_node_presave to get the service providers uid from the $node obj for the "appointment" content type and then use profile_user_load to get the hourly rate and apply it before saving.

I have a couple of

frob's picture

I have a couple of questions.

Take a look at the rules module. It should be able to do what you want it to do. Right now the learning rules series of videos is free over at drupalize.me http://drupalize.me/videos/introduction-rules

See if that will do what you want. Other than that it could get a little complicated (code heavy).

rules videos cont.

philosurfer's picture

Another great source for rules videos is at nodeone.se

http://dev.nodeone.se/en/learn-the-rules-framework


          "we are the cult of personality."

The Drupalize.me videos are

frob's picture

The Drupalize.me videos are done by the people over at nodeone. They are very thorough.

Computed Field

ruess's picture

Hi All,

Thanks for all the suggestions. I don't think Rules is going to work in this case as I need this field to be fetched and populated upon *loading" of the new content type form, not after it's been saved - unfortunately there does not appear to be a trigger for that.

My thought now is that I'll probably need to use computed fields to grab this field from the other content type for which the node is referenced (using the References module). Here's a snippet that I found for Drupal 6 from this issue: http://drupal.org/node/290443#comment-1822960

"Suppose you have 2 nodes; node1 has the field you want and node2 has a nodereference field pointing to node1.

<?php
$nid
= $node->field_from_node2_nodereference[0]['nid'];
$myNode = node_load($nid);
$node_field[0]['value'] = $myNode->field_from_node1[0]['value'];
?>

"
I've tried this snippet, but get no results displayed for the field (and also a NULL in my database). I am suspecting it's because it's not for Drupal 7. Does anyone have any ideas of what I could try to get this to work?

Thanks,

kevin

I don't see anywhere in the

frob's picture

I don't see anywhere in the code that the node is being saved, although I though you just wanted to display the information from the other node. Try adding the line node_save($myNode); I am guessing now that this what you are trying to do.

Also, I would still say to check out the rules framework. It is much expanded from the triggers actions module. I am pretty sure there is a load action.

Thanks frob! I have checked

ruess's picture

Thanks frob! I have checked out Rules and have found a way to do so I think. I used the rules_link and rules to create a new piece of content from the service provider's profile and added a rule to copy certain fields from one to another.

Great suggestion!