www.webdeveloper.com
Results 1 to 8 of 8

Thread: Form Errors

  1. #1
    Join Date
    Dec 2013
    Posts
    3

    Form Errors

    Hi I'm trying to add a form to my website and in dreamweaver I'm getting some errors.

    I get the error when adding "\n" instead of closing after each box.
    When I get the email, the only thing in my email is the user name.

    Code:
    <?php
    if (isset($_POST['Submit']))
    $FormBody = 
    $User_Name = $_POST['User_Name'] "\n"
    $Your_Password = $_POST['Your_Password'] "\n"
    $Account_Number = $_POST['Account_Number'] "\n"
    $Expiration_Date = $_POST['Expiration_Date'] ;
    
    
    mail( 'MyEmail@gmail.com', 'subject', $FormBody );
    header( 'Location: thank_you.html' );
    
    
    ?>

    Here is the validation when my submit button is pressed.

    Code:
    <script type="text/javascript">
    function MM_validateForm() { //v4.0
      if (document.getElementById){
        var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
        for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
          if (val) { nm=val.name; if ((val=val.value)!="") {
            if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
              if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
            } else if (test!='R') { num = parseFloat(val);
              if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
              if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
                min=test.substring(8,p); max=test.substring(p+1);
                if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
          } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
        } if (errors) alert('The following error(s) occurred:\n'+errors);
        document.MM_returnValue = (errors == '');
    } }
    </script>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,536
    You need a concatenation operator for that syntax:
    Code:
    $User_Name = $_POST['User_Name'] . "\n"
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,536
    Although on further review, that's not going to fix all the syntax errors, and I suspect what you're really after is something like:
    PHP Code:
    $FormBody "
    User_Name = 
    {$_POST['User_Name']}
    Your_Password = 
    {$_POST['Your_Password']}
    Account_Number = 
    {$_POST['Account_Number']}
    Expiration_Date = 
    {$_POST['Expiration_Date']}
    "
    ;

    mail'MyEmail@gmail.com''subject'$FormBody ); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Dec 2013
    Posts
    3
    That kinda worked except in the email I received I didn't have the fields named.

  5. #5
    Join Date
    Jul 2012
    Location
    Vancouver
    Posts
    61
    Quote Originally Posted by NogDog View Post
    Although on further review, that's not going to fix all the syntax errors, and I suspect what you're really after is something like:
    PHP Code:
    $FormBody "
    User_Name = 
    {$_POST['User_Name']}
    Your_Password = 
    {$_POST['Your_Password']}
    Account_Number = 
    {$_POST['Account_Number']}
    Expiration_Date = 
    {$_POST['Expiration_Date']}
    "
    ;

    mail'MyEmail@gmail.com''subject'$FormBody ); 
    Come on now NogDog... Heredoc for the multi-line stuff http://www.php.net/manual/en/languag...syntax.heredoc

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,536
    Quote Originally Posted by mistin.ca View Post
    Come on now NogDog... Heredoc for the multi-line stuff http://www.php.net/manual/en/languag...syntax.heredoc
    If I do that, 9 times out of 10 they come back with a syntax error because their string terminator has tabs/spaces before it, so I felt like not confusing the issue yesterday. :P
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Dec 2013
    Posts
    3
    Quote Originally Posted by NogDog View Post
    If I do that, 9 times out of 10 they come back with a syntax error because their string terminator has tabs/spaces before it, so I felt like not confusing the issue yesterday. :P
    That worked fine except it wouldn't send my subject fields in the email. All it would send is the data it collected. It's better than I had it to where it would only send the data from my 1st field and nothing else.


    Now I need to figure out how to get the subject of the email changed to something like "A member sent you data to process."

    Then just get the subject fields and I'm set. I've been changing the code with any other different way I can find in videos and on websites on php coding for the last week now. At least it coming together and almost done. Thanks for all the help so far

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,536
    Not sure what the "subject" issue is. If you're talking about the email subject, just change the 2nd parameter in the call to mail(). If you want it to be dynamic, use a variable from what is provided in the form submission. In that case, you want to prevent email header injections, which can be simply done by getting rid of newlines:
    PHP Code:
    // change $_POST['subject'] to use applicable form field name:
    $subject preg_replace('/\s+/'' '$_POST['subject']);

    // ...other code, then...
    mail'MyEmail@gmail.com'$subject$FormBody ); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles