Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

hightlighting required forms thru css

  • 31-03-2006 02:36AM
    #1
    Registered Users, Registered Users 2 Posts: 3,514 ✭✭✭


    hi guys, does anyone know a site where i could get some code to dispaly a dashed effect or similar for required forms (css/php). I have looked about but i haven't come across anything worth while.

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 2,204 ✭✭✭Serbian


    I could do it up for you, but I'm not exactly sure what you mean by a dashed effect? Do you mean a dashed border around the input element or a dashed background on the element? Or something else entirely?

    If you have seen a site that has used it before, post up the link.


  • Registered Users, Registered Users 2 Posts: 3,514 ✭✭✭Rollo Tamasi


    hi serbian, thanks for the offer. I got a script in the end late last night. Here the code for those who are intertesed in adding some user friendly aspects to their forms. Save as a php file....[PHP]
    <?php
    // Create an empty array to hold the error messages.
    $arrErrors = array();
    //Only validate if the Submit button was clicked.
    if (!empty($_POST)) {
    // Each time there's an error, add an error message to the error array
    // using the field name as the key.
    if ($_POST=='')
    $arrErrors = 'Please provide your name.';
    if ($_POST=='')
    $arrErrors = 'A valid email address is required.';
    if ($_POST=='')
    $arrErrors = 'Please provide your phone number.';
    if (count($arrErrors) == 0) {
    // If the error array is empty, there were no errors.
    // Insert form processing here.
    } else {
    // The error array had something in it. There was an error.
    // Start adding error text to an error string.
    $strError = '<div class="formerror"><p><img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt="">Please check the following and try again:</p><ul>';
    // Get each error and add it to the error string
    // as a list item.
    foreach ($arrErrors as $error) {
    $strError .= "<li>$error</li>";
    }
    $strError .= '</ul></div>';
    }
    }
    ?>

    <style>
    label {
    width: 80px;
    text-align: right;
    float: left;
    }

    .formerror {
    border: 1px solid red;
    background-color : #FFCCCC;
    width: auto;
    padding: 5px 0;
    }

    .errortext {
    padding-left: 80px;
    font: bold smaller sans-serif;
    }
    </style>

    <?php echo $strError; ?>
    <form method="post" action="<?php echo $PHP_SELF; ?>">

    <p<?php if (!empty($arrErrors)) echo ' class="formerror"'; ?>>
    <label for="name">Name:</label>
    <input name="name" type="text" id="name" value="<?php echo $_POST ?>">
    <?php if (!empty($arrErrors)) echo '<img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors.'</span>'; ?>
    </p>
    <p<?php if (!empty($arrErrors)) echo ' class="formerror"'; ?>>
    <label for="email">Email:</label>
    <input name="email" type="text" id="email" value="<?php echo $_POST ?>">
    <?php if (!empty($arrErrors)) echo '<img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors.'</span>'; ?>
    </p>
    <p<?php if (!empty($arrErrors)) echo ' class="formerror"'; ?>>
    <label for="phone">Phone:</label>
    <input name="phone" type="text" id="phone" value="<?php echo $_POST ?>">
    <?php if (!empty($arrErrors)) echo '<img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors.'</span>'; ?>
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit">
    </p>
    </form>[/PHP]


Advertisement