Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form validation to csv

    Ok so i need to validate a telephone number field(s)

    its like this:
    (area)prefix-suffix
    (3 diff fields)
    i need them to be REQUIRED(3,3,4)
    but i really need them to write into the CSV, into one cell.
    here;s how im posting now. it gives me an error if i do $area$pre$suf, in replace of $phone..
    PHP Code:
    //this is where the creating of the csv takes place 
                
    $cvsData $fn "," $ln "," $address "," $city "," $state "," $zip "," $phone "," $email "," .$school "," $src ."\n"
                
    //write to the file 
                
    $fp fopen("excel.csv","a"); 
                
    $fp2 fopen("archive.csv","a"); // $fp is now the file pointer to file $filename 
                
    if($fp){ 
                    
    fwrite($fp,$cvsData); 
                    
    fwrite($fp2,$cvsData);//    Write information to the file 
                    
    fclose($fp);  
                    
    fclose($fp2); //    Close the file 
                    
    $message 'Submission successfull. Thank you!'
                    
    $aClass 'normFrmClass'
                     
                    
    ?> 

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    it gives me an error if i do $area$pre$suf, in replace of $phone..
    Care to share? Or should we guess at the error you're getting? Also, when you echo the $area, $pre, and $suf variables, what do you see?

    FYI, you might be interested in the fputcsv() function, which does the formatting for you:

    http://us3.php.net/manual/en/function.fputcsv.php

  • #3
    New Coder
    Join Date
    Feb 2010
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it works. just had to make a
    $phone = $area$pre$suf

    I just need to make a way to VALIDATE this. ive searched EVERYWHERE for a script.
    i just need the area field to have a req 3, pre needs a req 3, and suf a req 4.

    So that it will show an error, if there isnt 3,3,4 characters in that field.

    I need it to be on same page, not POST to a validate script. because its fwriting to a .csv.

    recap: need to make the phone number fields ahve a REQUIRED min. character length of 3,3,4. (area)prefix-suffix. (555)555-5555.
    thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •