Home > Elgg Only, open source products > Javascript code to implement vaidation in Elgg Register

Javascript code to implement vaidation in Elgg Register

Javascript Code to Implement Validation in Elgg Registration :

Path : Views / Default / Account / Forms / Register.php.

************

Steps:

1.Include one extra field ‘js’=>’event”function name(parameter name)”’;

2.Write Corresponding function & javascript code in that php file


************

Code:

<script type=’text/javascript’>

function check(nam)

{

if(nam.value.length == 0)

{

alert(“Please Enter Display Name”);

return false;

}

else

{

alert(“OK….Fine!”);

return true;

}

}

</script>

<?php

/**

* Elgg register form

*

* @package Elgg

* @subpackage Core

* @author Curverider Ltd

* @link http://elgg.org/

*/

$username = get_input(‘u’);

$email = get_input(‘e’);

$name = get_input(‘n’);

$admin_option = false;

$loggedin_user = get_loggedin_user();

if ($loggedin_user && $loggedin_user->isAdmin() && isset($vars[‘show_admin’])) {

$admin_option = true;

}

$form_body = “<p><label>” . elgg_echo(‘name’) . “<br />” . elgg_view(‘input/text’ , array(internalname’ => ‘nam’, ‘class’ => “general-textarea”, ‘value’ => $name)) . “</label><br />”;

$form_body .= “<label>” . elgg_echo(’email’) . “<br />” . elgg_view(‘input/text’ , array(‘internalname’ => ’email’, ‘class’ => “general-textarea”, ‘value’ => $email)) . “</label><br />”;

$form_body .= “<label>” . elgg_echo(‘username’) . “<br />” . elgg_view(‘input/text’ , array(‘internalname’ => ‘username’, ‘value’ => $username)) . “</label><br />”;

$form_body .= “<label>” . elgg_echo(‘password’) . “<br />” . elgg_view(‘input/password’ , array(‘internalname’ => ‘password’, ‘class’ => “general-textarea”)) . “</label><br />”;

$form_body .= “<label>” . elgg_echo(‘passwordagain’) . “<br />” . elgg_view(‘input/password’ , array(‘internalname’ => ‘password2’, ‘class’ => “general-textarea”)) . “</label><br />”;

// view to extend to add more fields to the registration form

$form_body .= elgg_view(‘register/extend’);

// Add captcha hook

$form_body .= elgg_view(‘input/captcha’);

if ($admin_option) {

$form_body .= elgg_view(‘input/checkboxes’, array(‘internalname’ => “admin”, ‘options’ => array(elgg_echo(‘admin_option’))));

}

$form_body .= elgg_view(‘input/hidden’, array(‘internalname’ => ‘friend_guid’, ‘value’ => $vars[‘friend_guid’]));

$form_body .= elgg_view(‘input/hidden’, array(‘internalname’ => ‘invitecode’, ‘value’ => $vars[‘invitecode’]));

$form_body .= elgg_view(‘input/hidden’, array(‘internalname’ => ‘action’, ‘value’ => ‘register’));

$form_body .= elgg_view(‘input/submit’, array(‘internalname’ => ‘submit’, ‘value’ => elgg_echo(‘register’),‘js’ => ‘onClick=”check(nam)”‘)) . “</p>”;

?>

<div id=”register-box”>

<h2><?php echo elgg_echo(‘register’); ?></h2>

<?php echo elgg_view(‘input/form’, array(‘action’ => “{$vars[‘url’]}action/register”, ‘body’ => $form_body)) ?>

</div>

*****************

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: