SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    QuickFrom and Databases

    Hello there!

    I've been scouring the internet for help on this subject for some time now and becasue im a complete NOOB at this it doesnt make any sense to me what so ever.

    So i thought i would come here and ask in hopes to get a response so here goes....

    I'm building a registration form using QuickForm with the help of the PHP Anthology. What im trying to is have a "select" element pull information from the database and display it in a drop down format.

    Can anyone point me in the right direction on how to do this?

    $form->addElement('select','recruiter','Recruited by:');
    and then what???? lol I'm lost do i do a query for this? and the how would i implement it in the form?

    Any help would be greatly appreciated.
    Thanks in advance

    Russell

  2. #2
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    590
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uhmm we have no idea of the structure of your form , posting source codes will surely help
    Don't Panic

  3. #3
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its the form from the php anthology code below

    PHP Code:
    // 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"');
        
        [
    B]// The Recruiter field
        
    $form->addElement('select','recruiter','Recruited by:');[/B]

        
    // 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();
        }

    The part in bold is the part that i will need to display stuff from a database and display it in a drop down box.

  4. #4
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok so no help....

    Well i got a little further with my problem.

    Ive added this SQL

    PHP Code:
    $sql "SELECT login, user.user_id, user2collection.user_id, collection_id FROM user, user2collection WHERE user.user_id=user2collection.user_id AND collection_id='2'";
    $dsmembers = @mysql_query($sql);
    if (!
    $dsmembers) {
        exit(
    "Unable to get Ds members please contact the admin to resolve the registration issue with the following <br />Error code : " mysql_error() . "");
    }
    while (
    $recs mysql_fetch_array($dsmembers)) {
        
    $recruiter $recs['login']; 
    Then in the form i have this :

    PHP Code:
        $form->addElement('select','recruiter','Who recruited you?'$recruiter); 
    Trouble is the QuickForm is throwing me an error :

    Warning: Unknown class passed as parameter in /home/****/public_html/DsV2/HTML/QuickForm/select.php on line 447

    Warning: require_once(DB.php) [function.require-once]: failed to open stream: No such file or directory in /home/****/public_html/DsV2/HTML/QuickForm/select.php on line 397

    Fatal error: require_once() [function.require]: Failed opening required 'DB.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/****/public_html/DsV2/HTML/QuickForm/select.php on line 397

    And for the life of me i cant see whats causing the error any body help on this one.... or another blank?

  5. #5
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok... just encase ANYONE else wants to do this i will post the wrking code below.

    PHP Code:
    $sql "SELECT user.user_id, login FROM user, user2collection WHERE user.user_id=user2collection.user_id AND collection_id='2' ORDER BY user_id";
    $result $db->query($sql);

    while( 
    $row $result->fetch() ){

    $return[$row['user_id']] = $row['login'];

    the form code

    PHP Code:
    $form->addElement('select','recruiter','Who recruited you?'$return); 
    Not that it appears that anyone else in the world needs to do the above but hey.

    Peace


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
  •