SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    NYC
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trim Function with foreach LOOP..

    Hello,

    I wrote this trim function which loops through required field array and if the fields are not empty, it trims all of the required fields, I would appreciate any feedback.

    PHP Code:

    $req_fields 
    = array(
                
    $firstname,
                
    $lastname,
                
    $email,
                
    $phone,
                
    $college,
                
    $campus,
                
    $depatment,
                
    $date_needed
                    
    );
                    

    // TRIM FUNCTION
    function trim_fields($val)
        {

            if(!empty(
    $val))
            {
            foreach(
    $val as $keys)
                {
                
    trim($keys)
                }
            }
       }
    if (isset(
    $_POST))
        
         {
               
    trim_fields($_POST);
          } 
    Thanks.

  2. #2
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,196
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I wrote this trim function which loops through required field array and if the fields are not empty, it trims all of the required fields, I would appreciate any feedback.
    If you mean by that, that your trim_fields function should take the values in the $req_fields array in mind. Then you need to edit your trim_fields function. As currently it does not check the post key against the $req_fields array to see if its valid.

    In addition you might want to check if it really trim the text in the variables and save it (hint: no).

  3. #3
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    NYC
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks The Red Devil.


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
  •