Hello,
I am converting a site from ASP to PHP. The conversion are just about done with one exception. I am having an issue with form fields with the same name and how they are handled differently from ASP to PHP.
First what I am doing: I have multiple form fields with the same name for not only checkboxes but all types of form fields (text boxes, selects, etc). This is because the page is dynamically generated with multiple rows of data dynamically from the database and it allows the user to update one or all that are returned when the page is created. The user can update 1 or 10 different items at the same time (and each item has the same field name).
This works fine in ASP and using Javascript for validation using the field name as an array of values.
I researched and see how I need to change the form field name to use "[]" after the name to make this work in PHP so I can access the values of the form as an array.
My issue/question is:
1. Is there a way I can keep all my Javascript validation without having to re-write it all (using an array of the form fields). (I am currently using the form field name to access the values in the form fields).
2. What kinds of updates/changes do I need to make to the Javascipt to make it work if I change the form fields to have "[]" on the end of the name and still work/validate properly? I am currently using a LOT of functions that I just pass the object to the function and the function validates it, like this
ValidateFunction(window.do
cument.for
mName.fiel
dName)
3. What type of error trapping/checking will I need to do in PHP if there is only one field/value returned vs. 10? So the code will still execute properly if there is 1 field submitted on the form or if there are 10 with the same name?
If I had to make changes to the Javascript what would I need to do in the Javascript to make the changes I had to make in PHP work in Javascript?
I am great with ASP and Javascript and getting PHP pretty quick. I just want to find a way to make this work so I do not have to completely re-write all my form and Javascript code.
Thank you in advance for your help.
Start Free Trial