Skip to:
Content
Pages
Categories
Search
Top
Bottom

Capitalize fullnames before they're entered in the database


  • peterverkooijen
    Participant

    @peterverkooijen

    I have a function that “capitalizes” strings, make the first letter of a word capital, the rest lower-case.

    function nameize($str,$a_char = array("'","-"," ")){
    //$str contains the complete raw name string
    //$a_char is an array containing the characters we use as separators for capitalization. If you don't pass anything, there are three in there as default.
    $string = strtolower($str);
    foreach ($a_char as $temp){
    $pos = strpos($string,$temp);
    if ($pos){
    //we are in the loop because we found one of the special characters in the array, so lets split it up into chunks and capitalize each one.
    $mend = '';
    $a_split = explode($temp,$string);
    foreach ($a_split as $temp2){
    //capitalize each portion of the string which was separated at a special character
    $mend .= ucfirst($temp2).$temp;
    }
    $string = substr($mend,0,-1);
    }
    }
    return ucfirst($string);
    }

    Where can I apply nameize() to make sure the fullname from the form is capitalized before it is entered in the database?

    The fullname field, field_1, is part of a loop in register.php. Where can I apply nameize() to just the field_1 value?

    A CSS solution is no good. I also want to figure out how to make a two-part name required in the fullname field.

  • The topic ‘Capitalize fullnames before they're entered in the database’ is closed to new replies.
Skip to toolbar