473,574 Members | 2,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.formn ame.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 14823
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=\"valida te.php?" . SID . "\" method =\"post\">"

"RavenMaste r" <dm****@raven s-nest.com> schrieb im Newsbeitrag
news:Hf******** ************@co mcast.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.formn ame.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.formn ame.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="valida te();">

....use something like:

<form action="..." method="..." onsubmit="retur n 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=\"".$SCR IPT_NAME."\">";

include("jobs/job_form.inc");
echo "<input name=\"PHPSESSI D\" 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="JavaS cript">
<!--
function check_jobform() {

document.jobFor m.submit();

}
//-->

</script>


"Marius Mathiesen" <ma************ *********@hotma il.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
"RavenMaste r" <dm****@raven s-nest.com> wrote in message
news:Bu******** ************@co mcast.com...

I tried your suggestions:

Here is an extract of the php code:

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

include("jobs/job_form.inc");
echo "<input name=\"PHPSESSI D\" 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="JavaS cript">
<!--
function check_jobform() {

document.jobFor m.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.s ubmit()
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.jobFor m.submit.value;

But wait a minute! Now, when you call document.jobFor m.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1784
by: Mountain Man | last post by:
Hi, I posted on this matter earlier with the subject line "Trouble with sessions," but someone else started a different thread with the same subject line that arrived before my post, so I'm changing my subject line in order to avoid confusion. I was asked to provide a code example for analysis, so here it is, along with a a description...
7
7506
by: John | last post by:
Hello. I want to get this blasted .htaccess file sorted out, so I can have sessions without register_globals being on. I have looked everywhere for info on this and I mean everywhere including the php.net manual. In the manual it said to include something like the following:
3
1550
by: LMachado1 | last post by:
I just started with php and I'm trying to make a simple interface as follows: - user is asked to input an integers, for example: how many students do you want to enter? - user is then shown a page with number of text boxes = number he gave at the previous page - user fills out the test boxes with names of students and clicks submit - the...
9
2632
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php'; global $LOGINDIR;
4
4070
by: Ian Davies | last post by:
Hello I am struggling for a solution to clear some fields on my webpage that takes their values from some sessions My solution below works when the button is clicked twice. I sort of know why I have to click it twice to do the job (the first submit resets the sessions but this it too late to change the field values, which requires another...
10
6064
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
7
296
by: Nico | last post by:
Dear all, I made the following form. <FORM METHOD="POST" ACTION="prova.php"> <b>Combination</b><br><br> Element 1: <INPUT NAME="el1" TYPE="TEXT"> <BR> Element 2: <INPUT NAME="el2" TYPE="TEXT"> <br>
2
1355
by: Mike | last post by:
I have a site where users register and log in. All the data is stored in a MySQL database. When a user logs in, the username and password is checked in the database and if all ok I set a few sessions. Then at the top of each page I simply check that the sessions have been set and carry on. All this works fine except for users on AOL. ...
3
28215
Atli
by: Atli | last post by:
Introduction: Sessions are one of the simplest and more powerful tools in a web developers arsenal. This tool is invaluable in dynamic web page development and it is one of those things every developer needs to know how to use. This article explains the basics of PHP Sessions. Assumptions: Basic PHP knowledge is required (variables, arrays...
0
7753
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8265
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8132
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5332
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2265
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1365
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.