Ning Developer Docs

Adding private questions to your Network sign up page

The instructions here are out of date and private questions have been added into the social network code.
Introduction
If you've got additional profile information you'd like to collect from your members that you don't want to be made public, you can make some simple mods to your social network to have the information emailed to you when new members sign up.



To carry out these changes, you'll need to have the full code for your network.



XG_Message
The first step is to open up /lib/XG_Message.php and create a new class at the bottom of the file for the new type of message we'll be sending:

/** * XG_Message_AdminNewProfile is for administrative 

* messages of new users with additional profile questions
*/
class XG_Message_AdminNewProfile extends XG_Message {



public function __construct() {
$args = func_get_args();
call_user_func_array(array('parent','__construct'), $args);

}



public function send($to, $from) {
// Send a copy to the site owner
parent::send($to, $from);
}
}


If you want to create a new template for the message rather than using the default one, you can add the template to the /lib/XG_Message directory, and add this to the start of the class (where your template file is named my_great_template.php):

protected $_template = 'my_great_template';




Profile Template
The next step is to add your new form fields to the profile editing page. The template for the page is located at /widgets/profiles/templates/profile/edit.php. Look for the closing </fieldset> tag (around line 155 or so) and add the code for your form. Here's a sample:

<?php // customized profile form with extra fields for signing up to mailing list ?>

<?php if ($this->inJoinFlow) { ?>

<h3>Extra Contact Information</h3>
<p>Fill out the information below if you want to subscribe to my free internet newsletter.</p>



<fieldset class="nolegend">
<p><label for="extra_name">Name:</label><br/>
<input type="text" id="extra_name" style="width: 99%;"
class="textfield" value="" name="extra_name"/></p>
</fieldset>



<fieldset class="nolegend">
<p><label for="extra_address1">Address 1:</label><br/>
<input type="text" id="extra_address1" style="width: 99%;"
class="textfield" value="" name="extra_address1"/></p>
</fieldset>



<fieldset class="nolegend">
<p><label for="extra_address2">Address 2:</label><br/>
<input type="text" id="extra_address2" style="width: 99%;"
class="textfield" value="" name="extra_address2"/></p>
</fieldset>



<fieldset class="nolegend">
<p><label for="extra_city">City:</label><br/>
<input type="text" id="extra_city" style="width: 50%;"
class="textfield" value="" name="extra_city"/></p>
</fieldset>



<fieldset class="nolegend">
<p><label for="extra_state">State:</label><br/>
<input type="text" id="extra_state" style="width: 30%;"
class="textfield" value="" name="extra_state"/></p>
</fieldset>



<fieldset class="nolegend">
<p><label for="extra_zip">Zip:</label><br/>
<input type="text" id="extra_zip" style="width: 30%;"
class="textfield" value="" name="extra_zip"/></p>
</fieldset>



<fieldset class="nolegend">
<p><label for="extra_email">Email:</label><br/>
<input type="text" id="extra_email" style="width: 99%;"
class="textfield" value="" name="extra_email"/></p>
</fieldset>



<fieldset class="nolegend">
<p><label for="extra_phone">Phone:</label><br/>
<input type="text" id="extra_phone" style="width: 70%;"
class="textfield" value="" name="extra_phone"/></p>
</fieldset>

<?php } ?>


One thing to note here is that the entire new section of the form is wrapped in <?php if ($this->inJoinFlow) { ?>. This means that it will only be visible when people first join the group. This is a good thing because 1) we aren't storing the values to be able to echo them back to the user when they edit their profile page, and 2) we don't want a new email sent every time they update their profile.



Profile Controller
The last step is to update /widgets/profiles/ProfileController.php so that we can trigger the email to be sent when a new profile is created. Find the action_save() method in the controller. After the call to $this->user->save(), there's an if/else block, and inside the else {} fragment, there is an if ($userIsJoining) {} block. Right after the line which includes the Messaging classes (require_once NF_APP_BASE . '/lib/XG_Message.php';), you can drop in your code to trigger the new message:

$opts = array();

$opts['body'] = "Contact Details: " . $_POST['extra_name'] . "\\r\\n" . $_POST['extra_address1'] . "\\r\\n" .
$_POST['extra_address2'] . "\\r\\n" . $_POST['extra_city'] . "\\r\\n" . $_POST['extra_zip'] .
"\\r\\n" . $_POST['extra_email'] . "\\r\\n" . $_POST['extra_phone'];
$opts['subject'] = "New Contact Details";
$from = $this->_user->screenName;
$to = XN_Application::load()->ownerName;

$msg = XG_Message_AdminNewProfile::create($opts);
$msg->send($to, $from);


Here we're setting the body of the email, which consists of the values of our form fields, along with the subject and from and to addresses. Then we send it off. Easy!

Views: 42

Comment

You need to be a member of Ning Developer Docs to add comments!

Join Ning Developer Docs

© 2024   Created by Ning Developer Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service