www.webdeveloper.com
Results 1 to 2 of 2

Thread: How can I detect empty fields in the following script by using "trim"?

  1. #1
    Join Date
    Feb 2012
    Posts
    64

    How can I detect empty fields in the following script by using "trim"?

    Hi, I have a collection of PHP scripts that allow for text to be appended to an existing file by the user entering in the appended details into a text box. However, I would like it so that they cannot enter in blank spaces or so that they cannot just leave the text box blank, and I was wondering how this could be done by using the trim function. This is my appending file PHP script:

    Code:
    <!--Here, I am starting a PHP script-->
    <?php
    //An if statement is being used here so that if the contents of the text box in the form below that is called append is not null/empty, then this branch will run
    if($_POST['append'] !=null)
    {
    //Here, I am creating a variable called filename and am assiging it a value of the file path to a file called denman2.txt
    $filename="C:/xampp/htdocs/rcm/denman2.txt";
    //Here, I am creating a variable called file, and am assiging it a value of the fopen keyword that is appending (as shown by the "a" argument) to the value associated with the filename variable 
    $file=fopen($filename, "a");
    //Here, I am creating a variable called msg that is essentially the formatted string that will display "Updated Information:" and then get the text that was entered into the text box field called "append" in the form. The fputs variable is then used to append this formatted string to the file associated with the filename variable
    $msg="<p>Updated Information: " .$_POST['append']. "</p><br>";
    fputs ($file, $msg);
    //Here, I am using the fclose command to close the value associated with the file variable
    fclose($file);
    }
    //Here, I am ending the PHP script
    ?>
    Any help is appreciated!

  2. #2
    Join Date
    Nov 2002
    Posts
    2,632
    trim's purpose isn't what you are looking for. You want isset or empty.

    http://php.net/manual/en/function.isset.php
    http://www.php.net/manual/en/function.empty.php

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles