buildCommonNS(); $out['errors'] = array(); /** * Set up the elements and rules for the sign-up form. */ $form = new HTML_QuickForm('signup_form', 'POST', 'signup'); $form->addElement('text', 'full_name', 'Full Name'); $form->addElement('text', 'username', 'Username', array('maxlength'=>50)); $form->addElement('password', 'password', 'Password', array('maxlength'=>255)); $form->addElement('password', 'password_verify', 'Password (verify)', array('maxlength'=>255)); $form->addElement('text', 'email', 'Email'); $form->addElement('text', 'url', 'Home URL'); $form->addElement('text', 'location', 'Location'); $form->addElement('textarea', 'description', 'Bio / Description'); $form->addElement('file', 'profile_image', 'Profile Image'); $form->addElement('submit', 'signup', 'Sign up'); $form->addRule('username', 'Need a username', 'required'); $form->addRule('password', 'Password is blank', 'required'); $form->addRule('email', 'Email address needed', 'required'); $form->addRule('password_verify', 'Password verification', 'required'); $form->addRule(array('password', 'password_verify'), 'Passwords do not match', 'compare', 'eq'); $form->addRule('screen_name', 'Screen name is required', 'required'); /** * Attempt to validate the form data incoming. */ if ($form->validate()) { // Pull together all the fields needed for a new user record. $values = $form->getSubmitValues(); $user_fields = array(); foreach (array('email','full_name','location','description','profile_image_url','url') as $name) { $user_fields[$name] = $values[$name]; } $user_fields['created'] = date("Y-m-d H:i:s"); // Attempt to create a new user record, watch for errors. $rv = $this->auth->addUser($values['username'], $values['password'], $user_fields); if ($rv !== TRUE) { if ($rv instanceof PEAR_Error && strpos($rv->message, 'already exists') !== FALSE) { array_push($out['errors'], 'That username has already been taken.'); } } else { $profile_image = $form->getElement('profile_image')->getValue(); if ($profile_image && $profile_image['tmp_name']) { $this->updateAvatarImage($values['username'], $profile_image['tmp_name']); } // TODO: Require email verification (or openid?) before automatically approving/auth'ing account. $_POST[$this->auth->getPostUsernameField()] = $values['username']; $_POST[$this->auth->getPostPasswordField()] = $values['password']; $this->auth->logout(); $this->auth->start(); $form->freeze(); header("Location: {$out['BASE_URL']}/people/".$values['username']."/settings"); } } else { $out['showform'] = TRUE; } // Extract the results of form validation in an array for the template. $renderer = new HTML_QuickForm_Renderer_Array(); $form->accept($renderer); $out['form'] = $renderer->toArray(); // Render the signup template. echo $this->renderTemplate('signup', $out); ?>