...

View Full Version : Weird error, I can't figure it out...



Helljumper
10-15-2012, 09:44 PM
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:


<?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

Fou-Lu
10-15-2012, 10:44 PM
White pages are usually parser errors or potentially memory issues.
Add error reporting to the top of the page with:


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

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() ?>


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.

Redcoder
10-16-2012, 10:34 AM
<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:



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



OR:



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

tangoforce
10-16-2012, 12:20 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum