1 Replies - 481 Views - Last Post: 09 April 2012 - 01:05 PM

#1 hypertyper   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 13-December 10

How to process form with 20-30 fields?

Posted 09 April 2012 - 05:07 AM

I'm trying to read form inputs and eventually put them into a mysql db. I don't know how to conceptually do it. Should I give related fields the same "name" attribute so I have them in an array once I've posted them to the php file?

How about using JS to concatenate the fields into one "name" with delimiter to then split in php?

At the moment each field has a unique "name" but looping through will become slightly tricky in php.

All examples I can find are for small fields with very few fields and I don't know how to best scale it up.

I'd appreciate it any suggestions or tips.

Is This A Good Question/Topic? 0
  • +

Replies To: How to process form with 20-30 fields?

#2 4D1   User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 225
  • Joined: 22-October 09

Re: How to process form with 20-30 fields?

Posted 09 April 2012 - 01:05 PM

Its hard to say as I dont know what your already doing, but you could loop through them as follows...

foreach(array('someval', 'someval', 'someval', 'someval') as $field){
        //do some processing
        $mySanitizedArray[$field] = sanitized($_POST[$field]);

        case 'telephone':  //Telephone specific stuff;
        case 'email':  //Email specific stuff;
        default:  //Default string stuff;

As above it would also be easy to dynamically build the insert/update query if the form names match the DB fields, obviously you could add a prefix/suffix to the fields during processing if you didnt want to give away the field/table names in the source.

I beleive it is generally considered bad practice to rely on client side code, for instance checking that all mandatory fields are complete client side will save time, but ther should be server side code to do the same in case client side code is disabled or bypassed.

This post has been edited by 4D1: 09 April 2012 - 01:16 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1