473,385 Members | 1,311 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 14816
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
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...
7
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...
3
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...
9
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';...
4
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...
10
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...
7
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"...
2
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...
3
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.