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.
Page 1 of 3 123 LastLast
Results 1 to 15 of 36
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Arrow Validating my form

    Ok, I have tried 4 different forums today and I have not got a single response... I hope someone can help me here... I really can't work with tutorial's unless it tells what each feature does and how to edit it or it displays the correct code, but I would rather you please just make a validation for this form using php when the submit button is pressed.
    Code:
    <form action="uploader.php" method="post" enctype="multipart/data">
    <input type="hidden" name="3p42r3ad3a4than32" value="329r8g" /> 
    <div class="pureadd">
    <br>
    <br>Your Name:
    <br><input type="text" name="Name" class="input" />
    <br>Your Email:
    <br><input type="text" name="Email" class="input"/>
    <br>
    <script type="text/javascript">
    var d = new Date()
    document.write("<input type='hidden' value='"+Date()+"' name='time' />")
    </script>
    <br>
    <br>Agree To Terms of Service
    <br><input type="checkbox" name="TermsOfService" value="Agreed" /> Yes I Agree To the Terms of Service
    <br>
    
    File Description:
    <br>
    <textarea rows="5" cols="40" name="description" id="maxcharfield" onKeyDown="textCounter(this,'progressbar1',200)" onKeyUp="textCounter(this,'progressbar1',200)" onFocus="textCounter(this,'progressbar1',200)" class="textarea"></textarea><br />
    <div id="progressbar1" class="progress"></div>
    
    <input type="submit" class="input">
    
    
    </div>
    </form>
    THANKS!

  • #2
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post
    Now by validating, do you mean to see if everything is properly filled out and whatnot?

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok, by validating i mean to see whether if all the form inputs are properly filled out do you think you could write some code that could when the user clicks the submit button check the code before it sends it to make sure everything is filled out, and that there is a valid email address *or as close as you can get*

    Thanks and please say something if your going to help or just put the code up, *THANKS!!!!!!!!!!!!!!!!!*
    Last edited by rockonmetal; 08-28-2007 at 03:40 AM.

  • #4
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post
    I don't understand how this is an uploader script? or is that just the name you gave the action?

  • #5
    New Coder
    Join Date
    Aug 2007
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts
    on my form, the next page (uploader.php) is an file uploader which works and does not need any attention because it works PERFECTLY! Please, if someone could give/make me the code for this form so that:
    1. No fields are left blank
    2. That the email input has a valid email address or can be a email address...
    3. And that when the SUBMIT button is pressed, the code will validate form based on the 3 things above if it isn't valid then have the form say so...
    Thats all I need... Thanks
    Last edited by rockonmetal; 08-28-2007 at 04:19 AM.

  • #6
    Regular Coder meth's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Thanks
    0
    Thanked 9 Times in 9 Posts
    If you going to have this form submit to uploader.php, then that is the file which will be doing the validation, not this one.

    Unless of course you want javascript validation; in this case you're posting in the wrong forum.
    I do Web Design, Brisbane based.
    More time spent in PHP/MySQL Web Development.
    And Search Engine Optimisation takes up the rest of it.

  • #7
    New Coder
    Join Date
    Aug 2007
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok then what do I put on uploader.php ... because I really don't have time wasted on silly questions *sorry but 10 days till release of site*

  • #8
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    $err '';
    if (empty(
    $_POST['data'])) {
    $err '1'
    }//do that for as many fields as you like.
    if() { // look up ilovejackdaniels.com for a regex email validator
    }
    if (
    $err == '') { // or use if ($err != '' or $err == 1 etc..
    //upload
    }else{
    die(
    form field left empty...);


  • #9
    New Coder
    Join Date
    Aug 2007
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts
    THANK YOU!! now i'm going to go test it!!!!!!!!!!!!!

    YEAH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!! *idk if it works yet i'm just glad someone responded...*

  • #10
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    dont forget to set $err to 1 or so mething if the email validation fails, forgot that sorry

  • #11
    New Coder
    Join Date
    Aug 2007
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ? Oh, Idk why but it won't work... heres the code to uploader.php...

    Code:
    <?php $err = '';
    if (empty($_POST['name'])) {
    $err = '1'
    }
    if() { function check_email_address($email) {  
    (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {   return false;  }  $email_array = explode("@", $email);  $local_array = explode(".", $email_array[0]);  for ($i = 0; $i < 
    
    sizeof($local_array); $i++) {     
    if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {      return false;    }  }    if 
    
    (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) 
    {domain_array = explode(".", $email_array[1]);    if (sizeof($domain_array) < 2) {        return false; }    for ($i = 0; $i < sizeof($domain_array); $i++) {      if 
    
    (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {        return false;      }    }  }  return true;}
    
    }
    if ($err == '') {if ($err != '' or $err == 1 etc..
    else{
    die(form field left empty...);
    } 
    ?>
    <?php 
    $filename = 'data.html'; 
    $input1 = $_SERVER['REMOTE_ADDR']; 
    $input2 = $_POST["Name"];  
    $input3 = $_POST["Email"]; 
    $input4 = $_POST["time"]; 
    $input5 = $_POST["3p42r3ad3a4than32"]; 
    $input6 = $_POST["Description"];  
    $data = "<table border='1'><tr><td>User IP Address:</td><td>$input1</td></tr><tr><td>Name:</td><td>$input2</td></tr><tr><td>Email  
    
    Address:<td>$input3</td></tr><tr><td>Date Submitted:</td><td>$input4</td></tr><tr><td>Description</td><td><textarea cols='50'  
    
    rows='5'>$input6</textarea></td></tr></table>"; 
    
    
    if (is_writable($filename)) { 
        if (!$handle = fopen($filename, 'a')) { 
             echo "Cannot open file ($filename)"; 
             exit; 
        } 
    
        // Write $somecontent to our opened file. 
        if (fwrite($handle, $data) === FALSE) { 
            echo "Cannot write to file ($filename)"; 
            exit; 
        } 
    
        echo "Success your information has been submitted!  Now please submit your files..."; 
    
        fclose($handle); 
    
    } else { 
        echo "The file $filename is not writable"; 
    } 
    
    ?> 
    <?php 
    $upload_dir = "submitions/"; 
    $num_files = 2; 
    //the file size in bytes. 
    $size_bytes =20480000; //51200 bytes = 50KB. 
    //Extensions you want files uploaded limited to. 
    $limitedext = array(".gif",".jpg",".jpeg",".png",".bmp",".mov",".mpg",".mpeg"); 
    
    
       //check if the directory exists or not. 
       if (!is_dir("$upload_dir")) { 
          die ("Error: The directory <b>($upload_dir)</b> doesn't exist because we are in the process of the weekly upload."); 
       } 
       //check if the directory is writable. 
       if (!is_writeable("$upload_dir")){ 
          die ("Error: The directory <b>($upload_dir)</b> is NOT writable, Please click contact and then contact technical support to tell them this problem."); 
       } 
    
    
    //if the form has been submitted, then do the upload process 
    //infact, if you clicked on (Upload Now!) button. 
    if (isset($_POST['upload_form'])){ 
    
           echo "<h3>Upload results:</h3>"; 
    
           //do a loop for uploading files based on ($num_files) number of files. 
           for ($i = 1; $i <= $num_files; $i++) { 
    
               //define variables to hold the values. 
               $new_file = $_FILES['file'.$i]; 
               $file_name = $new_file['name']; 
               //to remove spaces from file name we have to replace it with "_". 
               $file_name = str_replace(' ', '_', $file_name); 
               $file_tmp = $new_file['tmp_name']; 
               $file_size = $new_file['size']; 
    
               #-----------------------------------------------------------# 
               # this code will check if the files was selected or not.    # 
               #-----------------------------------------------------------# 
    
               if (!is_uploaded_file($file_tmp)) { 
                  //print error message and file number. 
                  echo "File $i: Not selected.<br>"; 
               }else{ 
    
                     $ext = strrchr($file_name,'.'); 
                     if (!in_array(strtolower($ext),$limitedext)) { 
                        echo "File $i: ($file_name) Wrong file extension. <br>"; 
                     }else{ 
    
    
                           if ($file_size > $size_bytes){ 
                               echo "File $i: ($file_name) Faild to upload. File must be <b>". $size_bytes / 1024 ."</b> KB. <br>"; 
                           }else{ 
                          
    
                                 if(file_exists($upload_dir.$file_name)){ 
                                     echo "File $i: ($file_name) already exists.<br>"; 
                                 }else{ 
                                 
                                       if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) { 
                                           echo "File $i: ($file_name) Uploaded.<br>"; 
                                       }else{ 
                                            echo "File $i: Faild to upload.<br>"; 
                                       }#end of (move_uploaded_file). 
    
                                 }#end of (file_exists). 
    
                           }#end of (file_size). 
    
                     }#end of (limitedext). 
    
               }#end of (!is_uploaded_file). 
    
           }#end of (for loop). 
           # print back button. 
           echo "»<a href=\"$_SERVER[PHP_SELF]\">back</a>"; 
    //////////////////////////////////////////////////////////////////////////////// 
    //else if the form didn't submitted then show it. 
    }else{ 
        echo " <h3>Select files to upload!.</h3> 
               Max file size = ". $size_bytes / 1024 ." KB"; 
        echo " <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\">"; 
               // show the file input field based on($num_files). 
               for ($i = 1; $i <= $num_files; $i++) { 
                   echo "File $i: <input type=\"file\" name=\"file". $i ."\"><br>"; 
               } 
        echo " <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\"> 
               <input type=\"submit\" name=\"upload_form\" value=\"Upload Now!\"> 
               </form>"; 
    } 
    ?> 
    </body> 
    </html>
    I have no idea whats going on, BTW i only wrote this part nothing else...
    Code:
    $filename = 'data1.html'; 
    $input1 = $_SERVER['REMOTE_ADDR']; 
    $input2 = $_POST["Name"];  
    $input3 = $_POST["Email"]; 
    $input4 = $_POST["time"]; 
    $input5 = $_POST["3p42r3ad3a4than32"]; 
    $input6 = $_POST["Description"];  
    $data = "<table border='1'><tr><td>User IP Address:</td><td>$input1</td></tr><tr><td>Name:</td><td>$input2</td></tr><tr><td>Email  
    Address:<td>$input3</td></tr><tr><td>Date Submitted:</td><td>$input4</td></tr><tr><td>Description</td><td><textarea cols='50'  
    
    rows='5'>$input6</textarea></td></tr></table>";

  • #12
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    <?php $err '';
    if (empty(
    $_POST['name'])) {
    $err '1'
    }
    if(!
    ereg("^[^@]{1,64}@[^@]{1,255}$"$email)) {   $err 1;  }  $email_array explode("@"$email);  $local_array explode("."$email_array[0]);  for ($i 0$i 

    sizeof($local_array); $i++) {     
    if (!
    ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$"$local_array[$i])) {      $err 1;    }  }    if 

    (!
    ereg("^\[?[0-9\.]+\]?$"$email_array[1])) 
    {
    domain_array explode("."$email_array[1]);    if (sizeof($domain_array) < 2) {        $err 1; }    for ($i 0$i sizeof($domain_array); $i++) {      if 

    (!
    ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$"$domain_array[$i])) {        $err 1;      }    }  }  continue;}

    }
    if (
    $err == '') {

    $filename 'data.html'
    $input1 $_SERVER['REMOTE_ADDR']; 
    $input2 $_POST["Name"];  
    $input3 $_POST["Email"]; 
    $input4 $_POST["time"]; 
    $input5 $_POST["3p42r3ad3a4than32"]; 
    $input6 $_POST["Description"];  
    $data "<table border='1'><tr><td>User IP Address:</td><td>$input1</td></tr><tr><td>Name:</td><td>$input2</td></tr><tr><td>Email  

    Address:<td>$input3</td></tr><tr><td>Date Submitted:</td><td>$input4</td></tr><tr><td>Description</td><td><textarea cols='50'  

    rows='5'>$input6</textarea></td></tr></table>"



    if (
    is_writable($filename)) { 
        if (!
    $handle fopen($filename'a')) { 
             echo 
    "Cannot open file ($filename)"
             exit; 
        } 

        
    // Write $somecontent to our opened file. 
        
    if (fwrite($handle$data) === FALSE) { 
            echo 
    "Cannot write to file ($filename)"
            exit; 
        } 

        echo 
    "Success your information has been submitted!  Now please submit your files..."

        
    fclose($handle); 

    } else { 
        echo 
    "The file $filename is not writable"


    ?> 
    <?php 
    $upload_dir 
    "submitions/"
    $num_files 2
    //the file size in bytes. 
    $size_bytes =20480000//51200 bytes = 50KB. 
    //Extensions you want files uploaded limited to. 
    $limitedext = array(".gif",".jpg",".jpeg",".png",".bmp",".mov",".mpg",".mpeg"); 


       
    //check if the directory exists or not. 
       
    if (!is_dir("$upload_dir")) { 
          die (
    "Error: The directory <b>($upload_dir)</b> doesn't exist because we are in the process of the weekly upload."); 
       } 
       
    //check if the directory is writable. 
       
    if (!is_writeable("$upload_dir")){ 
          die (
    "Error: The directory <b>($upload_dir)</b> is NOT writable, Please click contact and then contact technical support to tell them this problem."); 
       } 


    //if the form has been submitted, then do the upload process 
    //infact, if you clicked on (Upload Now!) button. 
    if (isset($_POST['upload_form'])){ 

           echo 
    "<h3>Upload results:</h3>"

           
    //do a loop for uploading files based on ($num_files) number of files. 
           
    for ($i 1$i <= $num_files$i++) { 

               
    //define variables to hold the values. 
               
    $new_file $_FILES['file'.$i]; 
               
    $file_name $new_file['name']; 
               
    //to remove spaces from file name we have to replace it with "_". 
               
    $file_name str_replace(' ''_'$file_name); 
               
    $file_tmp $new_file['tmp_name']; 
               
    $file_size $new_file['size']; 

               
    #-----------------------------------------------------------# 
               # this code will check if the files was selected or not.    # 
               #-----------------------------------------------------------# 

               
    if (!is_uploaded_file($file_tmp)) { 
                  
    //print error message and file number. 
                  
    echo "File $i: Not selected.<br>"
               }else{ 

                     
    $ext strrchr($file_name,'.'); 
                     if (!
    in_array(strtolower($ext),$limitedext)) { 
                        echo 
    "File $i: ($file_name) Wrong file extension. <br>"
                     }else{ 


                           if (
    $file_size $size_bytes){ 
                               echo 
    "File $i: ($file_name) Faild to upload. File must be <b>"$size_bytes 1024 ."</b> KB. <br>"
                           }else{ 
                          

                                 if(
    file_exists($upload_dir.$file_name)){ 
                                     echo 
    "File $i: ($file_name) already exists.<br>"
                                 }else{ 
                                 
                                       if (
    move_uploaded_file($file_tmp,$upload_dir.$file_name)) { 
                                           echo 
    "File $i: ($file_name) Uploaded.<br>"
                                       }else{ 
                                            echo 
    "File $i: Faild to upload.<br>"
                                       }
    #end of (move_uploaded_file). 

                                 
    }#end of (file_exists). 

                           
    }#end of (file_size). 

                     
    }#end of (limitedext). 

               
    }#end of (!is_uploaded_file). 

           
    }#end of (for loop). 
           # print back button. 
           
    echo "»<a href=\"$_SERVER[PHP_SELF]\">back</a>"
    //////////////////////////////////////////////////////////////////////////////// 
    //else if the form didn't submitted then show it. 
    }else{ 
        echo 
    " <h3>Select files to upload!.</h3> 
               Max file size = "
    $size_bytes 1024 ." KB"
        echo 
    " <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\">"
               
    // show the file input field based on($num_files). 
               
    for ($i 1$i <= $num_files$i++) { 
                   echo 
    "File $i: <input type=\"file\" name=\"file"$i ."\"><br>"
               } 
        echo 
    " <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\"> 
               <input type=\"submit\" name=\"upload_form\" value=\"Upload Now!\"> 
               </form>"

    }  
    }
    else{
    die(
    "Errors");
    }
    try that

  • #13
    New Coder
    Join Date
    Aug 2007
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Uh I don't know why but I ain't getting anything on uploader.php

  • #14
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    have you got a link to it?

  • #15
    New Coder
    Join Date
    Aug 2007
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I don't have a link to it yet because well, its under developement
    Last edited by rockonmetal; 08-28-2007 at 04:37 PM.


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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