masterlayouts Posted April 22, 2012 Share Posted April 22, 2012 Sending values to a script (chapter 9), we are using hidden form fields and URL parameters. What if I want to pass more values for one parameter? (not "name1=value1&name2=value2", rather "name1" having "value1" and "value2"). In the hidden form element I guess we define the element's value as an array. I am more interested in the URL situation, what will work best. Is it safer to use numeric values as parameters or strings will be just fine? Link to comment Share on other sites More sharing options...
HartleySan Posted April 22, 2012 Share Posted April 22, 2012 If you have an array with multiple values, it's best to split those values into multiple parameters in the URL. You could, of course, pass all the values using one parameter, but that would require you to provide some sort of delimiter and split the string up on the PHP receiving end, which is just a waste. One parameter per value is best. You can easily use a foreach loop, etc. to go through each value in the array and construct the parameters list for the URL. 1 Link to comment Share on other sites More sharing options...
masterlayouts Posted April 22, 2012 Author Share Posted April 22, 2012 Hi Hartley, thank you for your reply. The thing is that the number of values is variable and doing something to generate a unique name requires the same effort. I am interested in the best practices here, otherwise I assume it may be done either way. I am also interested if having the value of the parameter of numeric value is an advantage or not. I am guessing it is easier to use numbers; on the other hand if the database has a look up table to restrict the input to predefined values and this values are string I assume it is equally safe, the advantage being that it has meaning and one don't have to do any extra effort to interpret what the numeric value means. Now I do not have enough experience to decide. Link to comment Share on other sites More sharing options...
HartleySan Posted April 22, 2012 Share Posted April 22, 2012 The difference between interpreting a number versus a string is so minor that you will never notice it. It'd probably take (literally) billions of operations with numbers versus strings before you'd even see a difference, so I wouldn't worry about that. Send whatever values are most convenient for you. As for best practices, while I don't have a source to quote at the moment, I can almost guarantee you that one value per parameter is the recommended course of action. Beyond that, if you want to do your own thing, that's fine, but I think one value per parameter is the safest, easiest and least prone to human error. If you'd like to give more specifics about your site, then maybe I could help more, but otherwise, there's not much else I can say. Thanks for the inquiries though. 1 Link to comment Share on other sites More sharing options...
Recommended Posts