I am completely new to Drupal and fairly new to PHP although I have done extensive work with CMS platforms as well as many programming languages. With that said, would anyone be able to point me in the right direction for this particular case?

  • I have added a few custom fields to the standard user profile (home town, personal bio, etc.). Visitors may self-register, but administrator approval is required.
  • Upon submission of the visitor's registration, I would like to post all of the fields of that registration into either 1) a certain forum topic or 2) a new poll content, in order for Senior Member (a custom role) users to review the registration.
  • A majority of Senior Members must approve of the new user before an administrator will allow the new membership.

Does that process make sense? I have searched through the Drupal Community and Forum and I can not find a similar case. Would anyone have a suggestion or model code that could help me?

Thanks, - KC

Comments

kalebcaptain’s picture

My first step is to create a forum post in the code when a new user registration is submitted.

My code:

    // Construct the new node object.
    $node = new stdClass();

    // Set the values for the node
    $node->title = "Test title";
    $node->body = "The body of my forum topic.\n\nAdditional Information";
    $node->type = 'forum';   // Your specified content type
    $node->created = time();
    $node->changed = $node->created;
    $node->status = 1;       // To have published, else use 0
    $node->promote = 0;      // If you want promoted to front page use 1, else use 0
    $node->sticky = 0;
    $node->format = 1;       // Filtered HTML
    $node->uid = 1;          // UID of content owner
    $node->language = LANGUAGE_NONE;

    // If known, the taxonomy TID values can be added as an array.
    //$node->taxonomy = array(16,22,);
    $container = taxonomy_get_term_by_name('Membership Applications');
    $node->taxonomy_forums = $container[0];

    // Save the node.
    node_save($node);

...is based on a stackoverflow tutorial. However, I am not sure what version of Drupal that tutorial addressed. The code does create a content node within Drupal, but it does not properly set the node as a forum post.

    $container = taxonomy_get_term_by_name('Membership Applications');
    $node->taxonomy_forums = $container[0];

...returns the warning "Undefined offset: 0". Does taxonomy_get_term_by_name() work within Drupal 7? Is there a better way to find/set the forum taxonomy?

Thanks!

Silicon.Valet’s picture

My search was unrelated, but you are very close up there.
Two things,

First: you're assigning the forum taxonomy incorrectly. Assign by tid and use the following field ref

    $node->taxonomy_forums['und'][0]['tid'] = $tid;

Second:You've left out comment settings, so it'll default to no comments.

  $node->comments = 2;

Other than that, the above code will work in Drupal 7

nevets’s picture

There should be no need to create the content. If you have used fields (vs code) the information should be available by looking at the users profile.

kalebcaptain’s picture

Thanks for the reply. Unfortunately I have a one-off use. I want new users to register, but then I seek to place their submitted profile as a snapshot into an officers forum. The officers would then vote whether to make this pending registrant a valid user. A snapshot of the profile would then be preserved (the user might update fields in the future) and the comments of the officers would also be recorded by using a forum thread.

Do you know of another way around this case? Thanks, - KC

nevets’s picture

You could use the profile 2 module and a content type for the profile. By enabling revisions you can retain the original information. You could use comments for the notes and one of the voting modules to support voting.