Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

hightlighting required forms thru css

  • 31-03-2006 1: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,170 ✭✭✭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