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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Weird error, I can't figure it out...

    Here is my code. All my class files and includes are valid and every other page I've wrote has worked except this one, and it's not even giving me an error message... It just gives me a blank page with absolutely no source code or anything and I don't know why. I've proofread it multiple times and cannot find the mistake; my guess is that it's within the $message variable but not sure.

    Here is the code:

    Code:
    <?php
    
    include 'inc.common.php';
    $page = new Page ( 'Contact Us' );
    
    ?>
    <h2>Contact Us</h2>
    <div class="text">
    <?php
    
    if ( isset ( $_POST['send'] ) )
    {
     $errors = array();
     $attr = array ( 'nm'  => $_POST['name'],
         'em'  => $_POST['email'],
         'sj'  => $_POST['subject'],
         'mg'  => $_POST['message']
         );
     if ( strlen ( $attr['nm'] ) < 2 || strlen ( $attr['nm'] ) > 50 )
      $errors[] = 'Please enter your name.';
     
     if ( strlen ( $attr['em'] ) < 5 || strlen ( $attr['em'] ) > 70 )
      $errors[] = 'Please enter a valid e-mail address.';
     
     if ( strlen ( $attr['sj'] ) < 2 || strlen ( $attr['sj'] ) > 30 )
      $errors[] = 'Please enter a subject that is between 2 and 30 characters in length.';
     
     if ( strlen ( $attr['mg'] ) < 2 || strlen ( $attr['mg'] ) > 4000 )
      $errors[] = 'Please enter a valid message.';
     
     if ( count ( $errors ) > 0 )
     {
      echo '  <blockquote>' . "\n",
        '   <span class="alert">The following errors occurred while trying to process your request:</span>' . "\n",
        '   <ul>' . "\n";
      foreach ( $errors as $errNo => $err )
      {
       echo '    <li><strong>(#' . ( $errNo + 1 ) . '):</strong> ' . $err . '</li>' . "\n";
      }
      echo '   </ul>' . "\n",
        '  </blockquote>' . "\n";
     } else {
      $headers = "From: $attr['em']\r\n";
      $headers .= 'Content-Type: text/html';
     
      $message = nl2br ( $attr['mg'] );
     
      $to = '';
     
      $body = '<tt>THIS IS A MESSAGE GENERATED BY THE CONTACT FORM AT .ORG</tt><br />
          The following information was provided:<br />
          <blockquote>
          <strong>Name:</strong> ' . $attr['nm'] . '<br />
          <strong>Subject:</strong> ' . $attr['sj'] . '<br />
          <strong>Reply-To:</strong> ' . $attr['em'] . '
         </blockquote>
         <p><strong>Message:</strong></p>
         <p>' . $message . '</p>';
         
      $subject = 'Contact Form: ' . $attr['sj'];
     
      mail ( $to, $subject, $body, $headers );
      echo '  <blockquote>' . "\n",
        '   <span class="alert">Message sent successfully, expect a response within 24 hours.</span>' . "\n",
        '  </blockquote>' . "\n";
     }
    }
    
    ?>
    <form action="?" method="post">
     <fieldset>
      <fieldset>
       <legend>Your Name</legend>
       <input type="text" name="name" value="" size="30" />
      </fieldset>
      <fieldset>
       <legend>Your E-Mail Address</legend>
       <input type="text" name="email" value="" size="50" />
      </fieldset>
      <fieldset>
       <legend>Message Subject</legend>
       <input type="text" name="subject" value="" size="40" />
      </fieldset>
      <fieldset>
       <legend>Message</legend>
       <textarea name="message" rows="4" cols="60"></textarea>
      </fieldset>
      <input type="submit" name="send" value="Send" />
     </fieldset>
    </form>
    </div>
    </div>
    <?= $page->genFooter() ?>
    I edited out e-mail addresses etc

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    White pages are usually parser errors or potentially memory issues.
    Add error reporting to the top of the page with:
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL E_STRICT); 
    And post the error. Alternatively, check the error logs on the server which will log these as well.
    You definitely have HTML output otherwise, so this indicates a parse error. If I just copy this into PHP tags. . .
    PHP Code:
    <?php

    include 'inc.common.php';
    $page = new Page 'Contact Us' );

    ?>
    <h2>Contact Us</h2>
    <div class="text">
    <?php

    if ( isset ( $_POST['send'] ) )
    {
     
    $errors = array();
     
    $attr = array ( 'nm'  => $_POST['name'],
         
    'em'  => $_POST['email'],
         
    'sj'  => $_POST['subject'],
         
    'mg'  => $_POST['message']
         );
     if ( 
    strlen $attr['nm'] ) < || strlen $attr['nm'] ) > 50 )
      
    $errors[] = 'Please enter your name.';
     
     if ( 
    strlen $attr['em'] ) < || strlen $attr['em'] ) > 70 )
      
    $errors[] = 'Please enter a valid e-mail address.';
     
     if ( 
    strlen $attr['sj'] ) < || strlen $attr['sj'] ) > 30 )
      
    $errors[] = 'Please enter a subject that is between 2 and 30 characters in length.';
     
     if ( 
    strlen $attr['mg'] ) < || strlen $attr['mg'] ) > 4000 )
      
    $errors[] = 'Please enter a valid message.';
     
     if ( 
    count $errors ) > )
     {
      echo 
    '  <blockquote>' "\n",
        
    '   <span class="alert">The following errors occurred while trying to process your request:</span>' "\n",
        
    '   <ul>' "\n";
      foreach ( 
    $errors as $errNo => $err )
      {
       echo 
    '    <li><strong>(#' . ( $errNo ) . '):</strong> ' $err '</li>' "\n";
      }
      echo 
    '   </ul>' "\n",
        
    '  </blockquote>' "\n";
     } else {
      
    $headers "From: $attr['em']\r\n";
      
    $headers .= 'Content-Type: text/html';
     
      
    $message nl2br $attr['mg'] );
     
      
    $to '';
     
      
    $body '<tt>THIS IS A MESSAGE GENERATED BY THE CONTACT FORM AT .ORG</tt><br />
          The following information was provided:<br />
          <blockquote>
          <strong>Name:</strong> ' 
    $attr['nm'] . '<br />
          <strong>Subject:</strong> ' 
    $attr['sj'] . '<br />
          <strong>Reply-To:</strong> ' 
    $attr['em'] . '
         </blockquote>
         <p><strong>Message:</strong></p>
         <p>' 
    $message '</p>';
         
      
    $subject 'Contact Form: ' $attr['sj'];
     
      
    mail $to$subject$body$headers );
      echo 
    '  <blockquote>' "\n",
        
    '   <span class="alert">Message sent successfully, expect a response within 24 hours.</span>' "\n",
        
    '  </blockquote>' "\n";
     }
    }

    ?>
    <form action="?" method="post">
     <fieldset>
      <fieldset>
       <legend>Your Name</legend>
       <input type="text" name="name" value="" size="30" />
      </fieldset>
      <fieldset>
       <legend>Your E-Mail Address</legend>
       <input type="text" name="email" value="" size="50" />
      </fieldset>
      <fieldset>
       <legend>Message Subject</legend>
       <input type="text" name="subject" value="" size="40" />
      </fieldset>
      <fieldset>
       <legend>Message</legend>
       <textarea name="message" rows="4" cols="60"></textarea>
      </fieldset>
      <input type="submit" name="send" value="Send" />
     </fieldset>
    </form>
    </div>
    </div>
    <?= $page->genFooter() ?>
    Nothing jumps out in particular as being off. The strings look correct and it appears the braces and brackets count up. It also looks like the lines are all terminated, so I'd be looking squarely at the new Page call.

  • #3
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    332
    Thanks
    2
    Thanked 47 Times in 46 Posts
    Quote Originally Posted by Helljumper View Post
    PHP Code:
    <form action="?" method="post"
    Why do you have a question mark(?) for the form action attribute. I've never seen that one.

    Try the below to point the form to the same script as it is on:
    PHP Code:

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    OR:
    PHP Code:

    <form action="" method="post">  <!-- Leaving it blank is ok to point it to the same script --> 

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by Redcoder View Post
    Why do you have a question mark(?) for the form action attribute. I've never seen that one.
    It will still wok with the question mark. There are a couple of uses for it however here is the first one that springs to mind:

    You have a switch in your php that checks for a query string. Now while you could use a default section or a ternary operator to check the status and set it to '' if nothing is sent, some people prefer just to do it with a plain question mark.

    Just because you've not seen it doesn't mean its invalid.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Posting Permissions

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