By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

add/edit combo form--opinions wanted

P: n/a
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?
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Mon, 12 Jul 2004 20:29:43 GMT, "Xenophobe" <xe*******@planetx.com> wrote:
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?


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 <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #2

P: n/a

"Xenophobe" <xe*******@planetx.com> wrote in message
news:XwCIc.62699$MB3.53701@attbi_s04...
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?


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

http://www.tonymarston.net

Jul 17 '05 #3

P: n/a
Xenophobe wrote:
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?


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?action=edit || index.php?action=add

--
kreso
Jul 17 '05 #4

P: n/a
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" <to**@NOSPAM.demon.co.uk> wrote in message
news:cd*******************@news.demon.co.uk...

"Xenophobe" <xe*******@planetx.com> wrote in message
news:XwCIc.62699$MB3.53701@attbi_s04...
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?


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

http://www.tonymarston.net

Jul 17 '05 #5

P: n/a
> 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.


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="adfsdfas">
<input type=hidden name=sender value=add_record>
......
<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.
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.