Please help - no variables passed from jscript to PHP script

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-27-2006
Sean.Dewis@gmail.com
 
Posts: n/a
Default Please help - no variables passed from jscript to PHP script

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>");

?>

Reply With Quote
  #2 (permalink)  
Old 01-28-2006
Janwillem Borleffs
 
Posts: n/a
Default Re: Please help - no variables passed from jscript to PHP script

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


Reply With Quote
  #3 (permalink)  
Old 01-28-2006
Dany Heusbourg
 
Posts: n/a
Default Re: Please help - no variables passed from jscript to PHP script

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


Reply With Quote
  #4 (permalink)  
Old 01-28-2006
Kimmo Laine
 
Posts: n/a
Default Re: Please help - no variables passed from jscript to PHP script

"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>


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:07 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0