This is a discussion on Please help - no variables passed from jscript to PHP script within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi I've got a simple web form, with j script validation. All i want it to do, once the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi
I've got a simple web form, with j script validation. All i want it to do, once the form fields pass validation, is POST the data to my PHP script for processing. In a very simple html form without any j script validation, it works fine. Now I've messed with it, the PHP script doesn't get any data in it's $_REQUEST variables. Can someone please help me? -----test.shtml----- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <script type="text/javascript" language="JavaScript"> <!-- Begin function Reset() { var ip = '<!--#echo var="REMOTE_ADDR"-->'; document.forms[0].elements[0].value = ""; document.forms[0].elements[1].value = "y...@emailaddress.com"; document.forms[0].elements[2].value = "07XXX123456"; document.forms[0].elements[3].value = "Please call me ASAP. Many thanks."; document.forms[0].elements[6].value = ip; document.forms[0].elements[0].focus(); } function submitForms() { if ( (isName() ) && (isEmail()) && (isPhone()) && (isComment()) && (isFavorite()) ) if (confirm("\nYou're about to send your contact this message.\n\nClick on YES to send.\n\nClick on NO to abort.")) { alert("\nYour message will now be sent.\n\n\nThank you!"); return true; } else { alert("\nYou have chosen not to send the message."); return false; } else return false; } function isName() { var str = document.forms[0].elements[0].value; if (str == "") { alert("\nThe NAME field is blank.\n\nPlease enter your name.") document.forms[0].elements[0].focus(); return false; } for (var i = 0; i < str.length; i++) { var ch = str.substring(i, i + 1); if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ') { alert("\nThe NAME field only accepts letters & spaces.\n\nPlease re-enter your name."); document.forms[0].elements[0].select(); document.forms[0].elements[0].focus(); return false; } } return true; } function isEmail() { emailAddress=document.forms[0].elements[1].value; if (document.forms[0].elements[1].value == "") { alert("\nThe E-MAIL field is blank.\n\nPlease enter your e-mail address.") document.forms[0].elements[1].focus(); return false; } if (document.forms[0].elements[1].value.indexOf ('@',0) == -1 || document.forms[0].elements[1].value.indexOf ('.',0) == -1) { alert("\nThe E-MAIL field requires a \"@\" and a \".\"be used.\n\nPlease re-enter your e-mail address.") document.forms[0].elements[1].select(); document.forms[0].elements[1].focus(); return false; } else { toName(); return true; } } function isPhone() { var str = document.forms[0].elements[2].value; if (str == "") { alert("\nThe telephone number field is blank.\n\nPlease enter your number.") document.forms[0].elements[2].focus(); return false; } for (var i = 0; i < str.length; i++) { var ch = str.substring(i, i + 1); if ((ch < "0" || "9" < ch) && (ch < "+" || "+" < ch)) { alert("\nThe telephone field only accepts numbers and the '+' sign.\n\nPlease re-enter your number."); document.forms[0].elements[2].select(); document.forms[0].elements[2].focus(); return false; } } return true; } function isComment() { if (document.forms[0].elements[4].value == "") { if (confirm("\nYou're about to submit without leaving a comment.\n\nClick on CANCEL to include a comment.\n\nClick on OK to continue without a comment.")) return true else { document.forms[0].elements[4].focus(); return false; } } else return true } function isFavorite() { return true } // End --> </script> <title></title> </head> <body onload="Reset()" vlink="#ffff99" alink="#0000ff" link="#ffcc00" bgcolor="#e1e1e1"> <br> <br> <center><font color="#800000"> <h1><font color="#800000">Send a message</font></h1> </font> </center> <center> <form enctype="text/plain" name="details" method="POST" action="testsend.php" onsubmit="document.details.submit()"> <table border="0" width="400"> <tr> <td align="middle"><font color="#800000"><strong> Enter your name:</strong></font></td> <td align="middle"><font color="#800000"><strong> Your e-mail address:<br><font size="1">(this will be used to provide you with a copy of the message)</font> </strong></font></td> </tr> <tr> <td align="middle"><input name="custName" size="30" maxlength="30"></td> <td align="middle"><input name="email" size="30" maxlength="40" value="y...@emailaddress.com"></td> </tr> <tr> <td align="middle"><font color="#800000"><strong>Your phone number:</strong></font></td> <td align="middle"><font color="#800000"><strong> <input maxlength="15" size="15" value="07XXX123456" name="custTel"></strong></font></td> </tr> <tr> <td align="middle"> </td> <td align="middle"> </td> </tr> </table> <center> <font color="#800000"><strong>Your comments or additional details for your contact:</strong></font> <br><textarea name="callback" wrap="yes" cols="50">Please call me ASAP. Many thanks. </textarea> </center> <center> </center> <center> <input type="submit" value="Send" style="WIDTH: 90px; HEIGHT: 39px" size="28" name="submit"> <input style="WIDTH: 73px; HEIGHT: 41px" onclick="Reset()" type="reset" size="27" value="Clear Form" name="reset"> <br> <br> <font size="-1"><font size="1">Your IP address (logged for security purposes)</font> <br> </font> </center> <center> <input maxlength="15" size="12" name="remIP" readonly="" style="WIDTH: 104px; HEIGHT: 22px"> </center> </form> <br> <br> <br> <br> </center> </body> </html> --------------testsend.php------------- <?php $reqID = '2'; // $_REQUEST['cID'] ; This is meant to be set at 2 for testing $callback = $_REQUEST['callback'] ; $custName = $_REQUEST['custName'] ; $custTel = $_REQUEST['custTel'] ; $serverIP = $_SERVER['REMOTE_ADDR'] ; printf("cID from FORM POST = $reqID<br><br><br>"); printf("Your IP address: $serverIP<BR>") ; printf("callback(comments)=$callback<BR>"); printf("custName=$custName<BR>"); printf("custTel=$custTel<BR>"); ?> |
|
|||
|
Sean.Dewis@gmail.com wrote:
> In a very simple html form without any j script validation, it works > fine. > > Now I've messed with it, the PHP script doesn't get any data in it's > $_REQUEST variables. > > Can someone please help me? > The JavaScript contains some errors > function isEmail() > { [...] > else > { > toName(); > return true; > There is no toName() function defined, you probably want to use isName() > <form enctype="text/plain" name="details" method="POST" > action="testsend.php" onsubmit="document.details.submit()"> > The value for the onsubmit attribute should be "return submitForms()" and the enctype attribute should be omitted: <form name="details" method="POST" action="testsend.php" onsubmit="return submitForms()"> JW |
|
|||
|
Hello
You should trie the $_POST variable in your php script!! > <form enctype="text/plain" name="details" method="POST" > action="testsend.php" onsubmit="document.details.submit()"> > <table border="0" width="400"> If you want to uese $_REQUEST change the method to GET. Dan |
|
|||
|
"Dany Heusbourg" <Dany.Heusbourg@post.rwth-aachen.de> kirjoitti
viestissä:441hn7F1pnhicU1@news.dfncis.de... > Hello > > You should trie the $_POST variable in your php script!! > >> <form enctype="text/plain" name="details" method="POST" >> action="testsend.php" onsubmit="document.details.submit()"> >> <table border="0" width="400"> > > If you want to uese $_REQUEST change the method to GET. That's not really true. $_REQUEST contains all POST, GET and COOKIE variables, so if the form was POSTed, the variables are available in $_REQUEST. Use of $_POST and $_GET would be reasonable yes, but it's not necessary. One can use $_REQUEST with post method as well. -- SETI @ Home - Donate your cpu's idle time to science. Further reading at <http://setiweb.ssl.berkeley.edu/> Kimmo Laine <antaatulla.sikanautaa@gmail.com.NOSPAM.invalid> |