...

View Full Version : Getting form errors to appear in right place on page



DJ Hands3
03-08-2009, 02:11 PM
I a have php web form and have managed to get the users values displayed on the next page so they can see what they have sent but when the user for example dosent fill everything in it displays an error of whatever they havent done i cant get it to format in the same way as if the form was done correctly, I know its something to do with the script outputing it directly rather than reading from the page so the css dosent kick in?

any ideas?




<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];


if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h1>Contact dj-promo.co.uk</h1>
<div class="box">
<h2 class="box">
Form error
</h2>
<div class="wysiwyg">Please enter a valid email address
</div>
<div class="filebox_links">
<a href="contact.php">Click here to go back</a>
</div>";
$badinput = "<h2>Feedback was NOT submitted</h2>";
echo $badinput;
die (" ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h1>Contact dj-promo.co.uk</h1>
<div class="box">
<h2 class="box">
Form error
</h2>
<div class="wysiwyg">Please fill out all fields
</div>
<div class="filebox_links">
<a href="contact.php">Click here to go back</a>
</div>";
die (" ");
}

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ;
$subject = $attn;

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

$from = "From: $visitormail\r\n";


mail("mysite@mysite.co.uk", $subject, $message, $from);

?>
<h1>Contact dj-promo.co.uk</h1>
<div class="box">
<h2 class="box">
Use the form below to get in touch
</h2>

<div class="wysiwyg"><Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

Attention: <?php echo $attn ?>
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?>
</div>
<div class="filebox_links">
<br /><br />
<a href="contact.php"> Next Page </a>
</div>

abduraooft
03-08-2009, 03:05 PM
You need to escape the inner double quotes, like

echo "<h1>Contact dj-promo.co.uk</h1>
<div class=\"box\">
<h2 class=\"box\">
Form error
</h2>
<div class=\"wysiwyg\">Please enter a valid email address
</div>
<div class=\"filebox_links\">
<a href=\"contact.php\">Click here to go back</a>
</div>"; and make sure that error reporting is turned on.

DJ Hands3
03-08-2009, 09:18 PM
Thanks for that almost there with it just run into a problem with it I know what I need to do but not to sure how to the php at the minute is



<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];


if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h1>Contact dj-promo.co.uk</h1>
<div class=\"box\">
<h2 class=\"box\">
Form error
</h2>
<div class=\"wysiwyg\">Please enter a valid email address
</div>
<div class=\"filebox_links\">
<a href=\"contact.php\">Click here to go back</a>
</div>";
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h1>Contact dj-promo.co.uk</h1>
<div class=\"box\">
<h2 class=\"box\">
Form error
</h2>
<div class=\"wysiwyg\">Please enter all details requested
</div>
<div class=\"filebox_links\">
<a href=\"contact.php\">Click here to go back</a>
</div>";
}

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ;
$subject = $attn;

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

$from = "From: $visitormail\r\n";


mail("mysite@mysite.co.uk", $subject, $message, $from);

?>
<h1>Contact dj-promo.co.uk</h1>
<div class="box">
<h2 class="box">
Use the form below to get in touch
</h2>

<div class="wysiwyg"><Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

Attention: <?php echo $attn ?>
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?>
</div>
<div class="filebox_links">
<a href="contact.php">Send another comment</a>
</div>


You may see I have removed


$badinput = "<h2>Feedback was NOT submitted</h2>";
echo $badinput;
die (" ");


This was because with die (" "); still adds text else where other than the css table thats created, the way you said to escape the inner double quotes worked great, iv come across another problem now im left with this showing constantly



<h1>Contact dj-promo.co.uk</h1>
<div class="box">
<h2 class="box">
Use the form below to get in touch
</h2>

<div class="wysiwyg"><Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

Attention: <?php echo $attn ?>
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?>
</div>
<div class="filebox_links">
<br /><br />
<a href="contact.php"> Next Page </a>
</div>


What im thinking to do is create an argument like the above 2 but instead of having if empty or wrong email, having one if alll values filled out correct to show the above php code then it should work? but doing this requires a bit more knowledge than what I have on the matter I will attempt to try :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum