HOW TO: Registration Form -- With "Terms" text and "I Agree" checkbox

A forum with Tips, tricks and small tutorials.

Moderators: mcsmom, unixboymd

Forum rules
Post Reply
dee_jay
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Tue Nov 14, 2006 12:20 am

HOW TO: Registration Form -- With "Terms" text and "I Agree" checkbox

Post by dee_jay » Wed Oct 03, 2007 12:27 pm

I made this mod because I needed this functionality and the options I could find were install Community Builder (very large) or JUser (commercial component) ... both of which are overkill for this relatively simple need.

This allows you to add "Terms and Conditions" to the Registration Form, and makes the user check an "I Agree" checkbox before the form is submitted. It validates that the box is checked, and prompts the user if it is unchecked.

There are three inserts to make to the registration.html.php file:

1. Insert your "Terms and Conditions" (indicated in red below)

2. Define your checkbox (indicated in red below)



       
            *
       
       
           
       
     
     
         
         
     
     
       
       
     


     
       
AGREEMENT TERMS

        Your text goes here..... and so on.
       
     







       
       
     


     

3. Add the checkbox validation in the field validation section (indicated in red below)

} else if ((form.password.value != "") && (form.password.value != form.password2.value)){
            alert( "" );
        } else if (r.exec(form.password.value)) {
            alert( "" );

   
   
        }  else if (form.IAgree.checked == false) {
            alert( "" );

       
       
        } else {
            form.submit();
        }
      }
     


That's it .... ! ! !
Last edited by dee_jay on Mon Nov 05, 2007 4:50 pm, edited 1 time in total.

Arjun Arya
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Tue Sep 25, 2007 2:44 pm

Re: HOW TO: Registration Form -- With "Terms" text and "I Agree" checkbox

Post by Arjun Arya » Tue Oct 23, 2007 8:00 am

Thanks Dee jay,

I really needed that.

Can you tell me on the same page, if I wanted to REMOVE the 1st field 'Name' and the 3rd field 'Email' and also remove their validation checks, what entries should I delete / modify ?

Thanks,

AA

Jim the Chin
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Apr 10, 2006 12:15 pm
Location: Cromer, Norfolk, UK

Re: HOW TO: Registration Form -- With "Terms" text and "I Agree" checkbox

Post by Jim the Chin » Sun Nov 04, 2007 7:16 am

Many thanks for this, DeeJay ... I've been looking for ages for this.

But, oh dear it doesn't work for me at http://jon-jackson.co.uk/registration.html - I've checked several times that I added your code correctly, went back and took it out (then it worked OK), tried again ... but no luck.  Is it possible I have an old version of the registration.html.php file?

My code is pasted below - any glaring errors please?

Code: Select all

<?php
/**
* @version $Id: registration.html.php 5930 2006-12-06 00:49:07Z friesengeist $
* @package Joomla
* @subpackage Users
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

/**
* @package Joomla
* @subpackage Users
*/
class HTML_registration {
   function lostPassForm($option) {
      // used for spoof hardening
      $validate = josSpoofValue();
      ?>
      <form action="index.php" method="post">

      <div class="componentheading">
         <?php echo _PROMPT_PASSWORD; ?>
      </div>

      <table cellpadding="0" cellspacing="0" border="0" width="100%" class="contentpane">
      <tr>
         <td colspan="2">
            <?php echo _NEW_PASS_DESC; ?>
         </td>
      </tr>
      <tr>
         <td>
            <?php echo _PROMPT_UNAME; ?>
         </td>
         <td>
            <input type="text" name="checkusername" class="inputbox" size="40" maxlength="25" />
         </td>
      </tr>
      <tr>
         <td>
            <?php echo _PROMPT_EMAIL; ?>
         </td>
         <td>
            <input type="text" name="confirmEmail" class="inputbox" size="40" />
         </td>
      </tr>
      <tr>
         <td colspan="2">
            <input type="submit" class="button" value="<?php echo _BUTTON_SEND_PASS; ?>" />
         </td>
      </tr>
      </table>
      
      <input type="hidden" name="option" value="<?php echo $option;?>" />
      <input type="hidden" name="task" value="sendNewPass" />
      <input type="hidden" name="<?php echo $validate; ?>" value="1" />
      </form>
      <?php
   }

   function registerForm($option, $useractivation) {
      // used for spoof hardening
      $validate = josSpoofValue();
      ?>
      <script language="javascript" type="text/javascript">
      function submitbutton_reg() {
         var form = document.mosForm;
         var r = new RegExp("[\<|\>|"|\'|\%|\;|\(|\)|\&|\+|\-]", "i");

         // do field validation
         if (form.name.value == "") {
            alert( "<?php echo addslashes( html_entity_decode(_REGWARN_NAME) );?>" );
         } else if (form.username.value == "") {
            alert( "<?php echo addslashes( html_entity_decode(_REGWARN_UNAME) );?>" );
         } else if (r.exec(form.username.value) || form.username.value.length < 3) {
            alert( "<?php printf( addslashes( html_entity_decode(_VALID_AZ09_USER) ), addslashes( html_entity_decode(_PROMPT_UNAME) ), 2 );?>" );
         } else if (form.email.value == "") {
            alert( "<?php echo addslashes( html_entity_decode(_REGWARN_MAIL) );?>" );
         } else if (form.password.value.length < 6) {
            alert( "<?php echo addslashes( html_entity_decode(_REGWARN_PASS) );?>" );
         } else if (form.password2.value == "") {
            alert( "<?php echo addslashes( html_entity_decode(_REGWARN_VPASS1) );?>" );
         } else if ((form.password.value != "") && (form.password.value != form.password2.value)){
            alert( "<?php echo addslashes( html_entity_decode(_REGWARN_VPASS2) );?>" );
         } else if (r.exec(form.password.value)) {
            alert( "<?php printf( addslashes( html_entity_decode(_VALID_AZ09) ), addslashes( html_entity_decode(_REGISTER_PASS) ), 6 );?>" );
         } else if (form.inputbox.IAgree.checked == false) {
               alert( "<?php echo 'Please check the I AGREE checkbox';?>" );
         } else {
            form.submit();
         }
      }
      </script>
      <form action="index.php" method="post" name="mosForm">

      <div class="componentheading">
         <?php echo _REGISTER_TITLE; ?>
      </div>

      <table cellpadding="0" cellspacing="0" border="0" width="100%" class="contentpane">
      <tr>
         <td colspan="2"><?php echo _REGISTER_REQUIRED; ?></td>
      </tr>
      <tr>
         <td width="30%">
            <?php echo _REGISTER_NAME; ?> *
         </td>
           <td>
              <input type="text" name="name" size="40" value="" class="inputbox" maxlength="50" />
           </td>
      </tr>
      <tr>
         <td>
            <?php echo _REGISTER_UNAME; ?> *
         </td>
         <td>
            <input type="text" name="username" size="40" value="" class="inputbox" maxlength="25" />
         </td>
      </tr>
      <tr>
         <td>
            <?php echo _REGISTER_EMAIL; ?> *
         </td>
         <td>
            <input type="text" name="email" size="40" value="" class="inputbox" maxlength="100" />
         </td>
      </tr>
      <tr>
         <td>
            <?php echo _REGISTER_PASS; ?> *
         </td>
           <td>
              <input class="inputbox" type="password" name="password" size="40" value="" />
           </td>
      </tr>
      <tr>
         <td>
            <?php echo _REGISTER_VPASS; ?> *
         </td>
         <td>
            <input class="inputbox" type="password" name="password2" size="40" value="" />
         </td>
      </tr>
      <tr>
           <td colspan="2">
           </td>
      </tr>
      <tr>
         <td colspan=2>
         </td>
      </tr>
        <!-- Text addition -->
      <tr>
         <td colspan=2><br /> AGREEMENT TERMS<br>
         Your text goes here..... and so on.
         </td>
      </tr>

<!-- Add the checkbox   -->
<tr>
<td colspan=2> <BR />
 <input type="checkbox" name="IAgree" class="inputbox" value="yes" alt="I Agree" />
        <?php echo "I AGREE" ?>
         </td>
      </tr>
      </table>

      <input type="hidden" name="id" value="0" />
      <input type="hidden" name="gid" value="0" />
      <input type="hidden" name="useractivation" value="<?php echo $useractivation;?>" />
      <input type="hidden" name="option" value="<?php echo $option; ?>" />
      <input type="hidden" name="task" value="saveRegistration" />
      <input type="button" value="<?php echo _BUTTON_SEND_REG; ?>" class="button" onclick="submitbutton_reg()" />
      <input type="hidden" name="<?php echo $validate; ?>" value="1" />
      </form>
      <?php
   }
}
?>

toolcrazy

Re: HOW TO: Registration Form -- With "Terms" text and "I Agree" checkbox

Post by toolcrazy » Mon Nov 05, 2007 5:53 am

I get the exact results as you. Everything works till it reaches the terms verify, then dies.

dee_jay
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Tue Nov 14, 2006 12:20 am

Re: HOW TO: Registration Form -- With "Terms" text and "I Agree" checkbox

Post by dee_jay » Mon Nov 05, 2007 2:45 pm

Hi ....

Try ....    (form.IAgree.checked == false)    take out .inputbox


.... let me know if that works.

Jim the Chin
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Apr 10, 2006 12:15 pm
Location: Cromer, Norfolk, UK

Re: HOW TO: Registration Form -- With "Terms" text and "I Agree" checkbox

Post by Jim the Chin » Mon Nov 05, 2007 3:27 pm

Works for me.  Thanks DeeJay you're a star!

dee_jay
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Tue Nov 14, 2006 12:20 am

Re: HOW TO: Registration Form -- With "Terms" text and "I Agree" checkbox

Post by dee_jay » Mon Nov 05, 2007 4:52 pm

whew ...  glad to hear that !!!

I don't know what happened there ..... I may have mistakenly uploaded the wrong version. ???

I have changed the code in the original post.

ayushpant
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Sat Jun 09, 2007 12:15 am

Re: HOW TO: Registration Form -- With "Terms" text and "I Agree" checkbox

Post by ayushpant » Fri Nov 09, 2007 9:20 am

Or, just buy JSUER extension. Its awesome!!!

Jim the Chin
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Apr 10, 2006 12:15 pm
Location: Cromer, Norfolk, UK

Re: HOW TO: Registration Form -- With "Terms" text and "I Agree" checkbox

Post by Jim the Chin » Sat Feb 09, 2008 7:31 am

Hi

A further thought on this Subject ... on the confirmation email how would you include the 'agreement' detail?

ScrapbookSupplies
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Thu Dec 13, 2007 10:48 pm
Contact:

Re: HOW TO: Registration Form -- With

Post by ScrapbookSupplies » Thu Feb 14, 2008 4:46 am

I was wondering.... Have you noticed if this little checkbox detours spambots from registering?

We recently bridged our phpBB forum and Joomla, and by doing so we no longer have our spam mods that we used when users were registering through phpBB.

And actually, now that I am asking.... The one mod that really worked was the VIP mod that required new member's to enter a pre-determined word on the registration form. We posted this word on the forum in an announcement box and a forum thread. So, could this form be adjusted to include a mandatory text box that the user had to fill in, with a certain word?

This is the phpBB mod, could it be altered to fit with the terms & conditions checkbox?
#-----[ OPEN ]------------------------------------------
#

includes/usercp_register.php


#
#-----[ FIND ]------------------------------------------
#

rawurlencode($website);
}

#
#-----[ AFTER, ADD ]------------------------------------------
#

// Start myVIPcode mod
if ( ($mode == 'register') && ($HTTP_POST_VARS['myVIPcode'] != '2486') )
{
message_die(GENERAL_MESSAGE, 'Sorry, but your <b>VIP code</b> is NOT correct.<br><br>You can find a valid <b>VIP code</b> on our homepage.');
}
// End myVIPcode mod

#
#-----[ FIND ]------------------------------------------
#

$template->assign_block_vars('switch_confirm', array());
}

#
#-----[ AFTER, ADD ]------------------------------------------
#

// Start myVIPcode mod
if ($mode == 'register')
{
$template->assign_block_vars('switch_myvipcode', array());
}
// End myVIPcode mod

#
#-----[ OPEN ]------------------------------------------
#

templates/subSilver/profile_add_body.tpl

#
#-----[ FIND ]------------------------------------------
#

<!-- END switch_confirm -->

#
#-----[ AFTER, ADD ]------------------------------------------
#

<!-- BEGIN switch_myvipcode -->
<tr>
<td class="row1"><span class="gen"><b>VIP code:</b> *</span><br />
<span class="gensmall">You can find a valid <b>VIP code</b> on our homepage!</span></td>
<td class="row2">
<input type="text" class="post" style="width: 200px" name="myVIPcode" size="25" maxlength="32" value="" />
</td>
</tr>
<!-- END switch_myvipcode -->

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM
ScrapbookSuppliesDirect.com

xlguide_dk

Re: HOW TO: Registration Form -- With

Post by xlguide_dk » Wed Feb 20, 2008 3:01 pm

This sounds like just what I'm looking for. Can this also be implemented in the login page of the FIREBOARD FORUM component. I havn't published the USER MENU because I want all visitors to be able to see the FORUM, and users only have to register in order to submit something to the FIREBOARD FORUM. So if I could place the terms & conditions with a Check box in this component it would be great.

Has anyone tried this before or know where to start?

xlguide_dk

Re: HOW TO: Registration Form -- With

Post by xlguide_dk » Fri Feb 29, 2008 12:37 pm

[quote="xlguide_dk"]This sounds like just what I'm looking for. Can this also be implemented in the login page of the FIREBOARD FORUM component. I havn't published the USER MENU because I want all visitors to be able to see the FORUM, and users only have to register in order to submit something to the FIREBOARD FORUM. So if I could place the terms & conditions with a Check box in this component it would be great.

Has anyone tried this before or know where to start?[/quote]

Solved the issue...it helped to look at the supplied coding in the trail. I was looking in the wrong component file. Thought I had to change it in the com_FB but found the com_registration. It works great...thanks.


Post Reply