469,288 Members | 2,353 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,288 developers. It's quick & easy.

PHP Sessions and Javascript submit method

I have a javascript form field validation script that I have used many times
with no problems. However, I just started using the script in a PHP
application that uses trans-sid for session management. Everything works
fine but when I execute the javascript function that includes the
"document.formname.submit();" statement nothing happens. I know for a fact
that this line gets evaluated after I successfully fill in the form.

Has anyone else run into the problem or have some javascript that works with
trans-sid?

Thanks in advance...
/dkm
Jul 16 '05 #1
5 14669
RavenMaster wrote:
Has anyone else run into the problem or have some javascript that works with
trans-sid?


Hunch: do you identify the session id in the URL (ie. non-cookie session
handling)? In that case, you'd potentially run into trouble with GET
forms. In that case, you'd have to include the session id in your form,
I suppose, like this (given the session is named PHPSESSID):
<input name="PHPSESSID" type="hidden" value="<?php echo session_name() ?>">

which would force your script into including the session identifier in
the request. Or you could use POST forms, which should work too.

OT:
Just discovered the validation functions in PEAR's HTML_QuickForm libraries:
http://pear.php.net/manual/en/packag...validation.php

This is just *too* cool!

--
Marius

Jul 16 '05 #2
it should run with method=post and appending an '?' and the SID constant
Example:
<?php print "<form action=\"validate.php?" . SID . "\" method =\"post\">"

"RavenMaster" <dm****@ravens-nest.com> schrieb im Newsbeitrag
news:Hf********************@comcast.com...
I have a javascript form field validation script that I have used many times with no problems. However, I just started using the script in a PHP
application that uses trans-sid for session management. Everything works
fine but when I execute the javascript function that includes the
"document.formname.submit();" statement nothing happens. I know for a fact that this line gets evaluated after I successfully fill in the form.

Has anyone else run into the problem or have some javascript that works with trans-sid?

Thanks in advance...
/dkm

Jul 16 '05 #3
RavenMaster wrote:

[snip]
when I execute the javascript function that includes the
"document.formname.submit();" statement nothing happens. I know for a
fact that this line gets evaluated after I successfully fill in the form.

Has anyone else run into the problem or have some javascript that works
with trans-sid?


This method of validating form input is poor, since the form becomes
completely unusable in the absence of Javascript. Instead of something
like:

<form action="..." method="...">
<button onclick="validate();">

....use something like:

<form action="..." method="..." onsubmit="return validate();">
<input type="submit">

Return true or false from your validate() function to determine whether or
not the form is submitted. This also has the side-effect of giving PHP a
proper action attribute to work its magic on (which is a mandatory
attribute in HTML 4.01 / XHTML 1.0 anyway).

--
Jim Dabell

Jul 16 '05 #4

I tried your suggestions:

Here is an extract of the php code:

echo "<form method=post name='jobForm' action=\"".$SCRIPT_NAME."\">";

include("jobs/job_form.inc");
echo "<input name=\"PHPSESSID\" type=\"hidden\" value=\"";
echo session_name();
echo "\">";
echo "
<input type='hidden' name='action' value='$action'>
<input type='hidden' name='step' value='2'>
<input type='button' name='submit' value='Next Step'
onclick=\"check_jobform();\">

</form>
</div>
";

Here is the javascript that appears inthe <head>

<script language="JavaScript">
<!--
function check_jobform() {

document.jobForm.submit();

}
//-->

</script>


"Marius Mathiesen" <ma*********************@hotmail.com> wrote in message
news:10***************@makrell.interpost.no...
RavenMaster wrote:
Has anyone else run into the problem or have some javascript that works with trans-sid?
Hunch: do you identify the session id in the URL (ie. non-cookie session
handling)? In that case, you'd potentially run into trouble with GET
forms. In that case, you'd have to include the session id in your form,
I suppose, like this (given the session is named PHPSESSID):
<input name="PHPSESSID" type="hidden" value="<?php echo session_name()

?>">
which would force your script into including the session identifier in
the request. Or you could use POST forms, which should work too.

OT:
Just discovered the validation functions in PEAR's HTML_QuickForm libraries: http://pear.php.net/manual/en/packag...validation.php
This is just *too* cool!

--
Marius

Jul 16 '05 #5
"RavenMaster" <dm****@ravens-nest.com> wrote in message
news:Bu********************@comcast.com...

I tried your suggestions:

Here is an extract of the php code:

echo "<form method=post name='jobForm' action=\"".$SCRIPT_NAME."\">";

include("jobs/job_form.inc");
echo "<input name=\"PHPSESSID\" type=\"hidden\" value=\"";
echo session_name();
echo "\">";
echo "
<input type='hidden' name='action' value='$action'>
<input type='hidden' name='step' value='2'>
<input type='button' name='submit' value='Next Step'
onclick=\"check_jobform();\">

</form>
</div>
";

Here is the javascript that appears inthe <head>

<script language="JavaScript">
<!--
function check_jobform() {

document.jobForm.submit();

}
//-->

</script>

Just a quick note (that has absolutely nothing to do with PHP), when you're
creating an HTML form and you want to call the formreference.submit()
method, you can't name any of your form elements "submit." This is why when
you called the submit() method before, nothing happened--your submit button
itself is named "submit." Think of how the browser constructs the parse
tree of your form:

jobForm
|- PHPSESSID
|- action
|- step
|- submit

Now, you can reference your submit button's value like this:

submitValue = document.jobForm.submit.value;

But wait a minute! Now, when you call document.jobForm.submit(), nothing
happens. Why? Because you replaced a part of the form's object tree with
your own form element. Try not to use (JavaScript) reserved words in any
form naming conventions. I would even recommend not using "action" as a
name even though everyone seems to do it.

HTH,
Zac
Jul 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mountain Man | last post: by
7 posts views Thread by John | last post: by
3 posts views Thread by LMachado1 | last post: by
9 posts views Thread by Bartosz Wegrzyn | last post: by
4 posts views Thread by Ian Davies | last post: by
7 posts views Thread by Nico | last post: by
2 posts views Thread by Mike | last post: by
Atli
2 posts views Thread by Atli | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.