forum.coppermine-gallery.net

Support => cpg1.4.x Support => Older/other versions => cpg1.4 miscellaneous => Topic started by: studeo on October 08, 2006, 06:07:03 am

Title: field required at registration
Post by: studeo on October 08, 2006, 06:07:03 am
Hi:

I have searched through the help and topic files but I have not found exactly what I am looking for.

Tonight I received an email as admin for a new user registration. I have set my cpg up to notify me and I will be responsible for activating the user (its a family site). This person only gave a user name.

I would like to make the location field and email field as well as an optional Full Name field I have added to profile line 5 a *required* field so I might know who this is trying to register. I have found various posts addressing javascripts, etc. but cound not find a definitive addition to make these fields required. Can you offer any suggestions? I will gladly pay my one karma point for this answer :)

Maybe someone can point me to a link if already aswered somewhere.

Thank you.
Title: Re: field required at registration
Post by: studeo on October 09, 2006, 12:56:16 am
Is this too tough a question?
Title: Re: field required at registration
Post by: Sami on October 09, 2006, 06:28:30 am
Javascript would be the simple way
- Disabling the submit button until *required* fields have value
Title: Re: field required at registration
Post by: studeo on October 09, 2006, 03:25:11 pm
Where would you say in the code that I would find and put in a javascript? I have to admit I am an html designer just learning about php and others...I'm used to looking at html code pages but I get a bit lost still in php without edit hints.

Thanks in advance
Title: Re: field required at registration
Post by: Sami on October 09, 2006, 03:40:28 pm
Take a look at register.php
That file will:
- create registration form
- validate inputs
- insert , inputs to DB
so you should put your JS to this file on form creation part
Title: Re: field required at registration
Post by: studeo on October 09, 2006, 05:46:27 pm
Thank you. I have been looking at register.php all morning and sadly I have to admit I have no clue where and what to add. I'm sorry to bother you again but can you provide more detailed information to accomplish this?

Thanks
Title: Re: field required at registration
Post by: Sami on October 09, 2006, 06:00:27 pm
Can you write a JS to disable the form (button) until required field got filled?
You wrote it and I'll let you know where to put it ;)
Title: Re: field required at registration
Post by: studeo on October 09, 2006, 06:27:24 pm
No I can't But I had found this code from Paver to require an image title to be submitted so I would think that it needs to be modified to require the registrar's email addess and my user field #5 titled 'Full Name' to be entered before submit.

Thanks for hanging in there with me and maybe you can help me tweak this js code. I wish I could write code like you can.


Code: [Select]
function open_form($path) {

    echo <<<EOT
    <script language="javascript" type="text/javascript">
    function textCounter(field, maxlimit) {
            if (field.value.length > maxlimit) // if too long...trim it!
            field.value = field.value.substring(0, maxlimit);
    }
    function ValidateForm(form) {
            title = form.title.value;
            title = title.replace(/^\s*/, '').replace(/\s*$/, '');
            if (title.length == 0) {
alert("You must enter a title."); // not language-compatible
form.title.focus();
return false;
            }
            return true;
    }
    </script>
    <form method="post" action="$path" enctype="multipart/form-data" name="upload_form" onSubmit="javascript:return ValidateForm(this)">
EOT;
}
Title: Re: field required at registration
Post by: Sami on October 09, 2006, 07:15:02 pm
I take back my previous suggestion , I think there could be an easy way without injecting any JS code ;)
Right now I should go, but I'll post instruction when I come back (maybe other supporter post it before me )
Title: Re: field required at registration
Post by: studeo on October 09, 2006, 10:45:32 pm
As a related issue, when we make the *required* fields effective, I would like to include the *email* field, and the Full Name field into the activation email I receive as admin. I find the code {USER_NAME} is include in there so how will I add the email field and the user field #5?

Thanks
Title: Re: field required at registration
Post by: Sami on October 10, 2006, 03:34:40 pm
Okey , Lets try to set FullName (custom field 5 for user Profile) as a mandatory field on registration:

- First you should go to config page and put FullName  on Profile 5 name (config=>Custom fields for user profile =>Profile 5 name)

- Open register.php from gallery root , around line 69~82 you  will find this:

Code: [Select]
    $form_data = array(
        array('label', $lang_register_php['required_info']),
        array('input', 'username', $lang_register_php['username'], 25),
        array('password', 'password', $lang_register_php['password'], 25),
        array('password', 'password_verification', $lang_register_php['password_again'], 25),
        array('input', 'email', $lang_register_php['email'], 255),
array('label', $lang_register_php['optional_info']),
                array('input', 'user_profile1', $CONFIG['user_profile1_name'], 255),
                array('input', 'user_profile2', $CONFIG['user_profile2_name'], 255),
                array('input', 'user_profile3', $CONFIG['user_profile3_name'], 255),
                array('input', 'user_profile4', $CONFIG['user_profile4_name'], 255),
                array('input', 'user_profile5', $CONFIG['user_profile5_name'], 255),
               array('textarea', 'user_profile6', $CONFIG['user_profile6_name'], 255)
        );


Replace it with

Code: [Select]
    $form_data = array(
        array('label', $lang_register_php['required_info']),
        array('input', 'username', $lang_register_php['username'], 25),
        array('password', 'password', $lang_register_php['password'], 25),
        array('password', 'password_verification', $lang_register_php['password_again'], 25),
        array('input', 'email', $lang_register_php['email'], 255),
        array('input', 'user_profile5', $CONFIG['user_profile5_name'], 255),// Added for fullname mandatory Mod
array('label', $lang_register_php['optional_info']),
                array('input', 'user_profile1', $CONFIG['user_profile1_name'], 255),
                array('input', 'user_profile2', $CONFIG['user_profile2_name'], 255),
                array('input', 'user_profile3', $CONFIG['user_profile3_name'], 255),
                array('input', 'user_profile4', $CONFIG['user_profile4_name'], 255),
//              array('input', 'user_profile5', $CONFIG['user_profile5_name'], 255), // Commented for fullname mandatory Mod
               array('textarea', 'user_profile6', $CONFIG['user_profile6_name'], 255)
        );

- Around line 222~228 you will find this:

Code: [Select]
    $email = trim(get_post_var('email'));
        $profile1 = addslashes($_POST['user_profile1']);
        $profile2 = addslashes($_POST['user_profile2']);
        $profile3 = addslashes($_POST['user_profile3']);
        $profile4 = addslashes($_POST['user_profile4']);
        $profile5 = addslashes($_POST['user_profile5']);
$profile6 = addslashes($_POST['user_profile6']);

Replace it with this:

Code: [Select]
    $email = trim(get_post_var('email'));
    $profile5 = trim(get_post_var('user_profile5')); // Added for fullname mandatory Mod
        $profile1 = addslashes($_POST['user_profile1']);
        $profile2 = addslashes($_POST['user_profile2']);
        $profile3 = addslashes($_POST['user_profile3']);
        $profile4 = addslashes($_POST['user_profile4']);
//      $profile5 = addslashes($_POST['user_profile5']); // Commented for fullname mandatory Mod
$profile6 = addslashes($_POST['user_profile6']);

- Put this

Code: [Select]
    if (utf_strlen($profile5) < 2) $error .= '<li>' . "Full name must be 2 characters long minimum"; // Added for fullname mandatory Mod

 right after this(around line 241~242):

Code: [Select]
    if ($password != $password_again) $error .= '<li>' . $lang_register_php['err_password_mismatch'];

Now you are Done ....
Title: Re: field required at registration
Post by: studeo on October 10, 2006, 03:58:33 pm
Thank you for the reply. I have changed/added your code to my register.php page.

Quote
First you should go to config page and put FullName  on Profile 5 name (config=>Custom fields for user profile =>Profile 5 name)

Are you referring to the config.php page in the root or some section in another document? When this is clarified I will run a test. Thanks Sami!

EDIT: I went ahead and tested this without resolving you first comment about config and all seems to work as expected. I could not register without filling out the the name, password, email and full name lines. I would like the admin activation email to include the fields 'email' and 'full name' as I mention earlier.  Thank you very much!!!!!
Title: Re: field required at registration
Post by: Sami on October 10, 2006, 04:06:18 pm
just login as an admin , click on config button and go to custom fields for user profile ... section and set the profile 5 name to Fullname
Title: Re: field required at registration
Post by: studeo on October 10, 2006, 04:09:48 pm
Thanks. Does 'Fullname' mean that cpg expects to find this field title as one word? As opposed to 'Full Name'  ?
Title: Re: field required at registration
Post by: Sami on October 10, 2006, 04:15:17 pm
No it's okey put there anything you want ;)
Title: Re: field required at registration
Post by: Sami on October 10, 2006, 04:18:03 pm
And now we are going to put Full name and user e-mail address to admin activation mail :

- Open Register.php from gallery root , around line 317~323 you will find:

Code: [Select]
                                                        $template_vars = array(
                                                                        '{SITE_NAME}' => $CONFIG['gallery_name'],
                                                                        '{USER_NAME}' => $user_name,
                                                                        '{ACT_LINK}' => $act_link,
        );

Replace it with this

Code: [Select]
                                                        $template_vars = array(
                                                                        '{SITE_NAME}' => $CONFIG['gallery_name'],
                                                                        '{USER_NAME}' => $user_name,
                                                                        '{ACT_LINK}' => $act_link,
        '{USER_MAIL}' => $email,// Added for Fullname mandatory Mod
        '{USER_FULLNAME}' => $profile5,// Added for Fullname mandatory Mod
                                                        );

- Open english.php from {gallery root}/lang, around line 1559 ~1570 you will find this:

Code: [Select]
$lang_register_approve_email = <<<EOT
A new user with the username "{USER_NAME}" has registered in your gallery.

In order to activate the account, you need to click on the link below or copy and paste it in your web browser.

<a href="{ACT_LINK}">{ACT_LINK}</a>

EOT;

Replace it with this:

Code: [Select]
$lang_register_approve_email = <<<EOT
A new user with

the username "{USER_NAME}"

and FullName "{USER_FULLNAME}"

and E-mail Address "{USER_MAIL}"

has registered in your gallery.

In order to activate the account, you need to click on the link below or copy and paste it in your web browser.

<a href="{ACT_LINK}">{ACT_LINK}</a>

EOT;

And now you are done !

I didn't test it yet but it should work AFAIK , check it and confirm .... ;)
Title: Re: field required at registration
Post by: studeo on October 10, 2006, 04:27:17 pm
Sami...

Thank you very much for the assistance. Everything works as expected.
People with family photo sites might like the extra security info in order allow users in.

Again, Thank you!

Studeo
Title: Re: field required at registration
Post by: loubymar on October 16, 2006, 07:16:23 pm
My Gallery is at: http://www.anastaciaisgreatgallery.co.nr (http://www.anastaciaisgreatgallery.co.nr)
Coppermine version: 1.4.8

Instead of having the full name i changed it to date of birth, but when users register they can enter just their year e.g. 1990, but i want them to enter their full date of birth, e.g. 06/09/1990 is they away of doing this plz??
Title: Re: field required at registration
Post by: Sami on October 16, 2006, 07:51:33 pm
You can use regular expression on this line :
Code: [Select]
if (utf_strlen($profile5) < 2) $error .= '<li>' . "Full name must be 2 characters long minimum"; // Added for fullname mandatory Mod

[Edit]
something like this could help you :
Replace this:

Code: [Select]
if (utf_strlen($profile5) < 2) $error .= '<li>' . "Full name must be 2 characters long minimum"; // Added for fullname mandatory Mod

with this:
Code: [Select]
if (utf_strlen($profile5) < 8 || !eregi("^([0-9]{2})+/+([0-9]{2})+/+[0-9]{4}$",$profile5)) $error .= '<li>' . "Birthday must be like this 16/09/2000 "; // Added for fullname mandatory Mod
Title: Re: field required at registration
Post by: hozyali on July 28, 2008, 09:09:46 pm
Hello,

I know this is an old topic but this is exactly what I need.

I wanted to make a few custom fields mandatory and I did the same as Sami described. But if I submit the form all empty, I get this error.
Code: [Select]
Script called without the required parameter(s). (user_profile5)
I doubled checked the register.php file to make sure I did everything correctly as specified. but it didn't help.
I am using version 1.4.8

Thanks
Title: Re: field required at registration
Post by: Joachim Müller on July 28, 2008, 10:02:34 pm
You should know my reply already: post a link to the page you're refering to. I've told you so often that it hurts. When will you learn to post your questions properly?
Title: Re: field required at registration
Post by: digof on October 19, 2008, 05:20:59 am
How Can I make the custom field: "GENDER" that I made, SELECTABLE? So people can only choose one: male/female or man/woman? Not write one of them in the field?
I already made custom fields nr 1, 2 and 3 mandatory as for your instruction:
In admin. mode I created the fields Birthday, Gender and State

In register.php


this Code:
Code:
Code: [Select]
    $form_data = array(
        array('label', $lang_register_php['required_info']),
        array('input', 'username', $lang_register_php['username'], 25),
        array('password', 'password', $lang_register_php['password'], 25),
        array('password', 'password_verification', $lang_register_php['password_again'], 25),
        array('input', 'email', $lang_register_php['email'], 255),
array('label', $lang_register_php['optional_info']),
                array('input', 'user_profile1', $CONFIG['user_profile1_name'], 255),
                array('input', 'user_profile2', $CONFIG['user_profile2_name'], 255),
                array('input', 'user_profile3', $CONFIG['user_profile3_name'], 255),
                array('input', 'user_profile4', $CONFIG['user_profile4_name'], 255),
                array('input', 'user_profile5', $CONFIG['user_profile5_name'], 255),
               array('textarea', 'user_profile6', $CONFIG['user_profile6_name'], 255)
        );

I Replaced it with:
Code:
Code: [Select]
    $form_data = array(
        array('label', $lang_register_php['required_info']),
        array('input', 'username', $lang_register_php['username'], 25),
        array('password', 'password', $lang_register_php['password'], 25),
        array('password', 'password_verification', $lang_register_php['password_again'], 25),
        array('input', 'email', $lang_register_php['email'], 255),
        array('input', 'user_profile1', $CONFIG['user_profile1_name'], 255),// Added for fullname mandatory Mod
        array('input', 'user_profile2', $CONFIG['user_profile2_name'], 255),// Added for fullname mandatory Mod
        array('input', 'user_profile3', $CONFIG['user_profile3_name'], 255),// Added for fullname mandatory Mod
array('label', $lang_register_php['optional_info']),
//              array('input', 'user_profile1', $CONFIG['user_profile1_name'], 255), // Commented for fullname mandatory Mod
//              array('input', 'user_profile2', $CONFIG['user_profile2_name'], 255), // Commented for fullname mandatory Mod
//              array('input', 'user_profile3', $CONFIG['user_profile3_name'], 255), // Commented for fullname mandatory Mod
                array('input', 'user_profile4', $CONFIG['user_profile4_name'], 255),
                array('input', 'user_profile5', $CONFIG['user_profile5_name'], 255),
               array('textarea', 'user_profile6', $CONFIG['user_profile6_name'], 255)
        );

this code:
Code:
Code: [Select]
    $email = trim(get_post_var('email'));
        $profile1 = addslashes($_POST['user_profile1']);
        $profile2 = addslashes($_POST['user_profile2']);
        $profile3 = addslashes($_POST['user_profile3']);
        $profile4 = addslashes($_POST['user_profile4']);
        $profile5 = addslashes($_POST['user_profile5']);
$profile6 = addslashes($_POST['user_profile6']);

replaced with:
Code:
   
Code: [Select]
$email = trim(get_post_var('email'));
    $profile1 = trim(get_post_var('user_profile1')); // Added for fullname mandatory Mod
    $profile2 = trim(get_post_var('user_profile2')); // Added for fullname mandatory Mod
    $profile3 = trim(get_post_var('user_profile3')); // Added for fullname mandatory Mod
//      $profile1 = addslashes($_POST['user_profile1']); // Commented for fullname mandatory Mod
//      $profile2 = addslashes($_POST['user_profile2']); // Commented for fullname mandatory Mod
//      $profile3 = addslashes($_POST['user_profile3']); // Commented for fullname mandatory Mod
        $profile4 = addslashes($_POST['user_profile4']);
        $profile5 = addslashes($_POST['user_profile5']);
$profile6 = addslashes($_POST['user_profile6']);

after this Code:
Code:
Code: [Select]
    if ($password != $password_again) $error .= '<li>' . $lang_register_php['err_password_mismatch'];
I ADDED this code:

Code:
Code: [Select]
    if (utf_strlen($profile1) < 8 || !eregi("^([0-9]{2})+/+([0-9]{2})+/+[0-9]{4}$",$profile1)) $error .= '<li>' . "Birthday must

be like this-16/09/2000 "; // Added for fullname mandatory Mod
    if (utf_strlen($profile2) < 2) $error .= '<li>' . "Gender"; // Added for fullname mandatory Mod
    if (utf_strlen($profile3) < 2) $error .= '<li>' . "Parents"; // Added for fullname mandatory Mod

replaced this code (second appearance of this code):
Code:
Code: [Select]
                                                        $template_vars = array(
                                                                        '{SITE_NAME}' => $CONFIG['gallery_name'],
                                                                        '{USER_NAME}' => $user_name,
                                                                        '{ACT_LINK}' => $act_link,
        );
with this code:
Code:
Code: [Select]
                                                        $template_vars = array(
                                                                        '{SITE_NAME}' => $CONFIG['gallery_name'],
                                                                        '{USER_NAME}' => $user_name,
                                                                        '{ACT_LINK}' => $act_link,
        '{USER_MAIL}' => $email, // Added for Fullname mandatory Mod
        '{Birthday}' => $profile1, // Added for Fullname mandatory Mod
        '{Gender}' => $profile2, // Added for Fullname mandatory Mod
        '{State}' => $profile3, // Added for Fullname mandatory Mod
                                                        );
And in Lang/english.php

this code:
Code:
Code: [Select]
$lang_register_approve_email = <<<EOT
A new user with the username "{USER_NAME}" has registered in your gallery.

In order to activate the account, you need to click on the link below or copy and paste it in your web browser.

<a href="{ACT_LINK}">{ACT_LINK}</a>

EOT;

Replaced with this
Code:
Code: [Select]
$lang_register_approve_email = <<<EOT
A new user with

the username: {USER_NAME}
E-mail Address {USER_MAIL}
Birthday: {Birthday}
Gender: {Gender}
State: {State}

has registered in your gallery.

In order to activate the account, you need to click on the link below or copy and paste it in your web browser.

<a href="{ACT_LINK}">{ACT_LINK}</a>

EOT;

Everything is working fine but I want people to click on MALE OR FEMALE, instead of writing
Title: Re: field required at registration
Post by: Joachim Müller on October 19, 2008, 02:47:48 pm
Don't double-post (http://forum.coppermine-gallery.net/index.php/topic,55822.0.html)!