SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2003
    Location
    Temecula, CA
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Customizing form requirment

    I was reading through some of the threads and found one (Where to begin? Client login for my wife's wedding consulting business)that directed me to http://www.phpfreaks.com/tutorials/40/0.php

    My question is: can a variable be added, for the email input, to where only certain email addresses can be utilized. i.e. only @domain.com addresses will be accepted -- so if someone enters user@notcorrect.com the registration will fail, but user@domain.com will be accpeted and the registration will continue?
    Code:
    <form name="form1" method="post" action="register.php">
      <table width="100%" border="0" cellpadding="4" cellspacing="0">
        <tr> 
          <td width="24%" align="left" valign="top">First Name</td>
          <td width="76%"><input name="first_name" type="text" id="first_name2" value="<? echo $first_name; ?>"></td>
        </tr>
        <tr> 
          <td align="left" valign="top">Last Name</td>
          <td><input name="last_name" type="text" id="last_name" value="<? echo $last_name; ?>"></td>
        </tr>
        <tr> 
          <td align="left" valign="top">Email Address</td>
          <td><input name="email_address" type="text" id="email_address" value="<? echo $email_address; ?>"></td>
        </tr>
        <tr> 
          <td align="left" valign="top">Desired Username</td>
          <td><input name="username" type="text" id="username" value="<? echo $username; ?>"></td>
        </tr>
        <tr> 
          <td align="left" valign="top">&nbsp;</td>
          <td><input type="submit" name="Submit" value="Join Now!"></td>
        </tr>
      </table>
    </form>
    Thanks for your help,
    Josh

  2. #2
    SitePoint Addict yjanse's Avatar
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could split it in to fields and use a dropdown box for the domain part of the email address:

    HTML Code:
    <tr>
      <td>
        <input name="email_uname" type="text" id="email_uname" value="usernamehere"> @
        <select>
          <option value="domain.com">domain.com</option>
          <option value="domain2.com">domain2.com</option>
          <option value="domain3.com">domain3.com</option>
        </select>
      </td>
    </tr>
    Store the allowed domain in a textfile or database, and fill the choice box with them. If you don't want to split the address in a part before the '@' and after it, consider a regular expression in the PHP code which checks if the entered address ends with a valid domain.
    Yves Janse:
    Android42.net - PHP5 Bookcase project - Developers Blog
    | PHP | MySQL | CSS | XML | XHTML | AJAX | Patterns |

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2003
    Location
    Temecula, CA
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    consider a regular expression in the PHP code which checks if the entered address ends with a valid domain.
    Is what I would like to do ... I'm going to see if I can figure it out. Its the "ends with" that I'm not sure about.

    Thank you

  4. #4
    SitePoint Addict yjanse's Avatar
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For example, you can explode it on the '@' character, and take the last part (not foolproof though).

    PHP Code:
    <?php
    // Small example (not tested, just from my head)
    $email 'dmj@somewhere.com';
    list(
    $username$domain) = explode('@'$email);
    echo 
    'Username: ' $username '<br/>'
    echo 
    'Domain: ' $domain '<br/>';
    $valid = array('domain1.com''domain2.com''bananas.com');
    if(
    array_key_exists($domain$valid)) {
      echo 
    "Don't register $username@$domain !!";
    } else {
      echo 
    "Go ahead and register him!";
    }
    /** OUTPUT
    Username: dmj
    Domain: somewhere.com
    Don't register [email]dmj@somewhere.com[/email] !!
    */
    ?>
    Yves Janse:
    Android42.net - PHP5 Bookcase project - Developers Blog
    | PHP | MySQL | CSS | XML | XHTML | AJAX | Patterns |

  5. #5
    SitePoint Zealot
    Join Date
    Sep 2003
    Location
    Temecula, CA
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you, that gives me a good direction.

    Thanks again
    Josh

  6. #6
    SitePoint Addict yjanse's Avatar
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem, good luck Josh!
    You might also like the string functions reference: http://nl.php.net/manual/en/ref.strings.php
    Yves Janse:
    Android42.net - PHP5 Bookcase project - Developers Blog
    | PHP | MySQL | CSS | XML | XHTML | AJAX | Patterns |


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
  •