PDA

View Full Version : Insert Multiple Records Question


eyethian348566
06-24-2009, 05:50 PM
Hello.

I've finally got around in using DataAssist. Not bad. However, there seemed to be a 'gotcha' or two. Maybe it's just a clash of coding preferences and/or styles.

I finally used the Insert Multiple Records server behavior. The gotcha was that I used the form names as student[] array instead of student0, or student1, etc. for dynamically generated records. This way, when PHP 'POST's the form, there'll be a nice array of student[] for me to work on. (For more examples, google "dynamic forms array php" to get the gist of what I'm using.)

Apparently, DataAssist insists on naming them as student[]_0, student[]_1, student[]_2, and breaks the script. :( The script can't 'find' the fields and simply aborts the process.

Is there a way I could use my dynamic form arrays instead of the using counter scheme for the Insert Multiple Records server behavior? I could rewrite my form to use appended counter values, and hope it doesn't break anything else.

Ray Borduin
06-25-2009, 07:58 AM
No there isn't a way.

The code depends on the naming convention to keep track of which field is filled out. Using the naming convention you recommend you wouldn't be able to get checkboxes to work since unchecked boxes would not be in the array and your form would have arrays of varrying length. This would prevent you from matching the array value to the correct corresponding value.

Also your technique would prevent users from having a multiselect list or checkbox group in thier form... It actaully requires naming like:
student_0[], student_1[], student_2[]... since the form fields themselves can be arrays already.

You might be able to hand edit the code to work in your case, but I would contend you would be limiting yourself by using the structure you propose, and though in simple forms it may work out for you things like checkboxes, checkbox groups, and multiselect lists really aren't covered in your proposed syntax.

eyethian348566
06-26-2009, 12:30 AM
The code depends on the naming convention to keep track of which field is filled out. Using the naming convention you recommend you wouldn't be able to get checkboxes to work since unchecked boxes would not be in the array and your form would have arrays of varrying length. This would prevent you from matching the array value to the correct corresponding value.Thank you for getting back to me quickly. First off; I simply assigned a counter value to the checkboxes. This way, the selected checkboxes will have a corresponding value, and the form will know what elements were selected, etc. Problem solved. :)

However, as you have aptly illustrated below;Also, your technique would prevent users from having a multiselect list or checkbox group in thier form... It actaully requires naming like:
student_0[], student_1[], student_2[]... since the form fields themselves can be arrays already.So the array technique in form collection isn't perfect. I'm not gonna quibble with you about that. I originally coded PHP the hard way; via BlueFish on Linux systems. When I first used Dreamweaver CS3, my eyes bugged out; you can do that with a simple server behavior? Never looked back.

I'm trying to get away from that, and try to rely on professional tools like your offerings a little bit more. I guess I will expect to stumble a little bit more of these 'gotcha's' as I use your tools more often, and try to adapt my coding style appropriately. I just hate it when it happens, as it costs me time in debugging my work. So far, DataAssist has generally met my expectations.

Ray Borduin
06-26-2009, 06:15 AM
I didn't really mean to quibble. We just need to design our code to work with everything and although you could use a simpler implementation because you aren't using multiselect lists or checkbox groups in your form, our code needs the added complexity to account for users that do.