New Window

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

    New Window

    I have a form that updates and stays in the same window. That is the
    desired behavior.

    On this form I also have two buttons. I want those buttons to open up a new
    window with information taken from another field. I tried putting those
    two buttons in a form that has target="_blank" , but it still came up in the
    same window. (That form is inside the outer form).

    I can make this happen if I put the forms one after another. The problem is
    that I want the update button on the first form to be the last thing on the
    page. Of course I can always put the form that brings up a new window
    first, but that is not aesthetically pleasing. Basically, I would like:

    <form same window>
    stuff
    <something like a form to bring up a new window with properties from
    fields in this form>
    update button outer form
    </form>

    What works is:
    <form to bring up a new window with properties from fields in this form>
    </form>
    <form same window>
    stuff
    update button
    </form>

    I don't want to use Javascript. I want this all with only php and html.

    One more thing: After bringing up the new window, I would like the data on
    the original form to be cleared. Does that have to be done in Javascript?
    Is there a way to get that field to repaint as clear through php? I doubt
    that it can because the header is devoted to the new window, so I think I
    will have to resort to Javascript.

    Shelly


  • petersprc@gmail.com

    #2
    Re: New Window

    HTML does not support nested forms unfortunately:

    "A document can have multiple forms, but forms cannot be nested --
    you cannot have a form within a form."

    Netscape HTML Tag Reference

    <http://devedge-temp.mozilla.or g/library/manuals/1998/htmlguide/tags10.html>

    Without JavaScript, one way to do this would be to define two forms and
    position the controls from the second form inside the main form using
    css. You could have three sections stacked on top of each other. The
    middle section would be your controls from the second form. Below is an
    example of doing this.

    If you are willing to use JavaScript, that would probably be a much
    easier solution. You would have one form, and the inner button would
    set "theForm.ta rget = '_blank'" to submit the form in a new window.

    To reset the form after submitting it, use "theForm.reset( )".

    [Example 1: Using JavaScript]

    <?

    // File: form.php

    // Check if the inner button was pressed in PHP:

    if (isset($_REQUES T['actionId']) && $_REQUEST['actionId'] == 'inner') {

    // The inner button was pressed

    }

    ?>

    <!-- Here is our main form -->

    <form name=form action="<?= htmlentities($_ SERVER['PHP_SELF'],
    ENT_QUOTES) ?>">

    <input name=field1>
    <br>

    <!-- This hidden parameter lets us check later if the
    form was submitted using the default button or
    the other button -->

    <input type=hidden name=actionId>

    <!-- The onClick event handler sets the form's target to
    _blank, updates actionId, submits the form, and then
    resets the form -->

    <input type=button name=inner value="Inner Button"
    onClick="docume nt.form.target = '_blank';
    document.form.a ctionId.value = 'inner';
    document.form.s ubmit();
    document.form.r eset()">
    <br>

    <input type=submit value="OK">

    </form>

    [Example 2: Using CSS]

    <?

    if (isset($_REQUES T['actionId']) && $_REQUEST['actionId'] == 'form2') {
    // Second form was submitted
    }

    ?>

    <!-- Statically positioning a form within a form -->

    <style type="text/css">
    #section1 {position: absolute; top: 10; height: 105;}
    #section2 {position: absolute; top: 115; height: 50;}
    #section3 {position: absolute; top: 165; height: 50;}
    </style>

    <form name=form1
    action="<?= htmlentities($_ SERVER['PHP_SELF'], ENT_QUOTES) ?>">

    <div id=section1>
    <h1>The Form</h1>
    <input id=field1 name=field1 value="Field 1">
    </div>

    <div id=section3>
    <input id=field3 name=field3 value="Field 3">
    <br>
    <br>
    <input type=submit value="Button 1">
    </div>

    </form>

    <form name=form2
    action="<?= htmlentities($_ SERVER['PHP_SELF'], ENT_QUOTES) ?>"
    onSubmit="docum ent.form2.submi t(); document.form1. reset();
    document.form2. reset(); return false;"
    target=_blank>

    <div id=section2>
    <input name=field2 value="Field 2">
    <input type=submit value="Button 2">
    </div>

    <input type=hidden name=actionId value=form2>

    </form>


    Shelly wrote:
    I have a form that updates and stays in the same window. That is the
    desired behavior.
    >
    On this form I also have two buttons. I want those buttons to open up a new
    window with information taken from another field. I tried putting those
    two buttons in a form that has target="_blank" , but it still came up in the
    same window. (That form is inside the outer form).
    >
    I can make this happen if I put the forms one after another. The problem is
    that I want the update button on the first form to be the last thing on the
    page. Of course I can always put the form that brings up a new window
    first, but that is not aesthetically pleasing. Basically, I would like:
    >
    <form same window>
    stuff
    <something like a form to bring up a new window with properties from
    fields in this form>
    update button outer form
    </form>
    >
    What works is:
    <form to bring up a new window with properties from fields in this form>
    </form>
    <form same window>
    stuff
    update button
    </form>
    >
    I don't want to use Javascript. I want this all with only php and html.
    >
    One more thing: After bringing up the new window, I would like the data on
    the original form to be cleared. Does that have to be done in Javascript?
    Is there a way to get that field to repaint as clear through php? I doubt
    that it can because the header is devoted to the new window, so I think I
    will have to resort to Javascript.
    >
    Shelly

    Comment

    • petersprc@gmail.com

      #3
      Re: New Window

      This can be done using:

      - An <iframeinside the main form that displays the second form.

      - JavaScript to change the window destination when the button is
      pressed.

      - CSS to position the second form's controls inside the main form.

      My original post didn't mention the iframe solution. It got bounced.
      Here it is below:

      HTML does not support nested forms unfortunately:

      "A document can have multiple forms, but forms cannot be nested --
      you cannot have a form within a form."

      Netscape HTML Tag Reference

      <http://devedge-temp.mozilla.or g/library/manuals/1998/htmlguide/tags10.html>

      Without JavaScript, one way to do this would be to define two forms and
      position the controls from the second form inside the main form using
      css. You could have three sections stacked on top of each other. The
      middle section would be your controls from the second form. Below is an
      example of doing this.

      If you are willing to use JavaScript, that would probably be a much
      easier solution. You would have one form, and the inner button would
      set "theForm.ta rget = '_blank'" to submit the form in a new window.

      To reset the form after submitting it, use "theForm.reset( )".

      [Example 1: Using JavaScript]

      <?

      // File: form.php

      // Check if the inner button was pressed in PHP:

      if (isset($_REQUES T['actionId']) && $_REQUEST['actionId'] == 'inner') {

      // The inner button was pressed

      }

      ?>

      <!-- Here is our main form -->

      <form name=form action="<?= htmlentities($_ SERVER['PHP_SELF'],
      ENT_QUOTES) ?>">

      <input name=field1>
      <br>

      <!-- This hidden parameter lets us check later if the
      form was submitted using the default button or
      the other button -->

      <input type=hidden name=actionId>

      <!-- The onClick event handler sets the form's target to
      _blank, updates actionId, submits the form, and then
      resets the form -->

      <input type=button name=inner value="Inner Button"
      onClick="docume nt.form.target = '_blank';
      document.form.a ctionId.value = 'inner';
      document.form.s ubmit();
      document.form.r eset()">
      <br>

      <input type=submit value="OK">

      </form>

      [Example 2: Using CSS]

      <?

      if (isset($_REQUES T['actionId']) && $_REQUEST['actionId'] == 'form2') {
      // Second form was submitted
      }

      ?>

      <!-- Statically positioning a form within a form -->

      <style type="text/css">
      #section1 {position: absolute; top: 10; height: 105;}
      #section2 {position: absolute; top: 115; height: 50;}
      #section3 {position: absolute; top: 165; height: 50;}
      </style>

      <form name=form1
      action="<?= htmlentities($_ SERVER['PHP_SELF'], ENT_QUOTES) ?>">

      <div id=section1>
      <h1>The Form</h1>
      <input id=field1 name=field1 value="Field 1">
      </div>

      <div id=section3>
      <input id=field3 name=field3 value="Field 3">
      <br>
      <br>
      <input type=submit value="Button 1">
      </div>

      </form>

      <form name=form2
      action="<?= htmlentities($_ SERVER['PHP_SELF'], ENT_QUOTES) ?>"
      onSubmit="docum ent.form2.submi t(); document.form1. reset();
      document.form2. reset(); return false;"
      target=_blank>

      <div id=section2>
      <input name=field2 value="Field 2">
      <input type=submit value="Button 2">
      </div>

      <input type=hidden name=actionId value=form2>

      </form>

      Shelly wrote:
      I have a form that updates and stays in the same window. That is the
      desired behavior.
      >
      On this form I also have two buttons. I want those buttons to open up a new
      window with information taken from another field. I tried putting those
      two buttons in a form that has target="_blank" , but it still came up in the
      same window. (That form is inside the outer form).
      >
      I can make this happen if I put the forms one after another. The problem is
      that I want the update button on the first form to be the last thing on the
      page. Of course I can always put the form that brings up a new window
      first, but that is not aesthetically pleasing. Basically, I would like:
      >
      <form same window>
      stuff
      <something like a form to bring up a new window with properties from
      fields in this form>
      update button outer form
      </form>
      >
      What works is:
      <form to bring up a new window with properties from fields in this form>
      </form>
      <form same window>
      stuff
      update button
      </form>
      >
      I don't want to use Javascript. I want this all with only php and html.
      >
      One more thing: After bringing up the new window, I would like the data on
      the original form to be cleared. Does that have to be done in Javascript?
      Is there a way to get that field to repaint as clear through php? I doubt
      that it can because the header is devoted to the new window, so I think I
      will have to resort to Javascript.
      >
      Shelly

      Comment

      Working...