SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Quick Else Statment Help

    Code:
    <?PHP
    								
    $email = $_GET['email'];
    								
    if ($email != 'Email'){
    echo ("<input name=\"email\" type=\"text\" value=\"{$email}\" alt=\"Email\" class=\"text_boxes\" />");
    } else {
    echo ("<input name=\"email\" type=\"text\" value=\"Email\" alt=\"Email\" class=\"text_boxes\" onfocus=\"(this.value == 'Email') ? this.value = '' :false;\" onblur=\"(this.value == '') ? this.value = 'Email' : false;\" />");
    }
    								
    ?>
    I want the else statment to show up as well when the field is left blank.

    I tried...

    Code:
    if ($email != 'Email' || !empty($email))
    but that didn't work.

    Any ideas?

    Thanks,
    Mario
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    You should have left the ! off of the empty.

    Code:
    if($email != 'Email' || !empty($email))
    However, just for the sake of good practice, you should probably do it like this:
    Code:
    if($email == 'Email') {
    echo ("<input name=\"email\" type=\"text\" value=\"Email\" alt=\"Email\" class=\"text_boxes\" onfocus=\"(this.value == 'Email') ? this.value = '' :false;\" onblur=\"(this.value == '') ? this.value = 'Email' : false;\" />");
    } else {
    echo ("<input name=\"email\" type=\"text\" value=\"{$email}\" alt=\"Email\" class=\"text_boxes\" />");
    }
    It's a lot easier to understand.

  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    I find this easier to understand
    PHP Code:
    $format  '<input name="email" type="text" value ="$s" class="text_boxes" %s />';
    $jscript 'onfocus="(this.value == \'Email\') ? this.value = \'\' :false;" '
             
    'onblur="(this.value == \'\') ? this.value = \'Email\' :false;"';

    $email = (!isset($_GET['email']) || empty($_GET['email'])) ? 'Email' $_GET['email'];

    printf($format$mail$jscript); 
    In a way
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •