Results 1 to 3 of 3

Thread: PHP getting form data

  1. #1
    Join Date
    Apr 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question PHP getting form data

    I am having trouble getting PHP to pick up the data from the form. The email is sent, but it says Name= and Age= giving no values.

    Thx

    http://www.businessmeninchrist.com/T...Javascript.php

    Code:
    <html><HEAD><TITLE>Waynes PHP Mail Testing with Javascript checking</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=windows-1252">
    <LINK href="stylesheet.css" rel=stylesheet>
    <script>
    function checkBMICform() {
    nameOK = true;
    ageOK = true;
    saveNameValue = document.BMICForm.name.value;
    saveAgeValue  = document.BMICForm.age.value;
    
    if (saveNameValue == "") {
    /*	alert("You must give us your name")  */
    	nameOK = false;
    	}
    
    if (saveAgeValue == "") {
    /*	alert("You must give us your age")  */
    	ageOK = false;
    	}
    
    if (nameOK && ageOK) {
    
    	
    <?php
    import_request_variables("gP", "name_");
    import_request_variables("gP", "age_");
    
    $to      = 'eugenebarleycorn@netscape.net';
    $subject = 'PHP Form Test';
    
    $message = "Name = " . $_POST['name'] . "\nAge = " . $_POST['age'];
    
    $message = wordwrap($message, 70);
    $headers = 'From: wmckinstry@businessmeninchrist.com' . "\r\n" .
       'Reply-To: wmckinstry@businessmeninchrist.com' . "\r\n" .
       'X-Mailer: PHP/' . phpversion();
    
    mail($to, $subject, $message, $headers);
    ?>
    
    	alert("Your information has been sent.");
    	document.BMICForm.name.value="";
    	document.BMICForm.age.value="";
    	
    	}
    	else {
    		alert("You must enter all values")				
    	      }
    
    }
    
    
    </script>
    </HEAD>
    <body>
    <h1> This is test of PHP forms </h1>
    
    
    
    <form name="BMICForm" method="post" onsubmit="return checkBMICform()">
    <p>Your name: <input type="text" name="name" id="name"/></p>
    <p>Your age: <input type="text" name="age" id="age"/></p>
    <p><input type="button" onclick="checkBMICform()" value="Send"/></p>
    <p><input type="reset" /></p>
    </form>
    
    
    
    </body>
    </html>

  2. #2
    Join Date
    Apr 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Never mind

    Never mind, I got it to work using an approach with all PHP. I don't think PHP and Javascript were meant to work together, since one is server-side and the other is client-side!!


  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Indeed.

    They can send data back and forth, but only between refreshes.

    The javascript would do stuff, then when the page is loaded (or reloaded), the javascript's values are sent to php. Then the php does it's stuff, and outputs more values, which could include values to javascript.

    They can't work together in realtime.



    Now, if you do need them to work together, look into AJAX. It's basically a way to shortcut around this and have php work in realtime by using javascript to refresh the php script behind the scenes. Pretty complex, though.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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