473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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?
Jul 17 '05 #1
5 2297
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

"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
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
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lucinda Roebuck | last post by:
I'm using Access 97 on a Windows XP computer. The combo box on the form "form1" will not refresh after a new name is added to the list. The "limit to list" properties for the combo box is set to...
1
by: Jim Heavey | last post by:
Suppose you had a Data Grid which had 7 columns in the normal mode. but when you selected "edit" mode you wanted 6 columns to appear on line 1 and the 7th column to appear on Line 2 under column 6....
6
by: Ron L | last post by:
I have a dataset whose source is a SQL 2k stored procedure that I am trying to display in a datagrid. This datasource has 4 columns that I am interested in here, a text column and 3 value columns...
9
by: Duncan Barnes-Ceeney | last post by:
I’m having problems with a custom Combo box. The main problem is that I want to modify the look of the combo which includes the size of the button. To do this I have inherited from the standard...
1
by: The Eclectic Electric | last post by:
I'd be very grateful if anyone could help me with this. From my limited knowledge of Javascript I don't think it is possible, but I'll punt anyway. I downloaded and very slightly adapted this...
0
by: Josetta | last post by:
This is for informational purposes...I had a problem and I thought it might help others in a similar situation. I hope someone, someday, finds this idea useful. I've garnered so much knowledge...
1
by: sejal17 | last post by:
hi everyone, I have a page with combo box. paypal payment:<select name="paypal"> <option value="On">On</Option> <option...
8
ddtpmyra
by: ddtpmyra | last post by:
Hi, I have PHP script that I use for new entry and edit entry, inside the form I have query combo (combo values querying from other table), my problem is how make the default value of my combo to...
0
by: Gordon Padwick | last post by:
A form contains controls, one or more of which can be other forms. A form that contains another form is known as a main form. A form contained by a main form is known as a subform. A subform itself...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.