PHP Error

  • VeX92
  • Novice
  • Novice
  • User avatar
  • Posts: 34

Post 3+ Months Ago

Hello Im new to PHP and I am trying to make a simple comment form, and a simple processing page.
Here is the code for the comment form:
Code: [ Select ]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script language="Javascript">
function doClear(Text) {
   if(Text.value == Text.defaultValue) {
     Text.value = ""
   }
}

</script>
<?php
$name = Fname;
$D = Domain;
$C = Comments;
$recpt = "Email";
$subject = "Test mail";
$body = "Name: " . $name . "Domain name: " . $D . "Comments: " . $C;
$from = "redsocks";
$headers = "From: $from";
?>
<form action="verify_comments.php" enctype="text/plain" method="post" name="contact-us">
<h3>Leave a comment for us!</h3>
Name: <br />
<input name="Fname" type="text"> <br />
Email: <br />
<input name="Email" type="text"> <br />
Domain name: <br />
<input name="Domain" type="text"> <br />
Comments: <br />
<textarea name="Comments" cols="21" rows="6" wrap="hard" onFocus="doClear(this)">Please insert your comments here...</textarea> <br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</h3>
</body>
</html>
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. </head>
  6. <body>
  7. <script language="Javascript">
  8. function doClear(Text) {
  9.    if(Text.value == Text.defaultValue) {
  10.      Text.value = ""
  11.    }
  12. }
  13. </script>
  14. <?php
  15. $name = Fname;
  16. $D = Domain;
  17. $C = Comments;
  18. $recpt = "Email";
  19. $subject = "Test mail";
  20. $body = "Name: " . $name . "Domain name: " . $D . "Comments: " . $C;
  21. $from = "redsocks";
  22. $headers = "From: $from";
  23. ?>
  24. <form action="verify_comments.php" enctype="text/plain" method="post" name="contact-us">
  25. <h3>Leave a comment for us!</h3>
  26. Name: <br />
  27. <input name="Fname" type="text"> <br />
  28. Email: <br />
  29. <input name="Email" type="text"> <br />
  30. Domain name: <br />
  31. <input name="Domain" type="text"> <br />
  32. Comments: <br />
  33. <textarea name="Comments" cols="21" rows="6" wrap="hard" onFocus="doClear(this)">Please insert your comments here...</textarea> <br />
  34. <input type="submit" name="submit" value="Submit" />
  35. </form>
  36. </body>
  37. </h3>
  38. </body>
  39. </html>


And here is the code for the processing page:
Code: [ Select ]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
function check_email_address($email) {
    if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
        return false; }
        
    $email_array = explode("@", $email);
    $local_array = explode(".", $email_array[0]);
    
    for ($i = 0; $i < sizeof($local_array); $i++) {
        if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } }
        if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
            $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) {
                return false; }
            
            for ($i = 0; $i < sizeof($domain_array); $i++) {
            if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } }
return true;
}

if (isset($_POST['FName']) /*&& isset($_REQUEST['Email']) && isset($_REQUEST['Domain']) && isset($_REQUEST['Comments']) && check_email_address($_REQUEST['Email'])*/)
{
    $Host_Email = "Email";
    $Subject = "New Comment!";
    $Name = $_POST['Name'];
    $Email = $_POST['Email'];
    $Domain = $_POST['Domain'];
    $Comments = $_POST['Comments'];
    $Body = $Name . " at email address: " . $Email . " with domain name: " . $Domain . " wrote: " . $Comments;
    mail($Host_Email, $Subject, $Body, "From: $Email");
}

else
{
    echo "Error in Application";
}
?>
</body>
</html>
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. </head>
  6. <body>
  7. <?php
  8. function check_email_address($email) {
  9.     if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
  10.         return false; }
  11.         
  12.     $email_array = explode("@", $email);
  13.     $local_array = explode(".", $email_array[0]);
  14.     
  15.     for ($i = 0; $i < sizeof($local_array); $i++) {
  16.         if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } }
  17.         if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
  18.             $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) {
  19.                 return false; }
  20.             
  21.             for ($i = 0; $i < sizeof($domain_array); $i++) {
  22.             if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } }
  23. return true;
  24. }
  25. if (isset($_POST['FName']) /*&& isset($_REQUEST['Email']) && isset($_REQUEST['Domain']) && isset($_REQUEST['Comments']) && check_email_address($_REQUEST['Email'])*/)
  26. {
  27.     $Host_Email = "Email";
  28.     $Subject = "New Comment!";
  29.     $Name = $_POST['Name'];
  30.     $Email = $_POST['Email'];
  31.     $Domain = $_POST['Domain'];
  32.     $Comments = $_POST['Comments'];
  33.     $Body = $Name . " at email address: " . $Email . " with domain name: " . $Domain . " wrote: " . $Comments;
  34.     mail($Host_Email, $Subject, $Body, "From: $Email");
  35. }
  36. else
  37. {
  38.     echo "Error in Application";
  39. }
  40. ?>
  41. </body>
  42. </html>


My problem is that even when i enter something into all fields I still get a Error in Application on the processing page. Any help?
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

In your processing page place the following at the top:

Code: [ Select ]
print_f($_POST);
  • VeX92
  • Novice
  • Novice
  • User avatar
  • Posts: 34

Post 3+ Months Ago

Hey SpooF thanks for your reply. print_f($_POST); returned Array strange enough. Any suggestions as to what this means?
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Yes. $_POST is an array. When you try to print it, you get the structure type as a result. Instead, use var_dump($_POST) to see its contents and post them back to us if you would like.
  • VeX92
  • Novice
  • Novice
  • User avatar
  • Posts: 34

Post 3+ Months Ago

Ok this is what i get now: array(0) { }
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

There's nothing getting passed by the form. The $_POST array should contain all key->val pairs that you submitted. Try removing this bit or changing the value.
Quote:
enctype="text/plain"


If you insist on keeping that attribute, then there are two standards-supported choices. For default text form, use "application/x-www-form-urlencoded". For uploads, use "multipart/form-data". IMO, what you want is the urlencoded one (which is default anyways), so I would just delete that attribute altogether from line 25 of the comment form code.
  • VeX92
  • Novice
  • Novice
  • User avatar
  • Posts: 34

Post 3+ Months Ago

Ok i removed the php script in the comment form and here is the error i get from var_dump: array(5) { ["Fname"]=> string(3) "John" ["Email"]=> string(3) "aaa" ["Domain"]=> string(1) "hey" ["Comments"]=> string(1) "hey" ["submit"]=> string(6) "Submit" }

Instead of trying to fix this, would anyone be kind enough to show me an example script that works. What I need is a very simple contact form with name and comments that has empty field validation (if someone omits a field or two it will not let them submit to the verification page). Then the validation page gets the data from the form page and emails it. Thanks a lot for all of your help so far.

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 86 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.