Question

Adding domain info after username similar to Hotmail at SquirrelMail login page

Asked by: Brainstormer

The title says it all I guess. I am not a JS guru. I am looking for a javascript script that would add the domain after the user name same as Hotmail does on their site. I am trying to modify the SquirrelMail webmail application's /src/login.php file so that a designated @domain.com can be inserted after user types his ID and moves to the password field. This is a requirement of the site's login process. The site is unique and the @... is specific and static, but if anyone can invent something better such as pulling the domain info from the address URL, that's great too.

Since the page has PHP, it may also be easier to add some PHP tags there, but I think JS would be the easiest way to go. If you want to see how Hotmail script works, look at the source in their login page.

Any working solution or workaround would help.

Since I have seen JS scripts implement similar to this with as little as 5 lines, I don't think this will be a majot effort. A similar sample is at http://www.mybannertaxi.com/scripts/echo.html

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-11-04 at 08:46:50ID20787568
Tags

squirrelmail

,

domain

,

login

Topic

JavaScript

Participating Experts
3
Points
25
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Hotmail pop3 & SMTP config
    does anybody know what to put in the pop3 and smtp host server in any kind of e-mail client for hotmail? I mean the address / domain name. If there is no way that i can send/receive hotMails via this method, can u suggest any good hotmail proxy (other than MS outlook :))? er...
  2. Trying to Use ASP to submit to PHP Webmail form
    Our company website is written in ASP, but our webmail login is in PHP. We don't have anyone that Understands PHP. I want to be able to submit a webmail form from ASP and have it login to the PHP website. I am not sure where to send the <form action=""> or ...
  3. Webmail
    I am looking for a good free webmail (preferably something I can host on my server, if not, then a free hosted solution) that requires a password to get into but then after that you can set it up so that it checks multiple IMAP/POP accounts and can not only seperate the mail ...
  4. Interact with Webmail
    Is it possible to interact with Webmail? If so is is possible to detect unread emails and if so tell you how many unread emails?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: jaysolomonPosted on 2003-11-04 at 09:00:34ID: 9679854

maybe this

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function addEmail(fObj){
      fObj.value = fObj.value +"@jay.com";
}      
// -->
</script>
</head>
<body>
<form name="form1" method="post" action="">
<input type="text" name="email" onChange="addEmail(this);">@jAy.com
</form>
</body>
</html>

 

by: jaysolomonPosted on 2003-11-04 at 09:02:55ID: 9679870

wait maybe i missread

Do you want it to do the same thing as the link you posted?

 

by: BrainstormerPosted on 2003-11-04 at 09:07:01ID: 9679896

You have to remember that it's a PHP file and the form implementation is not done as pure HTML.

 

by: jaysolomonPosted on 2003-11-04 at 09:08:57ID: 9679911

yes i know, can you not just use the script i provided and add the onchange to the text box?


 

by: BrainstormerPosted on 2003-11-04 at 09:14:37ID: 9679953

this is the complete login.php file contents:


<?php

/**
 * login.php -- simple login screen
 *
 * Copyright (c) 1999-2003 The SquirrelMail Project Team
 * Licensed under the GNU GPL. For full terms see the file COPYING.
 *
 * This a simple login screen. Some housekeeping is done to clean
 * cookies and find language.
 *
 * $Id: login.php,v 1.98.2.1 2003/07/03 20:24:47 stekkel Exp $
 */

/* Path for SquirrelMail required files. */
define('SM_PATH','../');

/* SquirrelMail required files. */
require_once(SM_PATH . 'functions/strings.php');
require_once(SM_PATH . 'config/config.php');
require_once(SM_PATH . 'functions/i18n.php');
require_once(SM_PATH . 'functions/plugin.php');
require_once(SM_PATH . 'functions/constants.php');
require_once(SM_PATH . 'functions/page_header.php');
require_once(SM_PATH . 'functions/html.php');
require_once(SM_PATH . 'functions/global.php');

/*
 * $squirrelmail_language is set by a cookie when the user selects
 * language and logs out
 */
set_up_language($squirrelmail_language, TRUE, TRUE);

/**
 * Find out the base URI to set cookies.
 */
if (!function_exists('sqm_baseuri')){
    require_once(SM_PATH . 'functions/display_messages.php');
}
$base_uri = sqm_baseuri();

/*
 * In case the last session was not terminated properly, make sure
 * we get a new one.
 */

sqsession_destroy();
 
header('Pragma: no-cache');

do_hook('login_cookie');

/* Output the javascript onload function. */

$header = "<script language=\"JavaScript\" type=\"text/javascript\">\n" .
          "<!--\n".
          "  function squirrelmail_loginpage_onload() {\n".
          "    document.forms[0].js_autodetect_results.value = '" . SMPREF_JS_ON . "';\n".
          "    var textElements = 0;\n".
          "    for (i = 0; i < document.forms[0].elements.length; i++) {\n".
          "      if (document.forms[0].elements[i].type == \"text\" || document.forms[0].elements[i].type == \"password\") {\n".
          "        textElements++;\n".
          "        if (textElements == " . (isset($loginname) ? 2 : 1) . ") {\n".
          "          document.forms[0].elements[i].focus();\n".
          "          break;\n".
          "        }\n".
          "      }\n".
          "    }\n".
          "  }\n".
          "// -->\n".
          "</script>\n";
$custom_css = 'none';          
displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );

echo '<body text="#000000" bgcolor="#FFFFFF" link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="squirrelmail_loginpage_onload();">' .
     "\n" . '<form action="redirect.php" method="post">' . "\n";

$username_form_name = 'login_username';
$password_form_name = 'secretkey';
do_hook('login_top');

$loginname_value = (sqGetGlobalVar('loginname', $loginname) ? htmlspecialchars($loginname) : '');

/* If they don't have a logo, don't bother.. */
if (isset($org_logo) && $org_logo) {
    /* Display width and height like good little people */
    $width_and_height = '';
    if (isset($org_logo_width) && is_numeric($org_logo_width) &&
     $org_logo_width>0) {
        $width_and_height = " width=\"$org_logo_width\"";
    }
    if (isset($org_logo_height) && is_numeric($org_logo_height) &&
     $org_logo_height>0) {
        $width_and_height .= " height=\"$org_logo_height\"";
    }
}

echo html_tag( 'table',
    html_tag( 'tr',
        html_tag( 'td',
            '<center>'.
            ( isset($org_logo) && $org_logo
              ? '<img src="' . $org_logo . '" alt="' .
                sprintf(_("%s Logo"), $org_name) .'"' . $width_and_height .
                ' /><br />' . "\n"
              : '' ).
            ( (isset($hide_sm_attributions) && $hide_sm_attributions) ? '' :
            '<small>' . sprintf (_("SquirrelMail version %s"), $version) . '<br />' ."\n".
            '  ' . _("By the SquirrelMail Development Team") . '<br /></small>' . "\n" ) .
            html_tag( 'table',
                html_tag( 'tr',
                    html_tag( 'td',
                        '<b>' . sprintf (_("%s Login"), $org_name) . "</b>\n",
                    'center', '#DCDCDC' )
                ) .
                html_tag( 'tr',
                    html_tag( 'td',  "\n" .
                        html_tag( 'table',
                            html_tag( 'tr',
                                html_tag( 'td',
                                    _("Name:") ,
                                'right', '', 'width="30%"' ) .
                                html_tag( 'td',
                                    '<input type="text" name="' . $username_form_name .'" value="' . $loginname_value .'" />' ,
                                'left', '', 'width="*"' )
                                ) . "\n" .
                            html_tag( 'tr',
                                html_tag( 'td',
                                    _("Password:") ,
                                'right', '', 'width="30%"' ) .
                                html_tag( 'td',
                                    '<input type="password" name="' . $password_form_name . '" />' . "\n" .
                                    '<input type="hidden" name="js_autodetect_results" value="SMPREF_JS_OFF" />' . "\n" .
                                    '<input type="hidden" name="just_logged_in" value="1" />' . "\n",
                                'left', '', 'width="*"' )
                            ) ,
                        'center', '#ffffff', 'border="0" width="100%"' ) ,
                    'left', '#FFFFFF' )
                ) .
                html_tag( 'tr',
                    html_tag( 'td',
                        '<center><input type="submit" value="' . _("Login") . '" /></center>',
                    'left' )
                ),
            '', '#ffffff', 'border="0" width="350"' ) . '</center>',
        'center' )
    ) ,
'', '#ffffff', 'border="0" cellspacing="0" cellpadding="0" width="100%"' );
do_hook('login_form');
echo '</form>' . "\n";

do_hook('login_bottom');
echo "</body>\n".
     "</html>\n";
?>

 

by: makcPosted on 2003-11-04 at 10:08:00ID: 9680362

so, is that username that should be appended with domain?

find string:
<input type="text" name="' . $username_form_name .'" value="' . $loginname_value .'" />

and append
<select name="quickhack"><option>@some.com</option><option>@awesome.net</option></select>

than, find
><input type="submit" value="' . _("Login") . '"

replace "submit" with "button" and add
onclick="document.forms[0].elements.' . $username_form_name . '.value+=document.forms[0].elements.quickhack.options[document.forms[0].elements.quickhack.selectedIndex].text"

 

by: makcPosted on 2003-11-04 at 10:09:22ID: 9680378

...****. forgot. last line in previous post, at the very end: .text" should be .text;document.forms[0].submit()"

 

by: BrainstormerPosted on 2003-11-04 at 13:05:57ID: 9682029

Sorry makc, I lost you in the code. I tried to patch but did not work. Can you present a more detailed code patch with the new code already in place?

I will try to use jaysolomon's approach. His was correct for HTML, it just needs implementing thru the PHP jungle :-)

 

by: BrainstormerPosted on 2003-11-04 at 13:25:21ID: 9682211

changes to login.php:


$header = "<script language=\"JavaScript\" type=\"text/javascript\">\n" .
          "<!--\n".
          "  function addEmail(fObj){ \n".
          "         fObj.value = fObj.value + "@mysite.net"; \n".
          "         } \n".
          "  function squirrelmail_loginpage_onload() {\n".

...

                                    '<input type="text" name="' . $username_form_name .'" value="' . $loginname_value .' onChange="addEmail(this);" />' ,
                                'left', '', 'width="*"' )

but I get a : Parse error: parse error, unexpected '@' in ...\wwwroot\webmail\src\login.php on line 58

I used \@ but that did not work. I took out @ completely, but it gave me another error for unexpected T_STRING

any input?

 

by: rstorey2079Posted on 2003-11-04 at 15:58:42ID: 9683246

What you need is the onBlur javascript event handler.  Use it like this:

<?php
if($_POST['submit']=="submit") {
      echo "Username was: $_POST[username]<br>";

}
?>
<html>
<head>
<title>Add Domain Test</title>
<script type="text/javascript" language="Javascript1.2">

function addDomain(element) {

      element.value = element.value + "@hotmail.com";

}

</script>
</head>

<body>


<form action="<?php echo $PHP_SELF; ?>" method="post" name="addDomainTest">
<input type="text" name="username" onBlur="javascript:addDomain(this);"><br>
<input type="text" name="password"><br>
<input type="submit" value="submit" name="submit">
</form>

</body>
</html>

 

by: BrainstormerPosted on 2003-11-04 at 18:09:14ID: 9683825

Again, althugh both your answers are correct for simple HTML, I can not implement this in PHP. Either the @ character in @domain.net or the whole @domain.net is causing a PHP parse error.

Parse error: parse error in /home/public_html/mail/src/login.php on line 58

which is:

"  function function addDomain(element) {\n".                                   // added the custom JS    line 57
"        element.value = element.value + "@domain.net";\n".               // in these lines               line 58
"        }\n".                                                                                    // here for domain           line 59

any suggestions with PHP implementation?

 

by: BrainstormerPosted on 2003-11-04 at 18:13:15ID: 9683838

I mistakenly typed:
function function addDomain(element) {\n"

the actual code for line 57 is:
function addDomain(element) {\n"

 

by: rstorey2079Posted on 2003-11-05 at 04:19:20ID: 9686100

I'm not sure why you are putting the javascript function into the PHP code, but if you are, you do have some parse error:

should be:

"  function function addDomain(element) {\n".                                   // added the custom JS    line 57
"        element.value = element.value + \"@domain.net]\";\n".               // in these lines               line 58
"        }\n".    

notice the way I have escaped the double quotes in line 58 with slashes.  that is why you are getting the parse error.  You need those slashes.

 

by: BrainstormerPosted on 2003-11-05 at 06:18:37ID: 9686773

the code from rstorey2079 worked. the working changes are as follows:

$header = "<script language=\"JavaScript\" type=\"text/javascript\">\n" .
          "<!--\n".
          "  function addDomain(element) {\n".
          "        element.value = element.value + \"@domain.net\";\n".
          "       }\n".  
          "  function squirrelmail_loginpage_onload() {\n".
...

html_tag( 'td',
      '<input type="text" name="' . $username_form_name .'" value="' . $loginname_value .'" onChange="javascript:addDomain(this);" />' ,
      'left', '', 'width="*"' )


but one problem I noticed is that the script adds a @domain.net everytime I change something in the field. Example:

I type USRE and the script adds @domain.com
I type the password, but I notice that USRE should have been USER

I make the changes, but after I leave the field, now the text looks like:  USER@domain.net@domain.net

One workaround would be to erase everything in the field and type USER at a blank box, but I am afraid the user may fail to realize what has happend, and can not see all the  USER@domain.net@domain.net
due to the visible character limit in the field.

Anyone with a suggestion to kill that part of the script if @domain.net is already inserted, or make the script a one time use only?

Currently the script lines are inserted inside an existing javascript from the SquirrelMail author. Can I move them outside, so 2 JavaScripts exist in the page, but one has a 1 time use or die call.

Thanks for your help so far.

 

by: BrainstormerPosted on 2003-11-05 at 06:21:03ID: 9686794

addition to the above comments:

I assume some users will not know that the script is active and will attempt to add the domain themselves. This will too cause a USERx@domain.net@domain.net

 

by: rstorey2079Posted on 2003-11-05 at 08:29:21ID: 9687909

Change the javascript function to this:

function addDomain(element) {

    var str = element.value;

     if(str.search(/\@domain\.net/)==-1) {
     element.value = element.value + "@hotmail.com";
     }

}

Make sure you properly escape any quotes or slashes if you are outputting this from PHP.

 

by: rstorey2079Posted on 2003-11-05 at 08:31:15ID: 9687931

Oops, forgot to mention that you now you need to change the domain in two places:  in the if statement and in the assignment statement.

 

by: BrainstormerPosted on 2003-11-05 at 10:27:12ID: 9688945

it worked like a charm! Thanks to everyone that contributed to this. I will award the points to  rstorey2079 for the great help in JavaScript and the final working code, even thought it was not embedded in PHP. I figured that part out.

final code for the new SquirrelMail /scr/login.php is as follows:

$header = "<script language=\"JavaScript\" type=\"text/javascript\">\n" .
          "<!--\n".
          "  function addDomain(element) {\n".
          "        var str = element.value; \n".
          "             if(str.search(/\@domain\.net/)==-1) { \n".
          "        element.value = element.value + \"@domain.net\";\n".
          "        }\n".  
          "  }\n".  
          "  function squirrelmail_loginpage_onload() {\n".
...

html_tag( 'td',
     '<input type="text" name="' . $username_form_name .'" value="' . $loginname_value .'" onChange="javascript:addDomain(this);" />' ,
      'left', '', 'width="*"' )

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...