SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Netherlands
    Posts
    672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Anthology example Acces control..

    I am finally able to get it working thanks to some help found on this forum only when i press on the submit buttons nothing happens?

    Does anybody know what is missing from the code :s

    Somewhere it generate the wrong html i think:

    <formArray>

    THere is no action ? To link to something ?

    PHP Code:
    <?php
    // Include the MySQL class
    require_once('MySQL.php');

    // Include the Session class
    require_once('Session/Session.php');

    // Include the SignUp class
    require_once('AccessControl/SignUp.php');

    // Include the QuickForm class
    require_once ("HTML/QuickForm.php");

    // Include the phpmailer class
    require_once ("phpmailer/class.phpmailer.php");

    // Settings for SignUp class
    $listener='http://localhost/scms_oop/components/com_login//6.php';
    $frmName='Your Name';
    $frmAddress='noreply@yoursite.com';
    $subj='Account Confirmation';
    $msg=<<<EOD
    <h2>Thank you for registering!</h2>
    <div>The final step is to confirm 
    your account by clicking on:</div>
    <div><confirm_url/></div>
    <div>
    <b>Your Site Team</b>
    </div>
    EOD;

    // Instantiate the MySQL class
    $db=& new MySQL($host,$dbUser,$dbPass,$dbName);

    // Instantiate the Session class
    $session=new Session;

    // Instantiate the signup class
    $signUp=new SignUp($db,$listener,$frmName,$frmAddress,$subj,$msg,TRUE);

    // Is this an account confirmation ?
    if ( isset ( $_GET['code'] ) ) {
        if ( 
    $signUp->confirm($_GET['code']) ) {
            
    $display='Thank you. You\'re account has now been confirmed.<br />'.
                   
    'You can now <a href="4.php">login</a>';
        } else {
            
    $display='There was a problem confirming your account.<br />'.
                     
    'Please try again or contact the site administrators';
        }

    // Otherwise display the form
    } else {

        
    // Register a session variable for use in the image
        
    if ( !$session->get('randomString') )
            
    $session->set('randomString',$signUp->createRandString());

        
    // A function for comparing password
        
    function cmpPass($element$confirmPass) {
            global 
    $form;
            
    $password $form->getElementValue('password');
            return (
    $password == $confirmPass);
        }

        
    // A function to encrypt the password
        
    function encryptValue($value) {
            return 
    md5($value);
        }

        
    // Instantiate the QuickForm class
        
    $form = new HTML_QuickForm('regForm''POST');

     
    // INSTANTIATE THE RENDERER
        
    $renderer =& $form->defaultRenderer();
        
        
    // Clear the default HTML templates
        
    $renderer->clearAllTemplates(); 

        
    // Define new templates
        
    $renderer->setFormTemplate('
    <table class="registration">
      <form{attributes}>{content}
      </form>
    </table>'
    );

        
    $renderer->setHeaderTemplate('
        <tr>
          <td class="header" colspan="2">{header}</td>
        </tr>'
    );

        
    $renderer->setElementTemplate('
        <tr valign="top">
          <td class="label">
          {label}
          </td>
          <td class="field">
          <!-- BEGIN error --><span class="error">{error}</span><br><!-- END error -->
          {element}
          <!-- BEGIN required --><span class="required">*</span><!-- END required -->
          </td>
        </tr>'
    );

        
    $renderer->setRequiredNoteTemplate('
        <tr>
          <td>&nbsp;</td>
          <td class="requiredNote">{requiredNote}</td>
        </tr>'
    );

        
    // Add a header to the form
         
    $form->addElement'header''header''Registration Form' ); 

        
    // Register the compare function
        
    $form->registerRule('compare''function''cmpPass');

        
    // The login field
        
    $form->addElement('text','login','Desired Username:','class="signupData"');
        
    $form->addRule('login','Please provide a username','required',false,'client');
        
    $form->addRule('login','Username must be at least 6 characters','minlength',6,'client');
        
    $form->addRule('login','Username cannot be more than 50 characters','maxlength',50,'client');
        
    $form->addRule('login','Username can only contain letters and numbers','alphanumeric',NULL,'client');

        
    // The password field
        
    $form->addElement('password','password','Password:','class="signupData"');
        
    $form->addRule('password','Please provide a password','required',false,'client');
        
    $form->addRule('password','Password must be at least 6 characters','minlength',6,'client');
        
    $form->addRule('password','Password cannot be more than 12 characters','maxlength',50,'client');
        
    $form->addRule('password','Password can only contain letters and numbers','alphanumeric',NULL,'client');

        
    // The field for confirming the password
        
    $form->addElement('password','confirmPass','Confirm:','class="signupData"');
        
    $form->addRule('confirmPass','Please confirm password','required',false,'client');
        
    $form->addRule('confirmPass','Passwords must match','compare','function');

        
    // The email field
        
    $form->addElement('text','email','Email Address:','class="signupData"');
        
    $form->addRule('email','Please an email address','required',false,'client');
        
    $form->addRule('email','Please enter a valid email address','email',false,'client');
        
    $form->addRule('email','Email cannot be more than 50 characters','maxlength',50,'client');

        
    // The first name field
        
    $form->addElement('text','firstName','First Name:','class="signupData"');
        
    $form->addRule('firstName','Please enter your first name','required',false,'client');
        
    $form->addRule('firstName','First name cannot be more than 50 characters','maxlength',50,'client');

        
    // The last name field
        
    $form->addElement('text','lastName','Last Name:','class="signupData"');
        
    $form->addRule('lastName','Please enter your last name','required',false,'client');
        
    $form->addRule('lastName','Last name cannot be more than 50 characters','maxlength',50,'client');

        
    // The signature field
        
    $form->addElement('textarea','signature','Signature:','class="signature"');

        
    // The image check field for "humanness"
        
    $form->addElement('text','imageCheck','Image Text:',
                          
    'class="signupData"');
        
    $form->addRule('imageCheck','Please enter text from image',
                       
    'required',false,'client');

        
    // Server side validation! Don't give away random string in JavaScript
        
    $form->addRule('imageCheck','Please confirm the text in the image',
                       
    'regex','/^'.$session->get('randomString').'$/',
                       
    'server');

    // The image check field
        
    $image ='
      <tr valign="top">
        <td class="info">
          Enter the text as it<br />appears in the image
        </td>
        <td class="field">
          <img src="8.php">
        </td>
      </tr>'
    ;

    $form->addGroup($group'name'$image); 

        
    // Add a submit button called submit and "Send" as the text for the button
        
    $form->addElement('submit','submit','Register','class="createAccount"');

        
    // Specify the "required field" note for the bottom of the form
        
    $form->setRequiredNote('<span class="required">*</span> required');

        
    // If the form is submitted...
        
    if ( $form->validate() ) {
            
    // Apply the encryption filter to the password
            
    $form->applyFilter('password''encryptValue');

            
    // Build an array from the submitted form values
            
    $submitVars=array (
                
    'login'=>$form->getSubmitValue('login'),
                
    'password'=>$form->getSubmitValue('password'),
                
    'email'=>$form->getSubmitValue('email'),
                
    'firstName'=>$form->getSubmitValue('firstName'),
                
    'lastName'=>$form->getSubmitValue('lastName'),
                
    'signature'=>$form->getSubmitValue('signature') );

            
    // Create signup
            
    if ( $signUp->createSignup($submitVars) ) {
                
    // Send confirmation email
                
    if ( $signUp->sendConfirmation() ) {
                    
    $display='Thank you. Please check your email to '.
                             
    'confirm your account';
                } else {
                    
    $display='Unable to send confirmation email.<br />'.
                             
    'Please contact the site administrators';
                }
            } else {
                
    $display='There was an error creating your account.<br />'.
                         
    'Please try again later or '.
                         
    'contact the site administrators';
            }
        } else {
            
    // If not submitted, display the form
            
    $display=$form->toHtml();
        }
    }
    ?>
    <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title> Sign Up </title>
    <style type="text/css">
    body, a, td, input, textarea
    {
        font-family: verdana;
        font-size: 11px;
    }
    .registration
    {
        width: 400px;
    }
    .header
    {
        color: navy;
        text-align: center;
        font-variant: small-caps;
        font-size: 15px;
        font-weight: bold;
        border-color: navy;
        border-style: dashed;
        border-width: 1px;
        background-color: #f6f7f8;
    }
    .label
    {
        color: navy;
        text-align: right;
        width: 40%;
        font-weight: bold;
        padding: 3px;
    }
    .info
    {
        color: navy;
        text-align: right;
        width: 40%;
        padding: 3px;
    }
    .required
    {
        color: red;
    }
    .field
    {
        width: 60%;
        padding: 3px;
    }
    .error
    {
        color: red;
    }
    .requiredNote
    {
        font-size: 9px;
        text-align: right;
    }
    .signupData
    {
        width: 200px;
        background-color: #f6f7f8;
        font-weight: bold;
    }
    .signature
    {
        background-color: #f6f7f8;
        font-weight: bold;
        width: 200px;
        height: 100px;
    }
    .createAccount
    {
        background-color: #f6f7f8;
        color: navy;
        font-weight: bold;
    }
    </style>
    </head>
    <body>
    <?php echo ( $display );?>
    </body>
    </html>
    Go visit my site :-D you know you want to ;-)
    www.mech7.net

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The problem you're seeing looks like an effect of the templating system having been changed in more recent versions of HTML_QuickForm. The setFormTemplate method obviously is no longer working as intended.

    Which version of HTML_QuickForm are you running? As noted in the book, the code presented there was written for version 3.1.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Netherlands
    Posts
    672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you but i solved it, i know the api changed but it was because HTML_Common changed also... when i updated the version it does work normally
    Go visit my site :-D you know you want to ;-)
    www.mech7.net


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •