add/edit combo form--opinions wanted

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

    #1

    add/edit combo form--opinions wanted

    I would like to use the same form for adding new records and editing
    existing records. New form values are contained in $_POST. Database values
    are contained in an associated array. It seems to me that in order to use
    the same form for both tasks, I need to assign the form field values to page
    variables. The flow might look something like this:

    if $_POST

    $variable1 = $_POST['field1'];
    $variable2 = $_POST['field2'];

    else if $rows

    $variable1 = $row['field1'];
    $variable2 = $row['field2'];

    end if

    Can someone suggest a simplier way to do this?


  • Andy Hassall

    #2
    Re: add/edit combo form--opinions wanted

    On Mon, 12 Jul 2004 20:29:43 GMT, "Xenophobe" <xenophobe@plan etx.com> wrote:
    [color=blue]
    >I would like to use the same form for adding new records and editing
    >existing records. New form values are contained in $_POST. Database values
    >are contained in an associated array. It seems to me that in order to use
    >the same form for both tasks, I need to assign the form field values to page
    >variables. The flow might look something like this:
    >
    >if $_POST
    >
    >$variable1 = $_POST['field1'];
    >$variable2 = $_POST['field2'];
    >
    >else if $rows
    >
    >$variable1 = $row['field1'];
    >$variable2 = $row['field2'];
    >
    >end if
    >
    >Can someone suggest a simplier way to do this?[/color]

    Cut out the repeated $variables and just use one array, e.g.

    if ($rows)
    $vars = &$row;
    else
    $vars = &$_POST;

    And then use $vars['field1'], $vars['field2'] in the form?

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

    Comment

    • Tony Marston

      #3
      Re: add/edit combo form--opinions wanted


      "Xenophobe" <xenophobe@plan etx.com> wrote in message
      news:XwCIc.6269 9$MB3.53701@att bi_s04...[color=blue]
      > I would like to use the same form for adding new records and editing
      > existing records. New form values are contained in $_POST. Database values
      > are contained in an associated array. It seems to me that in order to use
      > the same form for both tasks, I need to assign the form field values to[/color]
      page[color=blue]
      > variables. The flow might look something like this:
      >
      > if $_POST
      >
      > $variable1 = $_POST['field1'];
      > $variable2 = $_POST['field2'];
      >
      > else if $rows
      >
      > $variable1 = $row['field1'];
      > $variable2 = $row['field2'];
      >
      > end if
      >
      > Can someone suggest a simplier way to do this?[/color]

      The simple way is to not use the same form for both operations. If you use
      separate scripts for input and amend you don't have to work out whether the
      user's input is for a INSERT or an UPDATE. This is what the KISS principle
      is all about.

      --
      Tony Marston

      This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




      Comment

      • Kreso

        #4
        Re: add/edit combo form--opinions wanted

        Xenophobe wrote:[color=blue]
        > I would like to use the same form for adding new records and editing
        > existing records. New form values are contained in $_POST. Database
        > values are contained in an associated array. It seems to me that in
        > order to use the same form for both tasks, I need to assign the form
        > field values to page variables. The flow might look something like
        > this:
        >
        > if $_POST
        >
        > $variable1 = $_POST['field1'];
        > $variable2 = $_POST['field2'];
        >
        > else if $rows
        >
        > $variable1 = $row['field1'];
        > $variable2 = $row['field2'];
        >
        > end if
        >
        > Can someone suggest a simplier way to do this?[/color]

        isset($_POST['field1']) ? variable1 = $_POST['field1'] : variable1 = '';

        but

        don't use same form for both operations. You can have 2 forms in single
        script(file) each triggered by passed variable

        FE:
        index.php?actio n=edit || index.php?actio n=add

        --
        kreso


        Comment

        • Xenophobe

          #5
          Re: add/edit combo form--opinions wanted

          True, but the forms (there are several, depending on the category of
          information being entered) is quite lengthy and--for ease of development &
          maintenance--was hoping to use one form for each.

          That said, I will probably go ahead and use separate forms for each
          (add/edit) and hope the client isn't change order happy.

          "Tony Marston" <tony@NOSPAM.de mon.co.uk> wrote in message
          news:cd0ad3$gj4 $1$8300dec7@new s.demon.co.uk.. .[color=blue]
          >
          > "Xenophobe" <xenophobe@plan etx.com> wrote in message
          > news:XwCIc.6269 9$MB3.53701@att bi_s04...[color=green]
          > > I would like to use the same form for adding new records and editing
          > > existing records. New form values are contained in $_POST. Database[/color][/color]
          values[color=blue][color=green]
          > > are contained in an associated array. It seems to me that in order to[/color][/color]
          use[color=blue][color=green]
          > > the same form for both tasks, I need to assign the form field values to[/color]
          > page[color=green]
          > > variables. The flow might look something like this:
          > >
          > > if $_POST
          > >
          > > $variable1 = $_POST['field1'];
          > > $variable2 = $_POST['field2'];
          > >
          > > else if $rows
          > >
          > > $variable1 = $row['field1'];
          > > $variable2 = $row['field2'];
          > >
          > > end if
          > >
          > > Can someone suggest a simplier way to do this?[/color]
          >
          > The simple way is to not use the same form for both operations. If you use
          > separate scripts for input and amend you don't have to work out whether[/color]
          the[color=blue]
          > user's input is for a INSERT or an UPDATE. This is what the KISS principle
          > is all about.
          >
          > --
          > Tony Marston
          >
          > http://www.tonymarston.net
          >
          >
          >[/color]


          Comment

          • Perttu Pulkkinen

            #6
            Re: add/edit combo form--opinions wanted

            > True, but the forms (there are several, depending on the category of[color=blue]
            > information being entered) is quite lengthy and--for ease of development &
            > maintenance--was hoping to use one form for each.
            > That said, I will probably go ahead and use separate forms for each
            > (add/edit) and hope the client isn't change order happy.[/color]

            Always include the unchanging parts in order to ease development & big
            fixes. Another thing is, that client should see what makes him happy. But he
            is not propably interested in how you do it?

            Make copy-paste scripts in internet are all-in-one-form type, but I ahve
            also discovered that it makes things messy, when you have to speculate "if
            elseif...." all the time.

            Usually I have do my forms like this:
            <form action="adfsdfa s">
            <input type=hidden name=sender value=add_recor d>
            ......
            <input type=submit name=sub value="ADD">
            <input type=submit name=sub value="DO SOMETHING ELSE">
            </form>

            This way I have more freedom to name submit buttons the way I want, even I
            can have same names in different forms, because sender (or it could be also
            just the name of the form!) separates them. Of course I could speculate the
            name of the submitbutton instead of its value, but it results more
            dirtylooking code.


            Comment

            Working...