943,743 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 517
  • PHP RSS
Sep 3rd, 2009
0

Form submission

Expand Post »
Can some one help me to create a form & send the results to my e mail address?? and cc as well to another one ?
Field Names : Name , Telephone No (should get validated to c the user enters more than 10 numbers) , E Mail address (should get validated to c whether the user has entered a correct e mail format) , Radio button, and commens area please.Submit & reset buttons.We need to make sure that certain feilds such as name , comments cant keep "blank"
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pradeeprs is offline Offline
2 posts
since Sep 2009
Sep 3rd, 2009
0

Re: Form submission

Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 728
Bite my shiny metal ass!
pritaeas is offline Offline
4,166 posts
since Jul 2006
Sep 3rd, 2009
0

Re: Form submission

Since you didn't give your email address, nor did you specify the address to CC to I've just put a empty mail function there. If you can provide a email addresses I can help you out. For more on mail() see the PHP.net documentation.
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. if($_POST['submit']=="Submit"&&!empty($_POST['name']&&!empty($_POST['phone'])&&strlen($_POST['phone'])>10&&!empty($_POST['email'])&&#
  3. preg_match('/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/',$_POST['email'])&&!empty($_POST['comments']))
  4. {
  5. //Form is Valid
  6. echo "Thanks! Your submission was sent!";
  7. mail(); //<--Will Not work!! You need a email address, a subject, a body, and headers
  8. exit(); //Prevents user from seeing the form again
  9. }
  10. ?>
  11. <html>
  12. <head>
  13. <title>Form Submission Test</title>
  14. </head>
  15. <body>
  16. <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  17. <label for="name">Name: </label><input type="text" name="name" value="<?=$_POST['name']?>"><br/>
  18. <label for="phone">Telephone: </label><input type="text" name="phone" value="<?=$_POST['phone']?>"><br/>
  19. <label for="email">Email: </label><input type="text" name="email" value="<?=$_POST['email']?>"><br/>
  20. <label for="radio">Radio Button</label><input type="radio" name="radio" value="radio1'"><br>
  21. <label for="comments">Comments: </label><textarea name="comments"><?=$_POST['name']?></textarea><br>
  22. <input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset">
  23. </form>
  24. </body>
  25. </html>
Last edited by FlashCreations; Sep 3rd, 2009 at 5:24 am.
Reputation Points: 47
Solved Threads: 47
Posting Whiz
FlashCreations is offline Offline
393 posts
since Sep 2008
Sep 3rd, 2009
0

Re: Form submission

Sorry I am new to Forms !!! Got PHP files and JS from a friend , but cant configure them properly
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pradeeprs is offline Offline
2 posts
since Sep 2009
Sep 3rd, 2009
0

Re: Form submission

If you don't have a basic understanding then perhaps you should check out this article. Also here is some source for basic usage:
php Syntax (Toggle Plain Text)
  1. <?
  2. if (isset($_POST['subject']) && $_POST['message']!=='')
  3. {
  4. $address = "your_real_email@domain.com"; //change this to the receiving address.
  5. $subject = "Website Email: ".$_POST['subject'];
  6. if ($_POST['name']!=='')
  7. {
  8. $body = "<table border=0 cellpadding=5 cellspacing=0 width=200><tr><td>".$_POST['message']."<br>
  9. <br>
  10. Yours Sincerely<br>
  11. ".$_POST['name']."</td></tr></table>";
  12. } else {
  13. $body = "<table border=0 cellpadding=5 cellspacing=0 width=200><tr><td>".$_POST['message'].
  14. "</td></tr></table>";
  15. }
  16. $headers = 'MIME-Version: 1.0' . "\r\n";
  17. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  18. $headers .= 'From: do_not_reply@your_website_form' . "\r\n";
  19.  
  20. mail($address,$subject,$body,$headers);
  21. }
  22. //below displays the form while above processes it.
  23. echo "<form method='post'>Subject: <input type=text value='' maxlength=100 name='subject' size=30><br>
  24. <textarea cols=30 rows=20 name='message'></textarea><br>Name: <input type='text' value='' name='name'>
  25. <input type='submit' value='submit'></form>";
  26. ?>
If you don't have a clue what any of that code means then you have some studying to do. That code only uses basic concepts which you would use in every day coding. So perhaps a few php tutorials might help.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Invalid argument supplied for foreach()
Next Thread in PHP Forum Timeline: how to seprate php with html





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC