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 to the CF scene
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy Mail Form Variables

    Hi,

    I am having great difficulty trying to get my php script to include the form data in a message. It sends the message but it is blank.

    When i click submit, javascript will validate the form is entered (works) and then use a php script to email it (doen't work).

    php code (separate .php file):
    Code:
    <?php 
    $fname = $_POST["First Name"];
    $email = $_POST["Email"];
    $to = "xxxx@xxxx";
    $subject = "Newsletter Subscription";
    $message = "$fname $email";
    $from = "xxxx@xxxx";
    $headers = "From:" . $from;
    mail ($to,$subject,$message,$headers); 
    ?>
    HTML Code:
    Code:
     <form action="sendnewsletterform.php" method="post" name="newsletter" enctype="text/plain" onsubmit="return validateFormNewsletter()">
            Your First Name: <input name="First Name" type="text" id="name" size="50" maxlength="60" /><font color="#FF0000">*</font><br />
            Your Email Address: <input name="Email" type="text" id="email" size="50" maxlength="60" /><font color="#FF0000">*</font><br />
            <input name="Newsletter Submit" type="submit" /><input name="Newsletter Reset" type="reset" /></form>
    Javascript Code (separate .js file):
    Code:
    function validateFormNewsletter()
    {
    	var x=document.forms["newsletter"]["First Name"].value;
    	if (x==null || x=="")
    	{
    		alert("First name must be entered");
    		return false;
    	}
    	var x=document.forms["newsletter"]["Email"].value;
    	var atpos=x.indexOf("@");
    	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
    	{
    		alert("Not a valid e-mail address");
    		return false;
    	}
    }
    If anyone can correct my code so that it works please do.

    any help is greatly appreciated
    Last edited by pilotdude647; 10-17-2012 at 01:30 PM. Reason: spelling

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,721
    Thanks
    25
    Thanked 662 Times in 661 Posts
    In the form tag this: enctype="text/plain" is killing you remove it.
    Next name="First Name".
    A space (see final scene in Body Snatchers 1978 Donald Sutherland). I have found out in my 50 years of working with computers that spaces are not your friends and not only leave when your in trouble but will stab you in the back and cause the trouble. This is a case for that. Use name="name" or name="First_Name" Change the php and javascript accordingly.

  • Users who have thanked sunfighter for this post:

    pilotdude647 (10-17-2012)

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sunfighter View Post
    In the form tag this: enctype="text/plain" is killing you remove it.
    Next name="First Name".
    A space (see final scene in Body Snatchers 1978 Donald Sutherland). I have found out in my 50 years of working with computers that spaces are not your friends and not only leave when your in trouble but will stab you in the back and cause the trouble. This is a case for that. Use name="name" or name="First_Name" Change the php and javascript accordingly.
    Thank you so much @sunfighter. It works perfectly now


  •  

    Tags for this Thread

    Posting Permissions

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