SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Non-Member
    Join Date
    Apr 2007
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    User field automatically populates email field?

    I'm using program with a Create Account Page. It asks for User Name, Password, Email Address etc., I want the User Name to be the Users Email Address,

    Is there a way to modify this code so when the user enters an email address in the User Name field, and it automatically populates the Email Address field on that page?

    Thank you. Here is the code:

    Code:
    <?php global $account; ?>
    
    <form method="POST" action="index.php">
    <table align="center" cellpadding="1" width="70%" height="100%">
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
    <input class='field' type='hidden' name='command' value='account'>
    <input class='field' type='hidden' name='param' value='signup'>
    <tr><td colspan='2' class='pageTitle'><div class='hLine'>Create new account</div></td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr>
    <td class='fieldLabel' width="30%">Membership type</td>
    <td align="center">[account_type_panel]</td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr>
    <td class='fieldLabel' width="30%">User Name</td>
    <td><input class='field' type='text' size='30' maxlength="30" name='user_name' value='<?=$account->user_name ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('user_name') ?></span></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Password</td>
    <td><input class='field' type='password' size='30' maxlength="30" name='password' value='<?=$account->password ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('password') ?></span></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Re-enter Password</td>
    <td><input class='field' type='password' size='30' maxlength="30" name='reenter_password' value='<?=$account->reenter_password ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('reenter_password') ?></span></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Name </td>
    <td ><input class='field' type='text' size='40' maxlength="50" name='first_name' value='<?=$account->first_name ?>'>
    <span class='requiredField'>&nbsp;*&nbsp</span><span class='errorMessage'><?=$account->get_error('first_name') ?></span></td>
    
    </tr>
    <tr>
    <td class='fieldLabel'>business / company name</td>
    <td><input class='field' type='text' size='40' maxlength="50" name='last_name' value='<?=$account->last_name ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('last_name') ?></span></td>
    </tr>
    <tr><td>&nbsp;</td></tr>
    <tr>
    <td class='fieldLabel'>Email address</td>
    <td><input class='field' type='text' size='40' maxlength="50" name='email' value='<?=$account->email ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('email') ?></span></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Address</td>
    <td><input class='field' type='text' size='40' maxlength="70" name='address' value='<?=$account->address ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('address') ?></span></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Address 2</td>
    <td><input class='field' type='text' size='40' maxlength="70" name='address_second' value='<?=$account->address_second ?>'></td>
    
    </tr>
    <tr>
    <td class='fieldLabel'>City</td>
    <td><input class='field' type='text' size='40' maxlength="50" name='city' value='<?=$account->city ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('city') ?></span></td>
    </tr>
    
    <tr>
    <td class='fieldLabel'>Zip/Postal code</td>
    <td><input class='field' type='text' size='35' maxlength="35" name='zip_postal_code' value='<?=$account->zip_code ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('zip_code') ?></span></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Phone Number</td>
    <td><input class='field' type='text' size='35' maxlength="35" name='phone' value='<?=$account->phone ?>'></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Mobile Phone Number</td>
    <td><input class='field' type='text' size='35' maxlength="35" name='mobile_phone_number' value='<?=$account->mobile_phone_number ?>'></td>
    </tr>
    <tr><td>&nbsp;</td></tr>
    
    
    
    <tr><td>&nbsp;</td></tr>
    <tr><td colspan="2" class='hLine' align="right">&nbsp;<span class='requiredField'>&nbsp;*</span>&nbsp;&nbsp; Required field</td></tr>
    <tr><td colspan='2' align="right"><input class='button' type='submit' value='create'></td></tr>
    <tr><td colspan="2">&nbsp;</td></tr>
    </table>
    </form>

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this the case where you can use JavaScript like this:
    JavaScript Function:
    Code:
    function populate(frm){
    	frm.email.value = frm.user_name.value
    }
    And just call this function in the username field's onBlur event like this:
    Code:
    <input class='field' type='text' size='30' onBlur="populate(this.form);" maxlength="30" name='user_name' value='<?=$account->user_name ?>'>
    I hope this should work for you.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    Non-Member
    Join Date
    Apr 2007
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks...

    Thanks for your reply.

    So, If I understand you correctly I need to add this:

    Code:
    function populate(frm){
    	frm.email.value = frm.user_name.value
    }
    to the code that I posted? If so, Where Should I Add It?

    And then I should modify the line by adding onBlur="populate(this.form);

    Am I correct in understanding what you suggested?

    thank you. I look forward to your reply.

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is your complete code just copy and paste:
    [PHP]
    global $account;
    PHP Code:
    [HTML]
    <script language="javascript" type="text/javascript">
    function populate(frm){
        frm.email.value = frm.user_name.value
    }
    </script>
    <form method="POST" action="index.php">
    <table align="center" cellpadding="1" width="70%" height="100%">
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
    <input class='field' type='hidden' name='command' value='account'>
    <input class='field' type='hidden' name='param' value='signup'>
    <tr><td colspan='2' class='pageTitle'><div class='hLine'>Create new account</div></td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr>
    <td class='fieldLabel' width="30%">Membership type</td>
    <td align="center">[account_type_panel]</td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr>
    <td class='fieldLabel' width="30%">User Name</td>
    <td><input class='field' type='text' size='30' onBlur="populate(this.form);" maxlength="30" name='user_name' value='<?=$account->user_name ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('user_name'?></span></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Password</td>
    <td><input class='field' type='password' size='30' maxlength="30" name='password' value='<?=$account->password ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('password'?></span></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Re-enter Password</td>
    <td><input class='field' type='password' size='30' maxlength="30" name='reenter_password' value='<?=$account->reenter_password ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('reenter_password'?></span></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Name </td>
    <td ><input class='field' type='text' size='40' maxlength="50" name='first_name' value='<?=$account->first_name ?>'>
    <span class='requiredField'>&nbsp;*&nbsp</span><span class='errorMessage'><?=$account->get_error('first_name'?></span></td>

    </tr>
    <tr>
    <td class='fieldLabel'>business / company name</td>
    <td><input class='field' type='text' size='40' maxlength="50" name='last_name' value='<?=$account->last_name ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('last_name'?></span></td>
    </tr>
    <tr><td>&nbsp;</td></tr>
    <tr>
    <td class='fieldLabel'>Email address</td>
    <td><input class='field' type='text' size='40' maxlength="50" name='email' value='<?=$account->email ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('email'?></span></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Address</td>
    <td><input class='field' type='text' size='40' maxlength="70" name='address' value='<?=$account->address ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('address'?></span></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Address 2</td>
    <td><input class='field' type='text' size='40' maxlength="70" name='address_second' value='<?=$account->address_second ?>'></td>

    </tr>
    <tr>
    <td class='fieldLabel'>City</td>
    <td><input class='field' type='text' size='40' maxlength="50" name='city' value='<?=$account->city ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('city'?></span></td>
    </tr>

    <tr>
    <td class='fieldLabel'>Zip/Postal code</td>
    <td><input class='field' type='text' size='35' maxlength="35" name='zip_postal_code' value='<?=$account->zip_code ?>'>
    <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('zip_code'?></span></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Phone Number</td>
    <td><input class='field' type='text' size='35' maxlength="35" name='phone' value='<?=$account->phone ?>'></td>
    </tr>
    <tr>
    <td class='fieldLabel'>Mobile Phone Number</td>
    <td><input class='field' type='text' size='35' maxlength="35" name='mobile_phone_number' value='<?=$account->mobile_phone_number ?>'></td>
    </tr>
    <tr><td>&nbsp;</td></tr>

    <tr><td>&nbsp;</td></tr>
    <tr><td colspan="2" class='hLine' align="right">&nbsp;<span class='requiredField'>&nbsp;*</span>&nbsp;&nbsp; Required field</td></tr>
    <tr><td colspan='2' align="right"><input class='button' type='submit' value='create'></td></tr>
    <tr><td colspan="2">&nbsp;</td></tr>
    </table>
    </form>
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    Non-Member
    Join Date
    Apr 2007
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thank you but,

    Thank you, it works.
    Last edited by alex111; Jul 3, 2007 at 09:32.

  6. #6
    Non-Member
    Join Date
    Apr 2007
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks

    Having added the javascript and it works, is it possible to hide the email field, so that it doesn't appear on the page, yet adds the email info to the database?

    I tried <!-- -->, as in:

    Code:
    <!--</tr> <tr><td></td></tr><tr><td class='fieldLabel'><font face="Arial" color="#6B6B6B" size="2">&nbsp;Email Address</font></td> <td><input class='field' type='text' size='40' maxlength="50" name='email' value='<?=$account->email ?>'> <span class='requiredField'>&nbsp;*&nbsp;</span><span class='errorMessage'><?=$account->get_error('email') ?></span></td> </tr>-->
    but it didn't work, I couldn't Submit.

    Any thoughts on this will be appreciated.


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
  •