0

I am trying to override the default user registration form (user_register_form). I would like for the form to create a CCK node (membership_request) that is already on the system. I am able to get all of the hook overrides setup correctly but I can not get the fields of the CCK form to show up.

Here is what I have done so far:

sites/all/themes/bootstrap/includes/registry.inc

 $hooks['membership_request_node_form'] = array(
        'render element' => 'form',
        'path' => drupal_get_path('theme', 'bootstrap') . '/templates/forms',
        'template' => 'node--membership-request-form',
        'arguments' => array('form' => NULL),
        'preprocess functions' => array(
                'bootstrap_preprocess_membership_request_node_form'
        )
  );

sites/all/themes/bootstrap/template.php

function bootstrap_preprocess_membership_request_node_form(&$vars) {
    //$args = func_get_args();
    //array_shift($args);
    //$form_state['build_info']['args'] = $args;
    //$vars['form'] = drupal_build_form('membership_request_node_form', $form_state['build_info']['args']);
    //$vars['form'] = drupal_build_form('membership_request_node_form', membership_request_node_form(array()));
    $vars['intro_text'] = t('This is my super awesome reg form');
}

sites/all/themes/bootstrap/templates/forms/node--membership-request-form.tpl.php

<?php
print $intro_text; 
//print drupal_render_children($form);
?>  

In the below examples, "This is my super awesome reg form" will show up as expected form modal in the new registration form. However, 1) all attempts to pass the form from the preprocess function have failed for me (as shown with the commented lines in the template.php file) 2) when the drupal_render_children line is uncommented in the tpl file I get the following errors: form errors

Thanks

0

Why don't you alter the user registration form by adding fields at admin/config/people/accounts/fields there is an option Display on user registration form.

This will then modify the User entity to use those fields, which may mean your membership_request node is not needed, but if it still is you can use Rules to automatically create a node when a user registers.

  • Basically nodes do not have the anatomy to be exploited the way users accounts can. I use a form that does not allow anonymous users to create user entities in order to prevent potential vulnerability exploits. The theory behind that is even with captcha, rules, (user) status = 0, etc if a user account can be created, then it can also be exploited. So instead of creating user accounts, i create nodes (could also use webforms or any other form) so that in the event of an unknown exploit an anonymous user/script cannot generate user accounts that can then be escalated. – John R Nov 12 '15 at 9:53
  • The first part of your question is: "I am trying to override the default user registration form", therefore my approach is valid to your question. – Colin Shipton Nov 12 '15 at 15:26
  • Yes, your approach is valid to the the way my question is phrased. And I'm sure I need to rephrase a few parts. If it help to know, I'm using the bootstrap_login_modal. This module looks for user_register_form. I think I may have to kill a kitten to get the module to look for a different form so that is a no go! The end result is that I do not want the user registration form for to create a user account at all. Instead I want it to create a CCK node. I hope that clears things up a bit. Thanks – John R Nov 12 '15 at 16:50
  • Looking at the Bootstrap Login Modal module, it's a small module and all it does is $register_form = drupal_get_form('user_register_form');, can't you take that module as a starting point and replace the form used? – Colin Shipton Nov 12 '15 at 16:54
  • Yes, that is actually what I'm doing now $register_form = drupal_get_form('membership_request_node_form');!!! But the world has one less kitten! And I figured I would probably get flamed for hacking a contrib module instead of getting the question answered so alas I wanted to see if there was a "drupal way" to do it? – John R Nov 12 '15 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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