-
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>
-
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!!
:rolleyes:
-
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.