Page 1 of 1

PHP - signup page (warning! noob coder!!)

Posted: Tue Feb 09, 2010 7:54 pm
by churd
Actually, please disregard this post... I'm realizing that all of the processing that takes place happens within the libraries that are being pulled in.

Sorry! And, thanks for reading... I'm sure I'll be bring other questions to the forum :) .



(disregard the original post:)

I'm going to try and cover ground quickly here, so I'll start off with a punch list.

1) It's a pleasure to meet all of you! This certainly seems like an amazing forum, and I hope very much so that I can not only learn but (hopefully!) in the future contribute to it as well.

2) This is week 1 for me in terms of exposure to php... everybody keeps saying that if you know HTML, then you can figure out PHP. They forgot to mention that if your focus within PHP is database driven, then forget the aforementioned correleation :) . Aka; I am almost completely and totally lost.

3) I am working on a website in which I have a very short runway to make alot of changes and progress. Mostly what I have to work with right now are templated scripts, that I am trying to learn and modify for my purposes.

4) If I begin supplying too much information, please tell me and stop me... I know everyone here is posting out of the kindness of their hearts, so pleaes let me know if I am over-stepping forum boundaries.

Now to the coding itself... I am working on a signup page (a templated script). The url to the signup page is: http://churd.ath.cx/can/phpmembers/signup.php

I have added the fields: First Name , Last Name, Address , City , State , Zip . Email (1+2) and Password (1+2) already existed in the template.

I cannot for the LIFE of me, figure out where within the following code that regulates the signup page, the email and password variables are sent to the MySQL database that is running... I have created the forms (as you can see) but I have not been able to get the forms to submit to the database.

Code: Select all

<?php
/*
 * init web page
 */
include_once("./lib/config.inc.php");
include_once("./lib/database.inc.php");
include_once("./lib/page.class.php");
include_once("./lib/menu.block.php"); // load menu function
$page = new umPage(); // create page object
$page->get_language(); // get language id from client site
include_once("./languages/".$cfg['language'].".php"); // load language file
$page->template = "./templates/".$cfg['language']."/default.html"; // load template
 
include_once("./lib/user.class.php");
include_once("./lib/email.inc.php");
include_once("./lib/phpmailer/class.phpmailer.php");
include_once("./lib/phpmailer/class.smtp.php");
include_once("./lib/antispam.functions.php");
$con = connect_database();
/*
 * create content blocks
 * page is built in this part
 */
$page->blocks['title'] = $lang['title']['signUp'];
$page->blocks['menu'] = get_menu(1);
$page->blocks['folder'] = $cfg['site']['folder'];
$page->blocks['selectLanguage'] = $page->build_language_form();
 
if($cfg['site']['openSignUp']){
    if(isset($_POST['email'])){
        trim_post_value();
        $errorMessage = "";
        $errorMessage = validate_post_value();
        if($errorMessage == ""){
            // create new user
            $user = new umUser();
            $user->email = $_POST['email'];
            $user->first_name = $_POST['first_name'];
            $user->emailVerified = 0;
            $user->verificationCode = $user->generate_verification_code();
            $user->password = md5($_POST['password']);
            $user->createTime = date("Y-m-d H:i:s");
            if($cfg['site']['autoEnable']){
                $user->status = 1;
            }else{
                $user->status = 0;
            }
            if($user->create_user(true)){
                // user was created successfully
                if($cfg['site']['requireVerification']){
                    // send verification email
                    $emailTags = array();
                    $emailTags['siteName'] = $cfg['site']['name'];
                    $emailTags['siteURL'] = $cfg['site']['url'];
                    $emailTags['systemURL'] = $cfg['site']['url'].$cfg['site']['folder'];
                    $emailTags['link'] = $cfg['site']['url'].$cfg['site']['folder']."verify.php?id=".$user->userID."&code=".$user->verificationCode;
                    sendTemplateEmail(
                        $cfg['email']['systemEmail'],
                        $cfg['site']['name'],
                        $cfg['email']['systemEmail'],
                        $user->email,
                        "",
                        "./templates/".$cfg['language']."/emails/welcome_verify.txt",
                        $emailTags
                    );
                    $page->blocks['content'] = show_message($lang['text']['createUserSuccessfullyEmail']);
                }else{
                    // send welcome email
                    $emailTags = array();
                    $emailTags['siteName'] = $cfg['site']['name'];
                    $emailTags['siteURL'] = $cfg['site']['url'];
                    $emailTags['systemURL'] = $cfg['site']['url'].$cfg['site']['folder'];
                    $emailTags['link'] = $cfg['site']['url'].$cfg['site']['folder']."login.php";
                    sendTemplateEmail(
                        $cfg['email']['systemEmail'],
                        $cfg['site']['name'],
                        $cfg['email']['systemEmail'],
                        $user->email,
                        "",
                        "./templates/".$cfg['language']."/emails/welcome.txt",
                        $emailTags
                    );
                    $page->blocks['content'] = show_message(sprintf($lang['text']['createUserSuccessfully'], $cfg['site']['folder']));
                }
            }else{
                // failed to create new user
                $page->blocks['content'] = show_message($lang['text']['createUserFailed']);
            }
        }else{
            $page->blocks['content'] = build_form($lang['formTitle']['signUp'], $errorMessage);
        }
    }else{
        init_post_value();
        $page->blocks['content'] = build_form($lang['formTitle']['signUp']);
    }
}else{
    $page->blocks['content'] = show_message($lang['text']['signUpClose']);
}
 
/*
 * construct and print page
 */
$page->construct_page(); // construct html page
$page->output_page(); // output page
 
close_database($con);
 
/*
* ============================================== page complete here ==============================================
* The following functions construct content for this page
*/
 
/*
* show message
*/
function show_message($messageText){
    $html = "";
    $html .= "<div style=\"margin: 20px; height: 300px\">";
    $html .= $messageText;
    $html .= "</div>";
    return $html;
}
 
/*
* build form of this page
*/
function build_form($formTitle, $errorMessage = ""){
    global $lang;
    global $cfg;
    $html = "";
    $html .= "<div class=\"formDiv\">";
    $html .= "<form action=\"".$cfg['site']['folder']."signup.php\" method=\"post\" onSubmit=\"return disablePage();\" class=\"formLayer\">";
    $html .= "<fieldset>";
    $html .= "<legend>".htmlspecialchars($formTitle)."</legend>";
    if($errorMessage != ""){
        $html .= "<ul id=\"errorMessage\">".$lang['text']['errorsFoundList'].$errorMessage."</ul>";
    }else{
        $html .= "<br>";
    }
    //see ending comment below
    $html .= "<label>";
    $html .= $lang['field']['yourfname'];
    $html .= "</label>";
    $html .= "<input type=\"text\" name=\"first_name\" value=\"".htmlspecialchars($_POST['first_name'])."\" size=\"50\">";
    $html .= "<br>";
    
    $html .= "<label>";
    $html .= $lang['field']['yourlname'];
    $html .= "</label>";
    $html .= "<input type=\"text\" name=\"last_name\" value=\"".htmlspecialchars($_POST['last_name'])."\" size=\"50\">";
    $html .= "<br>";
    
    $html .= "<label>";
    $html .= $lang['field']['youraddress'];
    $html .= "</label>";
    $html .= "<input type=\"text\" name=\"address\" value=\"".htmlspecialchars($_POST['address'])."\" size=\"50\">";
    $html .= "<br>";
    
    $html .= "<label>";
    $html .= $lang['field']['yourcity'];
    $html .= "</label>";
    $html .= "<input type=\"text\" name=\"city\" value=\"".htmlspecialchars($_POST['city'])."\" size=\"50\">";
    $html .= "<br>";
    
    $html .= "<label>";
    $html .= $lang['field']['yourstate'];
    $html .= "</label>";
    $html .= "<input type=\"text\" name=\"state\" value=\"".htmlspecialchars($_POST['state'])."\" size=\"50\">";
    $html .= "<br>";
    
    $html .= "<label>";
    $html .= $lang['field']['yourzip'];
    $html .= "</label>";
    $html .= "<input type=\"text\" name=\"zip\" value=\"".htmlspecialchars($_POST['zip'])."\" size=\"50\">";
    $html .= "<br>";
    //the above fields were added by Caleb - 020910
    
    $html .= "<label>";
    $html .= $lang['field']['yourEmail'];
    $html .= "</label>";
    $html .= "<input type=\"text\" name=\"email\" value=\"".htmlspecialchars($_POST['email'])."\" size=\"50\">";
    $html .= "<br>";
    $html .= "<label>";
    $html .= $lang['field']['retypeEmail'];
    $html .= "</label>";
    $html .= "<input type=\"text\" name=\"email2\" value=\"".htmlspecialchars($_POST['email2'])."\" size=\"50\">";
    $html .= "<br>";
    $html .= "<label>";
    $html .= $lang['field']['password'];
    $html .= "</label>";
    $html .= "<input type=\"password\" name=\"password\" value=\"\" size=\"25\">";
    $html .= "<br>";
    $html .= "<label>";
    $html .= $lang['field']['retypePassword'];
    $html .= "</label>";
    $html .= "<input type=\"password\" name=\"password2\" value=\"\" size=\"25\">";
    $html .= "<br>";
    if(show_antispam_code()){
        $aCode = get_antispam_code();
        $html .= "<label>";
        $html .= $lang['field']['typeCode'];
        $html .= "</label>";
        $html .= "<input type=\"text\" name=\"aCode\" value=\"\" size=\"10\"> ";
        $html .= "<img src=\"".$cfg['site']['folder']."code_image.php?id=".$aCode."\" align=\"absmiddle\">";
        $html .= "<input type=\"hidden\" name=\"encryptACode\" value=\"".$aCode."\"> ";
        $html .= "<br>";
    }
    $html .= "<br>";
    $html .= "<label></label>";
    $html .= "<input type=\"submit\" name=\"submitBtn\" value=\"".$lang['buttonCaption']['signUp']."\" class=\"btn\" onmouseover=\"this.className='btnhov'\" onmouseout=\"this.className='btn'\">";
    $html .= " ";
    $html .= "<input type=\"reset\" name=\"resetBtn\" value=\"".$lang['buttonCaption']['reset']."\" class=\"btn\" onmouseover=\"this.className='btnhov'\" onmouseout=\"this.className='btn'\">";
    $html .= "<br>";
    $html .= "<br>";
    $html .= "</fieldset>";
    $html .= "</form>";
    $html .= "<p>".sprintf($lang['text']['alreadySignUp'], $cfg['site']['folder'])."</p>";
    $html .= "</div>";
    return $html;   
}
 
function init_post_value(){
    $_POST['first_name'] = "";
    $_POST['email'] = "";
    $_POST['email2'] = "";
    $_POST['password'] = "";
    $_POST['password2'] = "";
}
 
function trim_post_value(){
    $_POST['email'] = trim($_POST['email']);
    $_POST['email2'] = trim($_POST['email2']);
    $_POST['password'] = trim($_POST['password']);
    $_POST['password2'] = trim($_POST['password2']);
}
 
function validate_post_value(){
    global $lang, $cfg;
    $errorMessage = "";
    
    if(strlen($_POST['email']) < EMAIL_ADDRESS_LENGTH_MIN || strlen($_POST['email']) > EMAIL_ADDRESS_LENGTH_MAX){
        $errorMessage .= "<li>".sprintf($lang['error']['emailInvalidLength'], EMAIL_ADDRESS_LENGTH_MIN, EMAIL_ADDRESS_LENGTH_MAX)."</li>";;
    }
    if(!preg_match(EMAIL_FORMAT, $_POST['email'])){
        $errorMessage .= "<li>".$lang['error']['emailInvalidFormat']."</li>";
    }
    if($_POST['email'] != $_POST['email2']){
        $errorMessage .= "<li>".$lang['error']['emailsDonotMatch']."</li>";
    }
    $existingUser = new umUser();
    $existingUser->email = $_POST['email'];
    $existingUser->get_user();
    if($existingUser->userID != 0){
        $errorMessage .= "<li>".$lang['error']['emailExisits']."</li>";
    }
    if(strlen($_POST['password']) < PASSWORD_LENGTH_MIN || strlen($_POST['password']) > PASSWORD_LENGTH_MAX){
        $errorMessage .= "<li>".sprintf($lang['error']['passwordInvalidLength'], PASSWORD_LENGTH_MIN, PASSWORD_LENGTH_MAX)."</li>";;
    }
    if($_POST['password'] != $_POST['password2']){
        $errorMessage .= "<li>".$lang['error']['passwordsDonotMatch']."</li>";
    }
    if(show_antispam_code()){
        if(md5(md5($_POST['aCode']).$cfg['site']['cookieToken']) != $_POST['encryptACode']){
            $errorMessage .= "<li>".$lang['error']['inputNumberIncorrect']."</li>";
        }
    }
    return $errorMessage;
}
?>