Printing user validation errors from .php file back onto a form

Hey all. I have written a simple contact form with the extention .php. It includes the php validation and the form inputs on one page. If the input does not validate, a warning in red is printed at the top of the form after the user pushes submit. When I cut and paste the php validation code into a seperate file, the validation errors print on a blank screen. What I want is to have the same results with a seperate php file as I do when I include the php code on the form. (print errors from the seperate php validation file back onto the form).  Thanks for taking a look
<h1><span class="bodyheader1">Contact </span><span class="bodyheader2">Us</span></h1>
    <p class="subheading">Tell us what's on your mind:</p>
    <?php
    if(isset($_POST['send_comment']))
        //Validating the comment field
        //checking if a first_name field has been entered
        if($_POST['first_name'] != "")
            //Saitizing first_name with a filter
            $_POST['first_name'] = filter_var($_POST['first_name'], FILTER_SANITIZE_STRING);
            //Checking for no input
            if($_POST['first_name'] == "")
                //If no input, return error message
                $errors .='Please enter a valid first name.<br/>';
        else
            //Error message
            $errors .='Please enter your first name.<br/>';
        //Validating the last_name field
        //checking if last_name has been entered
        if($_POST['last_name'] != "")
            //Saitizing last_name with a filter
            $_POST['last_name'] = filter_var($_POST['last_name'], FILTER_SANITIZE_STRING);
            //Checking for no input
            if($_POST['last_name'] == "")
                //If no input, return error message
                $errors .='Please enter a valid last name.<br/>';
        else
            //Error message
            $errors .='Please enter your last name.<br/>';
        if($_POST['email'] != "")
            $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
            if (!filter_var($email, FILTER_VALIDATE_EMAIL))
                $errors .= "$email is not a valid email address.<br/>";
        else
            $errors .= 'Please enter your email address.<br/>';
        //Validating the comment field
        //checking if a comment has been entered
        if($_POST['comment'] != "")
            //Saitizing comment with a filter
            $_POST['comment'] = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
            //Checking for no input
            if($_POST['comment'] == "")
                //If no input, return error message
                $errors .='Please enter a comment.<br/>';
        else
            //Error message
            $errors .='Please enter a comment.<br/>';
        if(!$errors)
            $mail_to = '[email protected]';
            $subject = 'Contact form ' . $_POST['first_name'];
            $message = 'First Name: ' . $_POST['first_name'] . "\n";
            $message .= 'Last Name: ' . $_POST['last_name'] . "\n";
            $message .= 'Email: ' . $_POST['email'] . "\n";
            $message .= 'Comment: ' . $_POST['comment'] . "\n\n";
            mail($mail_to, $subject, $message);
            echo "<script>document.location.href='thankyou.html'</script>";
        else
            echo '<div style="color: red">' . $errors . '<br/></div>';
?>
*All fields are required<br />
<br />
    <form name="contact" method="post" action="contact.php">
        <p>First Name: <br />
          <input name="first_name" type="text" value="<?php echo $_POST['first_name']; ?>" size="30" maxlength="50" /><br />
          <br />
          Last Name: <br />
          <input name="last_name" type="text" value="<?php echo $_POST['last_name']; ?>" size="30" maxlength="50" /><br />
          <br />
          E-mail: <br />
          <input name="email" type="text" value="<?php echo $_POST['email']; ?>" size="40" maxlength="200" /><br />
          <br />
          Comment: <br />
          <textarea name="comment" rows="5" cols="50"><?php echo $_POST['comment'];?></textarea>
          <br />
         </p>
      <p><input type="submit" name="send_comment" />
      </p>
    </form>

You want the form to submit its results to a separate file which processes the data.  If this separate file finds errors, you want it to return control to the form page which would a) display the error messages, and b) populate the fields with the data entered?
If that's the case, then the processing file would have to send the errors and the data back to the form page either as a) URL variables, b) a cookie, or c) entries in a database.
Does that help?

Similar Messages

  • After clean install of Snow Leopard, Time Machine did not restore all files.  When I try to restore these files I get "Not enough disk space" error.  What do I need to do to get these important files back onto my Mac from my external hard drive??

    After clean install of Snow Leopard, Time Machine did not restore all files.  When I try to restore these files I get "Not enough disk space" error.  What do I need to do to get these important files back onto my Mac from my external hard drive?? 

    Janet.b wrote:
    About 3 years old...pretty dated now I guess.  Am thinking I may just need to have it upgraded by a Mac tech.
    For what the Apple Store's charge you can buy almost buy a new computer.
    Just for giggles I brought my old laptop in for a drive upgrade and asked, they wanted $600 for a drive that only cost $120 at the time and it was a slow 5,400 RPM drive. The new Mac's of a similar make were going for $1000.
    I did the drive replacement myself, got a faster drive of better quality for $300 instead.
    Then another time I asked for a RAM upgrade from 4GB to 8GB, they wanted to charge $400 + $35 for the labor.
    The same RAM is on Crucial.com for $90 and all I need is a 00 micro phillips screwdriver.
    So you see what's going on here.
    I think what you should do, if your out of warranty/AppleCare, is to call up the local PC tech guy who also does Mac's and have them fix you right up.
    They can offer more personalized care which you need. Clone your old drive to the new and everything.
    With Apple they are overworked at the Genius Bar and just place roadblocks so you buy a new machine instead.
    For instance, all new iMac's now have proprietary drive software installed on the hard drives for heat monitoring. So now the only choice a user has is to bring their iMac into a Apple Store for a very expensive drive upgrade, which a person then decides the money is better spent buying a new machine.

  • How to print only fatal error in log file in tomcat4.1

    Hi all ,i m using tomcat4.1
    1> i want to print only fatal error in log file ,but it print all thing in log file ,how i can avoid it(because i think this process is consuming my resource)
    assume below ip address is corect:
    this is exact printing in my log file
    .12.2.3.3  - - [24/Oct/2007:00:00:00 5050] "GET /menu/ir.jsp HTTP/1.1" 200 2828
    12.2.3.3  - - [24/Oct/2007:00:00:00 5050] "GET /menu/bottomAdv.jsp HTTP/1.1" 200 528
    12.2.3.3  - - [24/Oct/2007:00:00:02 5050] "GET /menu/alerts.jsp HTTP/1.1" 200 323
    12.2.3.3  - - [24/Oct/2007:00:00:02 5050] "GET /alerts/createAlertShow.jsp HTTP/1.1" 200 26140
    123.2.3. - - [24/Oct/2007:00:00:05 5050] "GET /menu/getsensex.jsp HTTP/1.1" 200 642
    12.2.3.3 - - [24/Oct/2007:00:00:05 5050] "GET /menu/latestRecommendation.jsp HTTP/1.1" 200 5210
    12.2.3.3 - - [24/Oct/2007:00:00:05 5050] "GET /portfolio/watchlist/displayWatchlistItemsShow.jsp?watchlistId=20070509013642953_1&watchlistName=First&refreshRate=900&flag=1 HTTP/1.1" 500 7257
    12.2.3.3  - - [24/Oct/2007:00:00:05 5050] "GET /menu/iwealthNewsScroller.jsp HTTP/1.1" 200 2828
    112.23.3  - - [24/Oct/2007:00:00:06 5050] "GET /menu/alerts.jsp HTTP/1.1" 200 323
    112.23.3 - - [24/Oct/2007:00:00:06 5050] "GET /menu/bottomAdv.jsp HTTP/1.1" 200 528
    12.2.3.3  - - [24/Oct/2007:00:00:07 5050] "GET /menu/alerts.jsp HTTP/1.0" 200 323
    12.2.3.3 - - [24/Oct/2007:00:00:09 5050] "POST /Transaction/equity/modifyConfirmShow.jsp?DelId=0 HTTP/1.1" 200 28661
    12.2.3.3  - - [24/Oct/2007:00:00:09 5050] "GET /menu/getsensex.jsp HTTP/1.1" 200 6422>what will happen if i change timestamp="false" and what is the significance of verbosity="1" or "2" or "3" ,or "4" and what happen if i change debug="1" or other in below code
    <Logger className="org.apache.catalina.logger.FileLogger" debug="0" directory="logs" prefix="www.xyz_log." suffix=".txt" timestamp="true" verbosity="4"/>Edited by: Deepak23 on Oct 24, 2007 10:41 PM
    Edited by: Deepak23 on Oct 24, 2007 11:16 PM

    One of my standard answers (which will explain the use of Directory Objects)...
    The UTL_FILE_DIR parameter has been deprecated by oracle in favour of direcory objects because of it's security problems.
    The correct thing to do is to create a directory object e.g.:
    CREATE OR REPLACE DIRECTORY mydir AS 'c:\myfiles';Note: This does not create the directory on the file system. You have to do that yourself and ensure that oracle has permission to read/write to that file system directory.
    Then, grant permission to the users who require access e.g....
    GRANT READ,WRITE ON DIRECTORY mydir TO myuser;Then use that directory object inside your FOPEN statement e.g.
    fh := UTL_FILE.FOPEN('MYDIR', 'myfile.txt', 'r');Note: You MUST specify the directory object name in quotes and in UPPER case for this to work as it is a string that is referring to a database object name which will have been stored in uppercase by default.

  • How to deal with validation errors from DAO layer.

    I have been pondering on how to deal with validation errors from DAO layer.
    Lets say you have a DAO that can save a car object. A car has a year, make, model, vin and so on. During the save operation of this DAO, it validates the car attributes to see if they pass some business rules. If it does not it throws some validation exception that contains all the validation errors. These validation errors know nothing about jsf or my components it just knows what attributes on the object are invalid and why.
    If I just want to show those errors at the top of the page that would be no problem I could just create some FacesMessage objects and add them to the FacesContext messages. But if the DAO layer is telling me that the make attribute is invalid it would be nice to map it to the make field on the screen. I am wondering if any of you have tackled this problem or have some ideas on how to tackle it?
    Brian

    Let it throw an exception with a self explaining message, then catch it and embed that message in a FacesMessage.
    Or let it throw more specific exception types (InvalidCarMakeException extends CarDAOException and so on) and let JSF handle it with own FacesMessage message.

  • How to print out the data from the file ?

    hi all,
    i have upload my file to here :
    [http://www.freefilehosting.net/ft-v052010-05-09 ]
    anyone can help me to print out the data from the file ?
    the content of the file should be like this :
    185.56.83.89 156.110.16.1 17 53037 53 72 1
    and for the seven column is
    srcIP dstIP prot srcPort dstPort octets packets

    hi all,
    i have try to do this
    public static void Readbinary() throws Exception
              String file = "D:\\05-09.190501+0800";
              DataInputStream dis = new DataInputStream(new FileInputStream(file));
              //but then how to read the content ??????can you give me more hint ?????
    i have find the netflow v5 structure by C
    struct NFHeaderV5{
    uint16_t version; // flow-export version number
    uint16_t count; // number of flow entries
    uint32_t sysUptime;
    uint32_t unix_secs;
    uint32_t unix_nsecs;
    uint32_t flow_sequence; // sequence number
    uint8_t engine_type; // no VIP = 0, VIP2 = 1
    uint8_t engine_id; // VIP2 slot number
    uint16_t reserved; // reserved1,2
    struct NFV5{ 
    ipv4addr_t srcaddr; // source IP address
    ipv4addr_t dstaddr; // destination IP address
    ipv4addr_t nexthop; // next hop router's IP address
    uint16_t input; // input interface index
    uint16_t output; // output interface index
    uint32_t pkts; // packets sent in duration
    uint32_t bytes; // octets sent in duration
    uint32_t first; // SysUptime at start of flow
    uint32_t last; // and of last packet of flow
    uint16_t srcport; // TCP/UDP source port number or equivalent
    uint16_t dstport; // TCP/UDP destination port number or equivalent
    uint8_t pad;
    uint8_t tcp_flags; // bitwise OR of all TCP flags in flow; 0x10
    // for non-TCP flows
    uint8_t prot; // IP protocol, e.g., 6=TCP, 17=UDP, ...
    uint8_t tos; // IP Type-of-Service
    uint16_t src_as; // originating AS of source address
    uint16_t dst_as; // originating AS of destination address
    uint8_t src_mask; // source address prefix mask bits
    uint8_t dst_mask; // destination address prefix mask bits
    uint16_t reserved;
    but how to translate the structure to java,then get the data from the file ?
    Edited by: 903893 on Dec 21, 2011 10:52 PM

  • Getting your photos from your computer back onto your camera

    I downloaded pictures from my camera to my computer and when i unplugged my camera all the pictures were deleted from my camera's memory card. I want to know how to get the pictures from my computer back onto my camera. Please Help!!!
    thanks,
    Alexa A.

    Alexa:
    Welcome to the Apple Discussions. Unless the camera can be mounted on the desktop like an external storage device you'll have to get a card reader, mount the memory card with it and copy the photos back to the card. I'd take one photo with the camera first so there will be the correct folder configuration on the card to put the photos.
    IMO it's much safer to upload the photos to a folder on the desktop with Image Capture or a card reader and then import from there into iPhoto. Too many reports of incomplete or aborted uploads and complete deletions from the camera.
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto (iPhoto.Library for iPhoto 5 and earlier) database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 6 and 7 libraries and Tiger and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • HT4527 I just had to clear the hard drive on my computer - now I want to transfer all the music and pictures from my ipad back onto my computer.  'Sync' doesn't do it.  What do I do?

    I had toclear the hard drive of my computer and reinstall Windows 7.  Now I want to transfer all the music and photos from my iPad back onto my computer.  I authorized the computer (it is the ONLY computer authorized on this account - and this is the ONLY account on this iPad).  ITunes then downloaded my purchases...or at least it tried - out of the hundreds of tracks I have purchased, it managed one album that I bought over a year ago and NOTHING else.  So I tried to Sync - since on older versions of iTunes (that were SO MUCH MORE user friendly) that would do the job -transferring things that were only on the iPad onto the computer and vice versa.  It doesn't do that anymore.  So I went from my iPad's summary to the Music tab - the box for Music was not checked but when I checked it said the only thing it could do was erase EVERYTHING from my iPad and replace it with what was on my computer (that ONE album).  What is going on?
    Why hasn't iTunes downloaded my other purchases since I authorized the computer? (there are over 3,000 tracks...not 18)
    How can I download my iPad to my computer?

    -Me again - it also won't upload the few new pictures I have on the computer onto the iPad without deleting all the photos that are already there....

  • We transferred purchases / synced an iPod touch to a toshiba laptop, and then updated the ipod. we can no longer put the files back onto the ipod. what are we doing wrong]

    we transferred purchases and synced from a iPod touch to a toshiba laptop, after it updated and synced again we have been unable to put the files back onto the ipod. the computer will not let us drag or copy paste files, and when we tried to " export" the library to the documents folder, it only showed up in code.  we have books and music we would like to reload to the ipod.

    Hello Jean164,
    Thank you for using Apple Support Communities!
    It sounds like you are unable to manually put your content back on your iPod Touch.
    It seems like you may need to re enable Manually Manage Music now that the device has been updated, and this article should help with that.
    Managing content manually on iPhone, iPad, and iPod
    http://support.apple.com/kb/HT1535
    Cheers,
    Sterling

  • My iTunes library has been replaced with my husband's iTunes library on our iMac. How do I get my iTunes library from my iPhone back onto my iTunes library on the iMac?

    My iTunes library has been replaced with my husband's iTunes library on our iMac. How do I get my iTunes library from my iPhone back onto my iTunes library on the iMac?  Help!!!

    Well, this is a problem, because the only material you can transfer from your iPhone (using only Apple software) is material you purchased in the iTunes Store.
    To do that, plug your iPhone into iTunes, then choose File > Devices > Transfer Purchases from iTunes' menu.
    Generally speaking, you should restore your iTunes library from your computer's backup.

  • How do I copy photos from my computer back onto my SD memory card?

    I have saved my photos from my camera SD memory card into iphoto. I then deleted the photos from my SD card. Now I want to copy some of these photos back onto the SD card. What are the steps to copy photos from my computer back onto my SD card? (One reason I want to do this is so I can play some of them on my digital photo frame).

    Select the photos in iPhoto and export them in the size you want for your frame to a desktop folder (file menu ==> export)
    Mount the card to the desktop (in your camera if it mounts - otherwise in a USB card reader) and drag the photos form the desktop folder to the card
    LN

  • We just got our computer fixed after a virus and found we lost our itunes. Can i transfer our family's songs(etc.) from our ipods back onto itunes?

    We just got our computer fixed after a virus and found we lost everything from our itunes. Can i transfer our family's songs(etc.) from our ipods back onto itunes?

    Copy everything from your backup copy of your computer.
    If for some reason you have failed to maintain a backup copy, not good, then you can transfer itunes purchases from an ipod.  Without syncing:  File>Transfer Purchases

  • I recently had to do a complete system restore how do i transfer my itunes library from my iphone back onto my computer

    I recently had to do a complete system restore on my computer. How do i transfer the itunes content from my iphone back onto my computer?

    You don't.
    The music sync is one way - computer to iphone. The only exception is itunes purchases.
    The iphone is not a backup device.
    It has always been very basic to always maintain a  backup copy of your computer. Certainly you did not restore your system without making sure that your backup copy was up to date.
    Use your backup copy to put everything back.
    If for some reason you have failed to maintain a backup ( not good) then you can transfer itunes purchases from the iphone.  Without syncing:  File>Transfer Purchases

  • My itunes was deleted off of my computer. Is there any way I can get my music from my Ipod back onto my computer?

    Most of my music is from CDs that I don't have anymore. I've got over a thousand songs and most of them were deleted when my computer crashed. Is there any way I can get my music from my ipod back onto my computer? Any sort of program you can buy? Thanks for any help, I really appreciate it!

    Recover media from iPod
    See this post from forum regular Zevoneer for options on moving your iPod data back to your computer.
    tt2

  • HT201269 I restored my iphone and now it has gone back to factory settings. How do I transfer all the purachsed items from my itunes back onto the phone?

    I restored my iphone and now it has gone back to factory settings. How do I transfer all the purachsed items from my itunes back onto the phone?

    Hello whytea4
    Check out the articles below and choose the one for your computer to sync media and apps to your iPhone.
    iTunes 11 for Mac: Set up syncing for iPod, iPhone, or iPad
    http://support.apple.com/kb/PH12113
    iTunes 11 for Windows: Set up syncing for iPod, iPhone, or iPad
    http://support.apple.com/kb/PH12313
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

  • I had to restore my computer to the factory settings, which means my itunes library was lost except for what was on my ipod nano.  How do pull the songs from my ipod back onto my computer?

    I had to restore my computer to the factory settings, which means my itunes library was lost except for what was on my ipod nano.  How do pull the songs from my ipod back onto my computer?  I have over 200 songs.  There is no way I can re-purchase them!  Any help?

    How to use your iPod to move your music to a new computer 

Maybe you are looking for