/**
  * Function to create a user in Drupal.
  *
  * @param array  $params associated array
  * @param string $mail email id for cms user
  *
  * @return uid if user exists, false otherwise
  *
  * @access public
  */
 function createUser(&$params, $mail)
 {
     $form_state = array();
     $form_state['values'] = array('name' => $params['cms_name'], 'mail' => $params[$mail], 'op' => 'Create new account');
     if (!variable_get('user_email_verification', TRUE)) {
         $form_state['values']['pass']['pass1'] = $params['cms_pass'];
         $form_state['values']['pass']['pass2'] = $params['cms_pass'];
     }
     $config = CRM_Core_Config::singleton();
     // we also need to redirect b
     $config->inCiviCRM = TRUE;
     $form = drupal_retrieve_form('user_register', $form_state);
     $form['#post'] = $form_state['values'];
     drupal_prepare_form('user_register', $form, $form_state);
     // remove the captcha element from the form prior to processing
     unset($form['captcha']);
     drupal_process_form('user_register', $form, $form_state);
     $config->inCiviCRM = FALSE;
     if (form_get_errors() || !isset($form_state['user'])) {
         return FALSE;
     }
     return $form_state['user']->uid;
 }
            <li class="support">
                <h2 class="support-the-cause"><?php echo t('Donate to a Walker'); ?></h2>
                <p><?php echo t('Support a participant in this walk.'); ?></p>
                <form action="<?php echo $search_url; ?>" method="post">
<?php
    $formId             = 'dw_campaigns_user_search_dummy_form';
    $form               = dw_campaigns_user_search_dummy_form($campaign_id);
    $form['#build_id']  = 'form-'. md5(uniqid(mt_rand(), true));

    if(count($_POST) > 0) {
        $form['#post'] = $_POST;
    }

    $formState         = array('storage' => NULL, 'submitted' => FALSE);

    drupal_prepare_form($formId, $form, $formState);
    drupal_process_form($formId, $form, $formState);

    echo drupal_render($form['query']);
    echo drupal_render($form['form_id']);
    echo drupal_render($form['form_build_id']);
    echo drupal_render($form['submit']);
?>
                </form>

            </li>
            <li class="city">
                <!-- <h2 class="raise-money-host"></h2> -->
                <span><?php echo t('Don\'t see your city in the list? !urlstart Click here to host a Walk !urlend in Your City', array('!urlstart' => '<a href="/dw/walking/host" class="">', '!urlend' => '</a>')); ?></span>
            </li>
            <li class="contest">
	if($user->uid == 0) { 

    /**
     * All this is required so drupal will call dw_campaigns_user_login_submit()
     */
    $form_id                    = 'dw_campaigns_user_login_form';
    $form                       = dw_campaigns_user_login_form();
    $form_build_id              = 'form-'. md5(uniqid(mt_rand(), true));
    $form['#build_id'] 	= $form_build_id;
    if(count($_POST) > 0) {
        $form['#post']		= $_POST;
    }
    
    $form_state 		= array('storage' => NULL, 'submitted' => FALSE);
            
    drupal_prepare_form($form_id, $form, $form_state);
    drupal_process_form($form_id, $form, $form_state);

    //remove labels
    unset($form['name']['#title']);
    unset($form['pass']['#title']); 

?>
    <h2><?php echo t('Fundraiser Login'); ?></h2>
	<?php
		if(isset($_REQUEST['create'])) {
			echo '<p>' . t('You must have an account to create a fundraising page.') . '</p>';
                        echo '<p>' . t('Please login below or create an account now ');
                        echo l(t('Sign Up'), 'dw/user/register');
                        echo '</p>';
		}
Exemple #4
0
/**
 * This is a re-implementation of drupal_get_form, which returns the form_build_id along with the rendred form
 */
function _nodereferrer_create_get_form($form_id)
{
    $form_state = array('storage' => NULL, 'submitted' => FALSE);
    $args = func_get_args();
    $cacheable = FALSE;
    if (isset($_SESSION['batch_form_state'])) {
        // We've been redirected here after a batch processing : the form has
        // already been processed, so we grab the post-process $form_state value
        // and move on to form display. See _batch_finished() function.
        $form_state = $_SESSION['batch_form_state'];
        unset($_SESSION['batch_form_state']);
    } else {
        // If the incoming $_POST contains a form_build_id, we'll check the
        // cache for a copy of the form in question. If it's there, we don't
        // have to rebuild the form to proceed. In addition, if there is stored
        // form_state data from a previous step, we'll retrieve it so it can
        // be passed on to the form processing code.
        if (isset($_POST['form_id']) && $_POST['form_id'] == $form_id && !empty($_POST['form_build_id'])) {
            $form = form_get_cache($_POST['form_build_id'], $form_state);
        }
        // If the previous bit of code didn't result in a populated $form
        // object, we're hitting the form for the first time and we need
        // to build it from scratch.
        if (!isset($form)) {
            $form_state['post'] = $_POST;
            // Use a copy of the function's arguments for manipulation
            $args_temp = $args;
            $args_temp[0] =& $form_state;
            array_unshift($args_temp, $form_id);
            $form = call_user_func_array('drupal_retrieve_form', $args_temp);
            $form_build_id = 'form-' . md5(mt_rand());
            $form['#build_id'] = $form_build_id;
            drupal_prepare_form($form_id, $form, $form_state);
            // Store a copy of the unprocessed form for caching and indicate that it
            // is cacheable if #cache will be set.
            $original_form = $form;
            $cacheable = TRUE;
            unset($form_state['post']);
        }
        $form['#post'] = $_POST;
        // Now that we know we have a form, we'll process it (validating,
        // submitting, and handling the results returned by its submission
        // handlers. Submit handlers accumulate data in the form_state by
        // altering the $form_state variable, which is passed into them by
        // reference.
        drupal_process_form($form_id, $form, $form_state);
        if ($cacheable && !empty($form['#cache'])) {
            // Caching is done past drupal_process_form so #process callbacks can
            // set #cache. By not sending the form state, we avoid storing
            // $form_state['storage'].
            form_set_cache($form_build_id, $original_form, NULL);
        }
    }
    // Most simple, single-step forms will be finished by this point --
    // drupal_process_form() usually redirects to another page (or to
    // a 'fresh' copy of the form) once processing is complete. If one
    // of the form's handlers has set $form_state['redirect'] to FALSE,
    // the form will simply be re-rendered with the values still in its
    // fields.
    //
    // If $form_state['storage'] or $form_state['rebuild'] have been
    // set by any submit or validate handlers, however, we know that
    // we're in a complex multi-part process of some sort and the form's
    // workflow is NOT complete. We need to construct a fresh copy of
    // the form, passing in the latest $form_state in addition to any
    // other variables passed into drupal_get_form().
    if (!empty($form_state['rebuild']) || !empty($form_state['storage'])) {
        $form = drupal_rebuild_form($form_id, $form_state, $args);
    }
    // If we haven't redirected to a new location by now, we want to
    // render whatever form array is currently in hand.
    return array('form_build_id' => $form['#build_id'], 'form' => drupal_render_form($form_id, $form));
}