Form with 2 submit buttons...

Discussion in 'HTML' started by Sonnich, Aug 7, 2006.

  1. Sonnich

    Sonnich Guest

    Hi all!

    I have a file where I'd have to submit buttons, and I need to differ
    between those.

    Step #1 - open html win with default selection

    Step #2 - user may select some criteries for the list
    Step 2 might be repeated, or not used at all. There is a button "apply
    selection"

    Step #3 - user selects a number of files/items, which are then handled.
    There is a button for that.
    Done.

    The point is, that I need both the critearies for the SQL selection in
    step 2, but also the selected files (list) in step 3. Actually the
    selection for step 2 are needed for step 3 only.

    Any good ideas on how I might have 2 buttons with submits data?

    BR
    Sonnich
     
    Sonnich, Aug 7, 2006
    #1
    1. Advertising

  2. Sonnich

    ZeldorBlat Guest

    Sonnich wrote:
    > Hi all!
    >
    > I have a file where I'd have to submit buttons, and I need to differ
    > between those.
    >
    > Step #1 - open html win with default selection
    >
    > Step #2 - user may select some criteries for the list
    > Step 2 might be repeated, or not used at all. There is a button "apply
    > selection"
    >
    > Step #3 - user selects a number of files/items, which are then handled.
    > There is a button for that.
    > Done.
    >
    > The point is, that I need both the critearies for the SQL selection in
    > step 2, but also the selected files (list) in step 3. Actually the
    > selection for step 2 are needed for step 3 only.
    >
    > Any good ideas on how I might have 2 buttons with submits data?
    >
    > BR
    > Sonnich


    Not entirely sure what you're trying to do, but if you want two submit
    buttons just give them different names:

    <input type="submit" name="foo" value="First Button"/>
    <input type="submit" name="bar" value="Second Button"/>

    And on the target page:

    if(isset($_REQUEST['foo'])) {
    //first button was used
    }
    else if(isset($_REQUEST['bar'])) {
    //second button was used
    }
     
    ZeldorBlat, Aug 7, 2006
    #2
    1. Advertising

  3. Sonnich

    Sonnich Guest

    ZeldorBlat wrote:
    > Sonnich wrote:
    > > Hi all!
    > >
    > > I have a file where I'd have to submit buttons, and I need to differ
    > > between those.
    > >
    > > Step #1 - open html win with default selection
    > >
    > > Step #2 - user may select some criteries for the list
    > > Step 2 might be repeated, or not used at all. There is a button "apply
    > > selection"
    > >
    > > Step #3 - user selects a number of files/items, which are then handled.
    > > There is a button for that.
    > > Done.
    > >
    > > The point is, that I need both the critearies for the SQL selection in
    > > step 2, but also the selected files (list) in step 3. Actually the
    > > selection for step 2 are needed for step 3 only.
    > >
    > > Any good ideas on how I might have 2 buttons with submits data?
    > >
    > > BR
    > > Sonnich

    >
    > Not entirely sure what you're trying to do, but if you want two submit
    > buttons just give them different names:
    >
    > <input type="submit" name="foo" value="First Button"/>
    > <input type="submit" name="bar" value="Second Button"/>
    >
    > And on the target page:
    >
    > if(isset($_REQUEST['foo'])) {
    > //first button was used
    > }
    > else if(isset($_REQUEST['bar'])) {
    > //second button was used
    > }


    That was exactly what I needed.

    I found that it should work here too:

    if( !(isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] ==
    "")) )
    echo " checked";
    else
    echo "";

    Idea: checkbox is default checked, but only if set and set to nothing
    it is not set.
    Boolean algebra. Only if set, and set to nothing, then it is not set.

    But by some reason it does not work. I have done this a 147533 times,
    and here it does not work. Why?
     
    Sonnich, Aug 7, 2006
    #3
  4. Sonnich wrote:
    > ZeldorBlat wrote:
    >> Sonnich wrote:
    >>> Hi all!
    >>>
    >>> I have a file where I'd have to submit buttons, and I need to differ
    >>> between those.
    >>>
    >>> Step #1 - open html win with default selection
    >>>
    >>> Step #2 - user may select some criteries for the list
    >>> Step 2 might be repeated, or not used at all. There is a button "apply
    >>> selection"
    >>>
    >>> Step #3 - user selects a number of files/items, which are then handled.
    >>> There is a button for that.
    >>> Done.
    >>>
    >>> The point is, that I need both the critearies for the SQL selection in
    >>> step 2, but also the selected files (list) in step 3. Actually the
    >>> selection for step 2 are needed for step 3 only.
    >>>
    >>> Any good ideas on how I might have 2 buttons with submits data?
    >>>
    >>> BR
    >>> Sonnich

    >> Not entirely sure what you're trying to do, but if you want two submit
    >> buttons just give them different names:
    >>
    >> <input type="submit" name="foo" value="First Button"/>
    >> <input type="submit" name="bar" value="Second Button"/>
    >>
    >> And on the target page:
    >>
    >> if(isset($_REQUEST['foo'])) {
    >> //first button was used
    >> }
    >> else if(isset($_REQUEST['bar'])) {
    >> //second button was used
    >> }

    >
    > That was exactly what I needed.
    >
    > I found that it should work here too:
    >
    > if( !(isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] ==
    > "")) )
    > echo " checked";
    > else
    > echo "";
    >
    > Idea: checkbox is default checked, but only if set and set to nothing
    > it is not set.
    > Boolean algebra. Only if set, and set to nothing, then it is not set.
    >
    > But by some reason it does not work. I have done this a 147533 times,
    > and here it does not work. Why?
    >

    I think a misplaced closing parentheses:

    if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] =="") ){
    echo " checked";
    }
    else {
    echo "";
    }

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Aug 7, 2006
    #4
  5. Sonnich

    Sonnich Guest

    - setting checkboxes


    > > I found that it should work here too:
    > >
    > > if( !(isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] ==
    > > "")) )
    > > echo " checked";
    > > else
    > > echo "";
    > >
    > > Idea: checkbox is default checked, but only if set and set to nothing
    > > it is not set.
    > > Boolean algebra. Only if set, and set to nothing, then it is not set.
    > >
    > > But by some reason it does not work. I have done this a 147533 times,
    > > and here it does not work. Why?
    > >

    > I think a misplaced closing parentheses:
    >


    You were right. This is what I have now:

    if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] ==
    "") )
    echo " checked";
    else
    echo "";

    but is still does not work. It sets them first time as it should, but
    after that it inverts the selection.
    I dont get it.

    Any ideas anyone?
     
    Sonnich, Aug 7, 2006
    #5
  6. Sonnich

    Miguel Cruz Guest

    "Sonnich" <> wrote:
    > I found that it should work here too:
    >
    > if( !(isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] ==
    > "")) )
    > echo " checked";
    > else
    > echo "";
    >
    > Idea: checkbox is default checked, but only if set and set to nothing
    > it is not set.
    > Boolean algebra. Only if set, and set to nothing, then it is not set.
    >
    > But by some reason it does not work. I have done this a 147533 times,
    > and here it does not work. Why?


    Are you sure you want $_POST[$part1[$i]] ? Maybe $_POST[$part1][$i] ?

    Hard to know without understanding how your form and code look, but my
    proposed alternative is more typical for dealing with checkboxes.

    If I am correct in my theory, turning on E_ALL error reporting would
    have drawn attention to the issue.

    miguel
    --
    Photos from 40 countries on 5 continents: http://travel.u.nu
    Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
    Airports of the world: http://airport.u.nu
     
    Miguel Cruz, Aug 7, 2006
    #6
  7. Sonnich

    Sonnich Guest

    Miguel Cruz wrote:
    > "Sonnich" <> wrote:
    > > I found that it should work here too:
    > >
    > > if( !(isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] ==
    > > "")) )
    > > echo " checked";
    > > else
    > > echo "";
    > >
    > > Idea: checkbox is default checked, but only if set and set to nothing
    > > it is not set.
    > > Boolean algebra. Only if set, and set to nothing, then it is not set.
    > >
    > > But by some reason it does not work. I have done this a 147533 times,
    > > and here it does not work. Why?

    >
    > Are you sure you want $_POST[$part1[$i]] ? Maybe $_POST[$part1][$i] ?
    >
    > Hard to know without understanding how your form and code look, but my
    > proposed alternative is more typical for dealing with checkboxes.
    >
    > If I am correct in my theory, turning on E_ALL error reporting would
    > have drawn attention to the issue.


    I have a number of checkboxes, which are created from a DB. I read a
    number of codes into an array $part1[]= then I create the checkboxes
    Name=\"$part1[$i]] \" and at the same time set them to checked or not.
    At first they should be checked, but the user can select to uncheck
    them. Then, when submitting the now present values should be in use.

    BR
    Sonnich
     
    Sonnich, Aug 7, 2006
    #7
  8. Re: - setting checkboxes

    Sonnich wrote:

    [You are improperly snipping who wrote what quote which can get quite
    confusing, try to keep or replace quoted author notices which I have
    restored to show you....]


    >> Sonnich wrote:
    >>>
    >>> I found that it should work here too:
    >>>
    >>> if( !(isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] ==
    >>> "")) )
    >>> echo " checked";
    >>> else
    >>> echo "";
    >>>
    >>> Idea: checkbox is default checked, but only if set and set to nothing
    >>> it is not set.
    >>> Boolean algebra. Only if set, and set to nothing, then it is not set.
    >>>
    >>> But by some reason it does not work. I have done this a 147533 times,
    >>> and here it does not work. Why?
    >>>


    > Jonathan wrote:
    >>
    >> I think a misplaced closing parentheses:
    >>

    >
    > You were right. This is what I have now:
    >
    > if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] ==
    > "") )
    > echo " checked";
    > else
    > echo "";
    >
    > but is still does not work. It sets them first time as it should, but
    > after that it inverts the selection.
    > I dont get it.
    >
    > Any ideas anyone?
    >


    Not enough info to determine, need URL and your source code. What you
    you me by 'sets them'? Sets what? And 'after the first time'? Are your
    reposting to the same script?

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Aug 7, 2006
    #8
  9. Sonnich

    Sonnich Guest

    Re: - setting checkboxes

    Jonathan N. Little wrote:
    > Sonnich wrote:
    >
    > [You are improperly snipping who wrote what quote which can get quite
    > confusing, try to keep or replace quoted author notices which I have
    > restored to show you....]
    >
    >
    > >> Sonnich wrote:
    > >>>
    > >>> I found that it should work here too:
    > >>>
    > >>> if( !(isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] ==
    > >>> "")) )
    > >>> echo " checked";
    > >>> else
    > >>> echo "";
    > >>>
    > >>> Idea: checkbox is default checked, but only if set and set to nothing
    > >>> it is not set.
    > >>> Boolean algebra. Only if set, and set to nothing, then it is not set.
    > >>>
    > >>> But by some reason it does not work. I have done this a 147533 times,
    > >>> and here it does not work. Why?
    > >>>

    >
    > > Jonathan wrote:
    > >>
    > >> I think a misplaced closing parentheses:
    > >>

    > >
    > > You were right. This is what I have now:
    > >
    > > if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] ==
    > > "") )
    > > echo " checked";
    > > else
    > > echo "";
    > >
    > > but is still does not work. It sets them first time as it should, but
    > > after that it inverts the selection.
    > > I dont get it.
    > >
    > > Any ideas anyone?
    > >

    >
    > Not enough info to determine, need URL and your source code. What you
    > you me by 'sets them'? Sets what? And 'after the first time'? Are your
    > reposting to the same script?


    Yes, I am reposting to the same script. An example:


    <html>
    <form method=post name='myform' action='sjjtest.php'><!-- same file -->
    <table>
    <?
    $part1[]="a";
    $part1[]="b";
    $part1[]="c";
    for($i=0; $i<count($part1); $i++)
    {
    echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox\"
    value=\"true\"";
    if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
    echo " checked";
    echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
    .."</td></tr>";
    }
    ?>
    <tr><td><input class="box" name="apply_selection" type="submit" value="
    Apply selection "></td></tr>
    </table>
    </form>
    </html>

    Try it and you will see
     
    Sonnich, Aug 7, 2006
    #9
  10. Sonnich

    Rik Guest

    Re: - setting checkboxes

    Sonnich wrote:
    > <?
    > $part1[]="a";
    > $part1[]="b";
    > $part1[]="c";
    > for($i=0; $i<count($part1); $i++)
    > {
    > echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox\"
    > value=\"true\"";
    > if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
    > echo " checked";
    > echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]


    Euhm, what it this last bit
    'isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]' actually supposed to do?
    It will either print '1-true' or ''(nothing)?

    > ."</td></tr>";
    > }



    You've got a submit button, it's name is in the POST array, so it should be
    present if the form is posted. Before posting, everything should be checked.
    After the posting only the previously left checked values should be checked,
    the rest unchecked. Is that how it should work? in that case:

    So let's say checked when:
    - $_POST['submit'] is not set
    OR
    - $_POST[$key] is in the array AND the value isn't empty

    $part1 = array('a','b','c'...........

    foreach($part1 as $value){
    $checked = (!isset($_POST['submit'] || (isset($_POST[$value]) &&
    !empty($_POST[$value])) ? ' checked' : '';
    printf('<td><input type="checkbox" name="%1$s"
    value="true"%2$s>%1$s</td>',$value,$checked');
    }

    Grtz,
    --
    Rik Wasmus
     
    Rik, Aug 7, 2006
    #10
  11. Re: - setting checkboxes

    Sonnich wrote:

    >
    > <html>
    > <form method=post name='myform' action='sjjtest.php'><!-- same file -->
    > <table>
    > <?
    > $part1[]="a";
    > $part1[]="b";
    > $part1[]="c";
    > for($i=0; $i<count($part1); $i++)
    > {
    > echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox\"
    > value=\"true\"";
    > if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
    > echo " checked";
    > echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
    > ."</td></tr>";
    > }
    > ?>
    > <tr><td><input class="box" name="apply_selection" type="submit" value="
    > Apply selection "></td></tr>
    > </table>
    > </form>
    > </html>
    >
    > Try it and you will see
    >


    Not sure what you are trying to accomplish here but in PHP block
    statements need to be surrounded by braces {} therefore it think your
    PHP part should be:


    <?
    $part1[]="a";
    $part1[]="b";
    $part1[]="c";
    for($i=0; $i<count($part1); $i++)
    {
    echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox\"
    value=\"true\"";

    if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
    { //needed open brace
    echo " checked";
    } //closing brace

    echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
    .."</td></tr>";
    }
    ?>


    But again not sure what your aim is here....

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Aug 8, 2006
    #11
  12. Re: - setting checkboxes

    Jonathan N. Little wrote:
    > Sonnich wrote:
    >
    >>
    >> <html>
    >> <form method=post name='myform' action='sjjtest.php'><!-- same file -->
    >> <table>
    >> <?
    >> $part1[]="a";
    >> $part1[]="b";
    >> $part1[]="c";
    >> for($i=0; $i<count($part1); $i++)
    >> {
    >> echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox\"
    >> value=\"true\"";
    >> if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
    >> echo " checked";
    >> echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
    >> ."</td></tr>";
    >> }
    >> ?>
    >> <tr><td><input class="box" name="apply_selection" type="submit" value="
    >> Apply selection "></td></tr>
    >> </table>
    >> </form>
    >> </html>
    >>
    >> Try it and you will see
    >>

    >
    > Not sure what you are trying to accomplish here but in PHP block
    > statements need to be surrounded by braces {} therefore it think your
    > PHP part should be:
    >
    >
    > <?
    > $part1[]="a";
    > $part1[]="b";
    > $part1[]="c";
    > for($i=0; $i<count($part1); $i++)
    > {
    > echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox\"
    > value=\"true\"";
    >
    > if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
    > { //needed open brace
    > echo " checked";
    > } //closing brace
    >
    > echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
    > ."</td></tr>";
    > }
    > ?>
    >
    >
    > But again not sure what your aim is here....
    >


    Actually since the body of the if statement is a single statement, the
    braces are optional. Only if you have multiple statements in the body
    of a loop, if, else, etc. are braces required.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.

    ==================
     
    Jerry Stuckle, Aug 8, 2006
    #12
  13. Re: - setting checkboxes

    Sonnich wrote:
    > Jonathan N. Little wrote:
    >
    >>Sonnich wrote:
    >>
    >>[You are improperly snipping who wrote what quote which can get quite
    >>confusing, try to keep or replace quoted author notices which I have
    >>restored to show you....]
    >>
    >>
    >> >> Sonnich wrote:
    >> >>>

    >>
    >>>>>I found that it should work here too:
    >>>>>
    >>>>> if( !(isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] ==
    >>>>>"")) )
    >>>>> echo " checked";
    >>>>> else
    >>>>> echo "";
    >>>>>
    >>>>>Idea: checkbox is default checked, but only if set and set to nothing
    >>>>>it is not set.
    >>>>>Boolean algebra. Only if set, and set to nothing, then it is not set.
    >>>>>
    >>>>>But by some reason it does not work. I have done this a 147533 times,
    >>>>>and here it does not work. Why?
    >>>>>

    >>
    >> > Jonathan wrote:
    >> >>

    >>
    >>>>I think a misplaced closing parentheses:
    >>>>
    >>>
    >>>You were right. This is what I have now:
    >>>
    >>> if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] ==
    >>>"") )
    >>> echo " checked";
    >>> else
    >>> echo "";
    >>>
    >>>but is still does not work. It sets them first time as it should, but
    >>>after that it inverts the selection.
    >>>I dont get it.
    >>>
    >>>Any ideas anyone?
    >>>

    >>
    >>Not enough info to determine, need URL and your source code. What you
    >>you me by 'sets them'? Sets what? And 'after the first time'? Are your
    >>reposting to the same script?

    >
    >
    > Yes, I am reposting to the same script. An example:
    >
    >
    > <html>
    > <form method=post name='myform' action='sjjtest.php'><!-- same file -->
    > <table>
    > <?
    > $part1[]="a";
    > $part1[]="b";
    > $part1[]="c";
    > for($i=0; $i<count($part1); $i++)
    > {
    > echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox\"
    > value=\"true\"";
    > if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
    > echo " checked";
    > echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
    > ."</td></tr>";
    > }
    > ?>
    > <tr><td><input class="box" name="apply_selection" type="submit" value="
    > Apply selection "></td></tr>
    > </table>
    > </form>
    > </html>
    >
    > Try it and you will see
    >


    If you had all errors enabled and were displaying them, you would have
    found errors in both statements with isset():

    Notice: Undefined index: a in myform.php on line 10

    In the first one your parens were set so that you were checking $_POST
    whether or not the particular index was set. In the second one the
    value in $_POST is always checked, whether it is valid or not.

    The following code does what you want:

    <?php
    $part1[]="a";
    $part1[]="b";
    $part1[]="c";
    for($i=0; $i<count($part1); $i++)
    {
    echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox\"
    value=\"true\"";

    if( (isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] != "") ))
    echo " checked";

    echo ">". (isset($_POST[$part1[$i]]) ? "-" . $_POST[$part1[$i]] :
    "" ) . "</td></tr>";
    }
    ?>


    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.

    ==================
     
    Jerry Stuckle, Aug 8, 2006
    #13
  14. Sonnich

    Miguel Cruz Guest

    "Sonnich" <> wrote:
    > Miguel Cruz wrote:
    >> "Sonnich" <> wrote:
    >>> if( !(isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] == "")) )

    >>
    >> Are you sure you want $_POST[$part1[$i]] ? Maybe $_POST[$part1][$i] ?
    >>
    >> Hard to know without understanding how your form and code look, but my
    >> proposed alternative is more typical for dealing with checkboxes.
    >>
    >> If I am correct in my theory, turning on E_ALL error reporting would
    >> have drawn attention to the issue.

    >
    > I have a number of checkboxes, which are created from a DB. I read a
    > number of codes into an array $part1[]= then I create the checkboxes
    > Name=\"$part1[$i]] \" and at the same time set them to checked or not.
    > At first they should be checked, but the user can select to uncheck
    > them. Then, when submitting the now present values should be in use.


    In that case you definitely want $_POST[$part1][$i] .

    miguel
    --
    Photos from 40 countries on 5 continents: http://travel.u.nu
    Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
    Airports of the world: http://airport.u.nu
     
    Miguel Cruz, Aug 8, 2006
    #14
  15. Sonnich

    Sonnich Guest

    Re: - setting checkboxes

    Rik wrote:
    > Sonnich wrote:
    > > <?
    > > $part1[]="a";
    > > $part1[]="b";
    > > $part1[]="c";
    > > for($i=0; $i<count($part1); $i++)
    > > {
    > > echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox\"
    > > value=\"true\"";
    > > if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
    > > echo " checked";
    > > echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]

    >
    > Euhm, what it this last bit
    > 'isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]' actually supposed to do?
    > It will either print '1-true' or ''(nothing)?


    That was meant as debugging :)

    >
    > > ."</td></tr>";
    > > }

    >
    >
    > You've got a submit button, it's name is in the POST array, so it should be
    > present if the form is posted. Before posting, everything should be checked.
    > After the posting only the previously left checked values should be checked,
    > the rest unchecked. Is that how it should work? in that case:


    Almost.
    In case of any new items, they should be checked too.

    There are other options, which might change sql query and by that the
    array, so we have new items. They should be selected by default when
    they appear.
    Otherwise I found this useful.

    I'll have to read a bit more about this subjet for PHP.

    BR & thanks
    Sonnich


    >
    > So let's say checked when:
    > - $_POST['submit'] is not set
    > OR
    > - $_POST[$key] is in the array AND the value isn't empty
    >
    > $part1 = array('a','b','c'...........
    >
    > foreach($part1 as $value){
    > $checked = (!isset($_POST['submit'] || (isset($_POST[$value]) &&
    > !empty($_POST[$value])) ? ' checked' : '';
    > printf('<td><input type="checkbox" name="%1$s"
    > value="true"%2$s>%1$s</td>',$value,$checked');
    > }
    >
    > Grtz,
    > --
    > Rik Wasmus
     
    Sonnich, Aug 8, 2006
    #15
  16. Sonnich

    Rik Guest

    Re: - setting checkboxes

    Sonnich wrote:
    > Rik wrote:
    >> Sonnich wrote:
    >>> <?
    >>> $part1[]="a";
    >>> $part1[]="b";
    >>> $part1[]="c";
    >>> for($i=0; $i<count($part1); $i++)
    >>> {
    >>> echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox\"
    >>> value=\"true\"";
    >>> if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
    >>> echo " checked";
    >>> echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]

    >> Euhm, what it this last bit
    >> 'isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]' actually supposed to do?
    >> It will either print '1-true' or ''(nothing)?

    >
    > That was meant as debugging :)
    >
    >>> ."</td></tr>";
    >>> }

    >>
    >> You've got a submit button, it's name is in the POST array, so it should be
    >> present if the form is posted. Before posting, everything should be checked.
    >> After the posting only the previously left checked values should be checked,
    >> the rest unchecked. Is that how it should work? in that case:

    >
    > Almost.
    > In case of any new items, they should be checked too.
    >
    > There are other options, which might change sql query and by that the
    > array, so we have new items. They should be selected by default when
    > they appear.
    > Otherwise I found this useful.
    >
    > I'll have to read a bit more about this subjet for PHP.


    Well, if we have to check wether the fields existed on the last
    page-load, there are several options:
    - store the request time, and the date fields get added. This is
    somewhat bulky.
    - store the available fields in a session, and on reload compare the
    session variable with the then available fields.
    - add an input type=hidden for every field, containing the name, and on
    submit check wether an available name is in the POST array or not.

    Grtz,
    --
    Rik Wasmus
     
    Rik, Aug 8, 2006
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    0
    Views:
    723
  2. Replies:
    4
    Views:
    1,014
  3. Matt
    Replies:
    2
    Views:
    193
    Bob Barrows [MVP]
    Jun 27, 2004
  4. Matt
    Replies:
    1
    Views:
    228
    Thomas 'PointedEars' Lahn
    Jul 5, 2004
  5. Replies:
    3
    Views:
    797
Loading...

Share This Page