SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Testing form validation using PHP/WAMP

    Gudday all
    I am trying on my laptop to test a catalogue request form. The JS validation seems to work ok. (Had a devil of a job turning off JS in IE7. It is not obvious. Why don't they have a button called called enable JS? Oh wait its Microsoft ).
    I have WAMP2 setup on my laptop.
    Anyway getting errors in both IE7 & FF, but both different.
    The code for calling the PHP from the form is
    Code:
    <form method="post" name="catalogue" onsubmit="return valFrm()" action="cataloguetest-6.php";">
    ..
    <input name="catalogue" id="catalogue" type="submit" value="Request catalogue">
    </form>
    and the PHP itself is
    PHP Code:
    <?php
    //This php is a new one to validate the form using php on 270609. Uses catalaoguerequestj.htm
    // Function to display form


    if (!isset($_POST['catalogue'])) 
     {  
      
    //empty from submitted
      
    header('location: cataloguerequestj.htm'); 
      
    //showForm();
     

     else 
      {
       
    //Form has some data entered
       //Init error variables
       
    $errorName  false;
       
    $errorAddress false;
       
    $errorCity  false;
       
    $errorState  false;
       
    $errorPostcode  false;
       
    $errorEmail false
       
       
    $name  = isset($_POST['name'])  ? trim($_POST['name'])  : '';  
       
    $address  = isset($_POST['address'])  ? trim($_POST['address'])  : '';
       
    $city  = isset($_POST['city'])  ? trim($_POST['city'])  : ''
       
    $state  = isset($_POST['state'])  ? trim($_POST['state'])  : '';
       
    $postcode  = isset($_POST['postcode'])  ? trim($_POST['postcode'])  : '';   
       
    $email = isset($_POST['email']) ? trim($_POST['email']) : '';   
       
       
    // Display the form again as there was an error   
       
    if ($errorName || $errorEmail || $errorMesg
        {     
          
    header('location: cataloguerequestI.htm');    
          
    //showForm($errorName,$errorEmail,$errorMesg);
        

        else 
        {
          
    $sendto "tlknell@tpg.com.au"
          
    $subject "Petals & Patches catalogue request"
          
    $message = <<<TEXT
          I would a copy of the Petals & Patches catalogue send to me please -\r\n
            Media: 
    $media\r\n
            Name: 
    $name\r\n
            Address: 
    $address\r\n
            City/Town: 
    $city\r\n
            State: 
    $state\r\n
            Post code: 
    $postcode\r\n
            Country: 
    $country\r\n
            E-mail: 
    $email\r\n
            Telephone: 
    $telephone
            TEXT;
          // sending e-mail
          mail("
    $sendto", "$subject", "$message");
          header('Location: thankyou.htm');
          exit();
        }
      
      
     } 
    ?>
    Initially I want to check what happens if an empty from is submitted. The form should just show itself (how do we display an error message saying 'No data was submitted'?).
    However the errors I get are
    a) IE7 - All I see is the PHP code rendered on the screen
    b) FF - I am getting the error message
    "Parse error: syntax error, unexpected $end in C:\wamp\www\PetalsandPatches\cataloguetest-6.php on line 60 ".
    Line 60 is the last line of the PHP.

    Perhaps both errors are in fact the same thing? I cannot see any syntax error but I have been looking for a long time and can't see the wood for the trees anymore.

    Any ideas gratefully accepted.
    ========================
    Carn the Tiges!
    www.petalsandpatches.com

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately it's always the small things that make us rip our hair out.

    In your heredoc statement which you're assigning to $message, the end-of-string command is TEXT. For this to be recognised it must be the first and last thing on the line - so simply remove all spaces from infront of 'TEXT;' and voila.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that Arkinstall.
    That cured the FF issue.
    But IE still has the problem of showing the php code when I submit the form. Does IE has any other quirks? (I wouldn't be suprised)
    ========================
    Carn the Tiges!
    www.petalsandpatches.com

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's nothing to do with IE - PHP is browser independent because it doesn't even touch the browser; it's all done on the server beforehand.

    Are you sure you're going through localhost and not just looking at the file directly?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just checked. I am running through the localhost (WAMP2) for both FF and IE.
    FF is fine but not IE.
    I am wondering if it is some setting on my IE.
    When I turned off JS on IE maybe I turned the wrong thing off or on?
    ========================
    Carn the Tiges!
    www.petalsandpatches.com

  6. #6
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You seem to be using JS in your script so you cant assume that IE will work properly if you have JS turned off in IE.

  7. #7
    SitePoint Zealot
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am doing client side and sever side testing of the form submission. The client side seems to be working ok so I have turned off JS in IE (well I hope I have).
    I now want to test the server side with PHP hence my apparent troubles.
    ========================
    Carn the Tiges!
    www.petalsandpatches.com

  8. #8
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Could you not just comment out the JavaScript instead of messing with the settings? Anyways validate the returning HTML output. It might be messing IE up.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  9. #9
    SitePoint Zealot
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    Could you not just comment out the JavaScript instead of messing with the settings? Anyways validate the returning HTML output. It might be messing IE up.
    Logic_earth
    What exactly do you mean by the last comments
    "Anyways validate the returning HTML output. It might be messing IE up."
    ========================
    Carn the Tiges!
    www.petalsandpatches.com

  10. #10
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure but maybe he meant to use validator / or make sure the html output is valid html.
    http://validator.w3.org/


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
  •