By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,747 Members | 2,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,747 IT Pros & Developers. It's quick & easy.

data input

P: 4
Hi. I am new to PHP though i have a small background in C++ (took a intro course in college). I am wondering if this is legal to do:

Expand|Select|Wrap|Line Numbers
  1. <form action="<?
  2. $name = $HTTP_POST_VARS['name'];
  3. $fromemail = $HTTP_POST_VARS['fromemail'];
  4. $subject = $HTTP_POST_VARS['subject'];
  5. $message = $HTTP_POST_VARS['message'];
  6. $date = date('M.j.y');
  7. $header = "From: $name <$fromemail>" . "Date: $date";
  8.  
  9.  
  10. if ($name == "")
  11. {
  12.     echo "<p>Please provide your name</p>";
  13. }
  14. if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $fromemail))
  15. {
  16.     $fromemail = "not provided";
  17. }
  18. if ($subject == "")
  19. {
  20.     $subject = "message from user";
  21. }
  22. if (mail("admin@blabla.com",$subject,$message,$header))
  23. {
  24.     echo "<p>Thank you for sending the email.</p>";
  25. } else {
  26.     echo "<p>Can not send the email. Please try again later.</p>";
  27. }
  28. ?>" method="post">
  29.     <p>Name:<input name="name" type="text" size="20" /></p>
  30.     <p>Subject: <input name="subject" type="text" size="30" /></p>
  31.     <p>Message: <textarea name="message" cols="35" rows="5" /></textarea></p>
  32.     <p align="left"><input type="submit" value="send" /></p>
  33.     </form>
  34.  
Also, for the
Expand|Select|Wrap|Line Numbers
  1. if (mail("admin@blabla.com",$subject,$message,$header))
  2. {
  3.     echo "<p>Thank you for sending the email.</p>";
  4. } else {
  5.     echo "<p>Can not send the email. Please try again later.</p>";
  6. }
Is there a way I can put this message in place of the forms instead of going to another page? Or would i have to use the main template and make it so the code is on a whole seperate page?

Thank you
Feb 26 '07 #1
Share this Question
Share on Google+
1 Reply


Motoma
Expert 2.5K+
P: 3,235
Yes, if you put your form inside an echo statement, then put that inside a condition, you can effectively replace your form with the result message.
Feb 26 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.