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 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    90
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Getting form errors to appear in right place on page

    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 Code:

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

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    You need to escape the inner double quotes, like
    Code:
    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.
    Last edited by abduraooft; 03-08-2009 at 04:08 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    90
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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 Code:
    <?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
    PHP Code:
    $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

    PHP Code:
    <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


  •  

    Posting Permissions

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