$_SERVER[PHP_SELF] and <SELECT>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Salve Håkedal

    $_SERVER[PHP_SELF] and <SELECT>

    When I select Februar here and sends, selection returns to Januar.
    I know why: no option is marked selected...
    But can php get this right in an easy way?
    <html><head><ti tle>Part of a bigger page</title></head>
    <?php
    $form ="
    <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
    <select name=obs_mnd>
    <option value=\"Jan\">J anuar</option>
    <option value=\"Feb\">F ebruar</option>
    <option value=\"Des\">D esember</option>
    </select>
    <input type=\"submit\" name=\"submit\" value=\"Send\">
    </form>
    ";
    echo "$form"
    ?>
    </body></html>
  • Dennis Biletsky

    #2
    Re: $_SERVER[PHP_SELF] and &lt;SELECT&g t;


    "Salve Håkedal" <ikkje.spam.sal ve@fiolinmaker. no> ???????/???????? ?
    ???????? ?????????: news:bYrcc.5258 $zf6.69970@news 4.e.nsc.no...[color=blue]
    > When I select Februar here and sends, selection returns to Januar.
    > I know why: no option is marked selected...
    > But can php get this right in an easy way?
    > <html><head><ti tle>Part of a bigger page</title></head>
    > <?php
    > $form ="
    > <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
    > <select name=obs_mnd>
    > <option value=\"Jan\">J anuar</option>
    > <option value=\"Feb\">F ebruar</option>
    > <option value=\"Des\">D esember</option>
    > </select>
    > <input type=\"submit\" name=\"submit\" value=\"Send\">
    > </form>
    > ";
    > echo "$form"
    > ?>
    > </body></html>[/color]

    Why are you suprised? When you press SUBMIT the same script is execute
    (there is no selected item in it) due to action=\"$_SERV ER[PHP_SELF]\", so
    where is pointing for previous selected item? No.


    Comment

    • Markus Ernst

      #3
      Re: $_SERVER[PHP_SELF] and &lt;SELECT&g t;

      "Salve Håkedal" <ikkje.spam.sal ve@fiolinmaker. no> schrieb im Newsbeitrag
      news:bYrcc.5258 $zf6.69970@news 4.e.nsc.no...[color=blue]
      > When I select Februar here and sends, selection returns to Januar.
      > I know why: no option is marked selected...
      > But can php get this right in an easy way?
      > <html><head><ti tle>Part of a bigger page</title></head>
      > <?php
      > $form ="
      > <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
      > <select name=obs_mnd>
      > <option value=\"Jan\">J anuar</option>
      > <option value=\"Feb\">F ebruar</option>
      > <option value=\"Des\">D esember</option>
      > </select>
      > <input type=\"submit\" name=\"submit\" value=\"Send\">
      > </form>
      > ";
      > echo "$form"
      > ?>
      > </body></html>[/color]

      As you write the form into a variable and then output it, it makes it
      complicated. I usually do:

      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="myform"
      method="post">
      <select name="obs_mnd">
      <option value="Jan" <?php if(isset($obs_m nd) && $obs_mnd=="Jan" ) echo
      "selected"; ?>>Januar</option>
      ....

      HTH
      Markus


      Comment

      • Geoff Berrow

        #4
        Re: $_SERVER[PHP_SELF] and &lt;SELECT&g t;

        I noticed that Message-ID: <407267ce$0$222 68$afc38c87@new s.easynet.ch>
        from Markus Ernst contained the following:
        [color=blue]
        ><form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="myform"
        >method="post ">
        ><select name="obs_mnd">
        ><option value="Jan" <?php if(isset($obs_m nd) && $obs_mnd=="Jan" ) echo
        >"selected"; ?>>Januar</option>[/color]


        I do a similar thing, but use a function. No easy way AFAIK (for some
        value of 'easy')
        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • Salve Håkedal

          #5
          Re: $_SERVER[PHP_SELF] and &lt;SELECT&g t;

          Markus Ernst skreiv:
          [color=blue]
          > "Salve Håkedal" <ikkje.spam.sal ve@fiolinmaker. no> schrieb im Newsbeitrag
          > news:bYrcc.5258 $zf6.69970@news 4.e.nsc.no...[color=green]
          >> When I select Februar here and sends, selection returns to Januar.
          >> I know why: no option is marked selected...
          >> But can php get this right in an easy way?
          >> <html><head><ti tle>Part of a bigger page</title></head>
          >> <?php
          >> $form ="
          >> <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
          >> <select name=obs_mnd>
          >> <option value=\"Jan\">J anuar</option>
          >> <option value=\"Feb\">F ebruar</option>
          >> <option value=\"Des\">D esember</option>
          >> </select>
          >> <input type=\"submit\" name=\"submit\" value=\"Send\">
          >> </form>
          >> ";
          >> echo "$form"
          >> ?>
          >> </body></html>[/color]
          >
          > As you write the form into a variable and then output it, it makes it
          > complicated. I usually do:
          >
          > <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="myform"
          > method="post">
          > <select name="obs_mnd">
          > <option value="Jan" <?php if(isset($obs_m nd) && $obs_mnd=="Jan" ) echo
          > "selected"; ?>>Januar</option>
          > ...
          >
          > HTH
          > Markus[/color]
          Thank you. This is neat and I can understand it.
          But my script should lead the user back to the form if it's not properly
          filled out, while it's going to present the user with only "Thank you
          ....etc" if it _is_ properly filled out. Am I right to say that the form has
          to be buildt as a variable to achieve that?

          $alve

          Comment

          • Salve Håkedal

            #6
            Re: $_SERVER[PHP_SELF] and &lt;SELECT&g t;

            Dennis Biletsky skreiv:
            [color=blue]
            >
            > "Salve Håkedal" <ikkje.spam.sal ve@fiolinmaker. no> ???????/???????? ?
            > ???????? ?????????: news:bYrcc.5258 $zf6.69970@news 4.e.nsc.no...[color=green]
            >> When I select Februar here and sends, selection returns to Januar.
            >> I know why: no option is marked selected...
            >> But can php get this right in an easy way?
            >> <html><head><ti tle>Part of a bigger page</title></head>
            >> <?php
            >> $form ="
            >> <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
            >> <select name=obs_mnd>
            >> <option value=\"Jan\">J anuar</option>
            >> <option value=\"Feb\">F ebruar</option>
            >> <option value=\"Des\">D esember</option>
            >> </select>
            >> <input type=\"submit\" name=\"submit\" value=\"Send\">
            >> </form>
            >> ";
            >> echo "$form"
            >> ?>
            >> </body></html>[/color]
            >
            > Why are you suprised? When you press SUBMIT the same script is execute
            > (there is no selected item in it) due to action=\"$_SERV ER[PHP_SELF]\", so
            > where is pointing for previous selected item? No.[/color]
            I ain't surprised !
            $alve

            Comment

            • Chung Leong

              #7
              Re: $_SERVER[PHP_SELF] and &lt;SELECT&g t;

              "Salve Håkedal" <ikkje.spam.sal ve@fiolinmaker. no> wrote in message
              news:bYrcc.5258 $zf6.69970@news 4.e.nsc.no...[color=blue]
              > When I select Februar here and sends, selection returns to Januar.
              > I know why: no option is marked selected...
              > But can php get this right in an easy way?
              > <html><head><ti tle>Part of a bigger page</title></head>
              > <?php
              > $form ="
              > <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
              > <select name=obs_mnd>
              > <option value=\"Jan\">J anuar</option>
              > <option value=\"Feb\">F ebruar</option>
              > <option value=\"Des\">D esember</option>
              > </select>
              > <input type=\"submit\" name=\"submit\" value=\"Send\">
              > </form>
              > ";
              > echo "$form"
              > ?>
              > </body></html>[/color]

              To interpolate a array element into a string you need to use curly brackets.

              $form = "<form action\"{$_SERV ER['PHP_SELF']}\"> ... ";


              Comment

              • Andy Hassall

                #8
                Re: $_SERVER[PHP_SELF] and &lt;SELECT&g t;

                On Tue, 6 Apr 2004 18:25:32 -0400, "Chung Leong" <chernyshevsky@ hotmail.com>
                wrote:
                [color=blue]
                >"Salve Håkedal" <ikkje.spam.sal ve@fiolinmaker. no> wrote in message
                >news:bYrcc.525 8$zf6.69970@new s4.e.nsc.no...[/color]
                [color=blue][color=green]
                >> <form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >[/color]
                >
                >To interpolate a array element into a string you need to use curly brackets.
                >
                >$form = "<form action\"{$_SERV ER['PHP_SELF']}\"> ... ";[/color]

                Strictly speaking you don't NEED to, but you certainly SHOULD do.

                --
                Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
                http://www.andyh.co.uk / http://www.andyhsoftwa re.co.uk/space

                Comment

                • Chung Leong

                  #9
                  Re: $_SERVER[PHP_SELF] and &lt;SELECT&g t;

                  "Salve Håkedal" <ikkje.spam.sal ve@fiolinmaker. no> wrote in message
                  news:JKBcc.5205 $px6.73518@news 2.e.nsc.no...[color=blue]
                  > Thank you. This is neat and I can understand it.
                  > But my script should lead the user back to the form if it's not properly
                  > filled out, while it's going to present the user with only "Thank you
                  > ...etc" if it _is_ properly filled out. Am I right to say that the form[/color]
                  has[color=blue]
                  > to be buildt as a variable to achieve that?[/color]

                  No. For a conditional block of HTML you can do:

                  <? if($is_properly _filled_out) { ?>
                  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="myform"
                  method="post">
                  <select name="obs_mnd">
                  ....
                  <? }?>

                  or as I prefer it

                  <? if($is_properly _filled_out): ?>
                  <form action="<?=$_SE RVER['PHP_SELF']?>" name="myform"
                  method="post">
                  <select name="obs_mnd">
                  ....
                  <? endif; ?>

                  For HTML that appears often, you can define it as a function

                  <? function PrintLoginForm( $name) { ?>
                  <? $name = htmlspecialchar s($name); ?>
                  <form>
                  <table><tr><t d>
                  <input name="name" value="<?=$name ?>"><br>
                  ...
                  </table>
                  </form>
                  <? } ?>


                  Comment

                  • Chung Leong

                    #10
                    Re: $_SERVER[PHP_SELF] and &lt;SELECT&g t;


                    "Andy Hassall" <andy@andyh.co. uk> wrote in message
                    news:fpc6701dkg tua9veh6j9vgrkn l41gapqg6@4ax.c om...[color=blue]
                    >
                    > Strictly speaking you don't NEED to, but you certainly SHOULD do.[/color]

                    Why, you are right! Though I would swear that's something that can't be
                    done. I guess you learn something new everyday.


                    Comment

                    Working...