Page 1 of 1

Validation ina multi record form ...

Posted: Sat Aug 17, 2002 11:22 pm
by markwenham
I am trying to design a form that has the following qualities

1. It can be multi-record depending upon number of rows in the db. I use
variable variables to do this.
2. It can be used to edit and update the rows.

The above is fine and works ok but I want to add

3. Server validation with PHP. If there is a problem with validation then I
want to re-present the form with the originally posted values.This is fairly
easy to do with a single record form by submitting the form to itself, BUT
doing this with a variable number of records is confusing me big time!!

Can anyone pass on their experiences with doing this sort of thing or
suggest the pseudo code.

Thanks, Mark
8O

Posted: Sat Aug 17, 2002 11:56 pm
by gotDNS
I'm going to bed now...i think i can help you tomorrow...

Posted: Sun Aug 18, 2002 12:01 am
by markwenham
sounds good, thanks

Posted: Sun Aug 18, 2002 12:45 am
by hob_goblin
assuming you use $_POST to transfer these variables

look into foreach().. you can pass each variable in post back to the form, or do what you want.

Posted: Sun Aug 18, 2002 9:49 am
by markwenham
Hmmm...

When I query the db I get say 3 records returned, each with 4 fields. I name the fields like this, where the trailing number relates to the record

ref0 fname0 sname0 tel0
ref1 fname1 sname1 tel1
ref2 fname2 sname2 tel2

These are obviously the keys that end up in the $_POST array once the form is posted.

Now what is confusing me is how I can reload the original page in the same format with posted values, should the validation not take place correctly. I guess my question also relates to how I can lay out the newly returned page. In the original page I use a loop with mysql_fetch_assoc to format one table row for each record returned.

In the newly returned page after unsuccesful validation all I have is the $_POST array which does not make a "per record" distinction. I guess I could use some type of substr to grab the number from the end of the item and format around that, but it seems clumsy. ??

Thanks, Mark