PHP Sessions and Javascript submit method

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RavenMaster

    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


  • Marius Mathiesen

    #2
    Re: PHP Sessions and Javascript submit method

    RavenMaster wrote:[color=blue]
    > Has anyone else run into the problem or have some javascript that works with
    > trans-sid?[/color]

    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:


    This is just *too* cool!

    --
    Marius

    Comment

    • frimi

      #3
      Re: PHP Sessions and Javascript submit method

      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" <dmoore@raven s-nest.com> schrieb im Newsbeitrag
      news:HfacnUvJgZ TmJ7qiXTWJgA@co mcast.com...[color=blue]
      > I have a javascript form field validation script that I have used many[/color]
      times[color=blue]
      > 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[/color]
      fact[color=blue]
      > 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[/color]
      with[color=blue]
      > trans-sid?
      >
      > Thanks in advance...
      > /dkm
      >
      >[/color]


      Comment

      • Jim Dabell

        #4
        Re: PHP Sessions and Javascript submit method

        RavenMaster wrote:

        [snip][color=blue]
        > 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?[/color]

        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

        Comment

        • RavenMaster

          #5
          Re: PHP Sessions and Javascript submit method


          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" <marius_doesnt_ read_this@hotma il.com> wrote in message
          news:1059569821 .748042@makrell .interpost.no.. .[color=blue]
          > RavenMaster wrote:[color=green]
          > > Has anyone else run into the problem or have some javascript that works[/color][/color]
          with[color=blue][color=green]
          > > trans-sid?[/color]
          >
          > 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()[/color]
          ?>">[color=blue]
          >
          > 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[/color]
          libraries:[color=blue]
          >[/color]
          http://pear.php.net/manual/en/packag...validation.php[color=blue]
          >
          > This is just *too* cool!
          >
          > --
          > Marius
          >[/color]


          Comment

          • Zac Hester

            #6
            Re: PHP Sessions and Javascript submit method

            "RavenMaste r" <dmoore@raven s-nest.com> wrote in message
            news:BuOdnWFFbp VUVrqiXTWJhg@co mcast.com...[color=blue]
            >
            > 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>
            >[/color]


            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


            Comment

            Working...