[PHP-DEV] Bug #13718 Updated: form elements with same name problem
ID: 13718 User updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Bogus Bug Type: Feature/Change Request Operating System: All PHP Version: 4.0.6 New Comment: I'm sorry to keep bringing this issue to light, but this actually would mimic that of your existing functionality. If you name an element in a form with a [] that does not garuntee that the variable on the other end will be an array. If there is only one element posted with that name followed by [] it will end up as a standard variable. So, I again make the plea: If you have more than one element with the same name with or without a [] it will come out an array. If you have one element with or without a [] it will come out the other end as a single variable. It is possible that you actually intended for the single element with [] to come out as an array, if that is the case, I guess you should consider this a bug report for the functionality of trailing [] in forms. Previous Comments: [2001-10-18 11:38:37] [EMAIL PROTECTED] Oh, I'm sorry, I missunderstood you. I understand what you are getting at, ambiguity can be a problem. I guess I'll just deal with using the suggestion of indexing on a string in javascript. Thank you for all your help. [2001-10-18 11:33:49] [EMAIL PROTECTED] no, i didn't ;) i just tried to describe what would happen *if* we would follow your suggestion and that it is a not so good idea after all (although we definetly should have a look at the [] syntax regarding standard conformance) [2001-10-18 10:57:57] [EMAIL PROTECTED] wow, I just noticed that you are suggesting that php actually generate an array! I posted two example html files, that clearly show that you are wrong. PHP always treats them as a single variable, no matter how many are actually set. [2001-10-18 10:54:37] [EMAIL PROTECTED] sorry, I refreshed the page, and it reposted. Thank you for your help, I hope that you will consider my suggestion for future releases. [2001-10-18 10:53:44] [EMAIL PROTECTED] I do understand that if you were in the middle of a php script, this would be a simple reassigning of the variable. However, this is a preprocessor command, and thus should be handled a little differently. Adding a [] at the tail of a variable and having it come out as an array on the other end seems a like a trick. It has its uses I'll give you that, but if you look at my suggestion you will realize that it would be a nice feature. You guys seem to have take the time to make sure that elements with [] get properly shoved into arrays, so why not this. This is a fairly common situation in html forms. Especially if you are dynamically generating them. What this really comes down to is, are you willing to overlook the fact that something like this does sort of already exist, in favor of another form of functionality? There is one other issue. If you use the variable names that you suggest, it breaks javascript. ie: html body form name=form1 action= method=post Baseball: input type=checkbox name=interest[] value=baseball br Teams: input type=text name=teams[] size=30 onFocus=form1.interest[0].checked=1 br input type=submit value=submit /form /body /html will cause an error, because you don't define arrays in javascript this way. I realize that this seems like a bug in javascript, but actually it isn't. The html 4.01 specification clearly states that: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). Note: this does not suggest that you can add [ or ]. So, in essence you are violating the html specification. If you still do not agree that this would only improve php, I will stop bothering you. The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/?id=13718 Edit this bug report at http://bugs.php.net/?id=13718edit=1 -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] Bug #13718 Updated: form elements with same name problem
I can't reproduce this with neither with current CVS nor with 4.0.6. Can you post a small reproduceable example ? - Markus ps: no idea, php.bugs won't accept my cvs user/pass On Wed, Oct 24, 2001 at 10:58:57PM -, [EMAIL PROTECTED] wrote : ID: 13718 User updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Bogus Bug Type: Feature/Change Request Operating System: All PHP Version: 4.0.6 New Comment: I'm sorry to keep bringing this issue to light, but this actually would mimic that of your existing functionality. If you name an element in a form with a [] that does not garuntee that the variable on the other end will be an array. If there is only one element posted with that name followed by [] it will end up as a standard variable. So, I again make the plea: If you have more than one element with the same name with or without a [] it will come out an array. If you have one element with or without a [] it will come out the other end as a single variable. It is possible that you actually intended for the single element with [] to come out as an array, if that is the case, I guess you should consider this a bug report for the functionality of trailing [] in forms. Previous Comments: [2001-10-18 11:38:37] [EMAIL PROTECTED] Oh, I'm sorry, I missunderstood you. I understand what you are getting at, ambiguity can be a problem. I guess I'll just deal with using the suggestion of indexing on a string in javascript. Thank you for all your help. [2001-10-18 11:33:49] [EMAIL PROTECTED] no, i didn't ;) i just tried to describe what would happen *if* we would follow your suggestion and that it is a not so good idea after all (although we definetly should have a look at the [] syntax regarding standard conformance) [2001-10-18 10:57:57] [EMAIL PROTECTED] wow, I just noticed that you are suggesting that php actually generate an array! I posted two example html files, that clearly show that you are wrong. PHP always treats them as a single variable, no matter how many are actually set. [2001-10-18 10:54:37] [EMAIL PROTECTED] sorry, I refreshed the page, and it reposted. Thank you for your help, I hope that you will consider my suggestion for future releases. [2001-10-18 10:53:44] [EMAIL PROTECTED] I do understand that if you were in the middle of a php script, this would be a simple reassigning of the variable. However, this is a preprocessor command, and thus should be handled a little differently. Adding a [] at the tail of a variable and having it come out as an array on the other end seems a like a trick. It has its uses I'll give you that, but if you look at my suggestion you will realize that it would be a nice feature. You guys seem to have take the time to make sure that elements with [] get properly shoved into arrays, so why not this. This is a fairly common situation in html forms. Especially if you are dynamically generating them. What this really comes down to is, are you willing to overlook the fact that something like this does sort of already exist, in favor of another form of functionality? There is one other issue. If you use the variable names that you suggest, it breaks javascript. ie: html body form name=form1 action= method=post Baseball: input type=checkbox name=interest[] value=baseball br Teams: input type=text name=teams[] size=30 onFocus=form1.interest[0].checked=1 br input type=submit value=submit /form /body /html will cause an error, because you don't define arrays in javascript this way. I realize that this seems like a bug in javascript, but actually it isn't. The html 4.01 specification clearly states that: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). Note: this does not suggest that you can add [ or ]. So, in essence you are violating the html specification. If you still do not agree that this would only improve php, I will stop bothering you. The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/?id=13718 Edit this bug report at http://bugs.php.net/?id=13718edit=1 -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the
[PHP-DEV] Bug #13718 Updated: form elements with same name problem
ID: 13718 User updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Bogus Bug Type: Feature/Change Request Operating System: All PHP Version: 4.0.6 New Comment: I do understand that if you were in the middle of a php script, this would be a simple reassigning of the variable. However, this is a preprocessor command, and thus should be handled a little differently. Adding a [] at the tail of a variable and having it come out as an array on the other end seems a like a trick. It has its uses I'll give you that, but if you look at my suggestion you will realize that it would be a nice feature. You guys seem to have take the time to make sure that elements with [] get properly shoved into arrays, so why not this. This is a fairly common situation in html forms. Especially if you are dynamically generating them. What this really comes down to is, are you willing to overlook the fact that something like this does sort of already exist, in favor of another form of functionality? There is one other issue. If you use the variable names that you suggest, it breaks javascript. ie: html body form name=form1 action= method=post Baseball: input type=checkbox name=interest[] value=baseball br Teams: input type=text name=teams[] size=30 onFocus=form1.interest[0].checked=1 br input type=submit value=submit /form /body /html will cause an error, because you don't define arrays in javascript this way. I realize that this seems like a bug in javascript, but actually it isn't. The html 4.01 specification clearly states that: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). Note: this does not suggest that you can add [ or ]. So, in essence you are violating the html specification. If you still do not agree that this would only improve php, I will stop bothering you. Previous Comments: [2001-10-17 23:14:48] [EMAIL PROTECTED] No, its not 'how it should work'. Image when you write the following code in php: $interests = something; $interests = new; Would you expect this ending up with $interests being an array(something, new); ? Certainly not. So, for you to have an array, like Jani said, append '[]' and you have what you want. - Markus [2001-10-17 22:19:52] [EMAIL PROTECTED] Here is an example of what I am talking about, try to imagine the interests being dynamically generated, because it is easy if you already know the names of all of the elements and the form itself: form.html: html body form action=post.html method=post Baseball: input type=checkbox name=interests value=baseballbr Teams: input type=text name=teams size=40 onFocus=interests[0].checked='1'brbr Football:input type=checkbox name=interests value=footballbr input type=submit value=Submit /form /body /html post.html: html body ?php /** * This is how it should work, interests should be an array **/ echo(interest 1: $interests[0]br\n); echo(interest 2: $interests[1]br\n); /** * Instead, the value of $interests is that of the last * value posted. **/ echo($interests); ? /body /html [2001-10-17 20:10:49] [EMAIL PROTECTED] Just name them as 'name=varname[]' (add the []'s in the end) and you'll get an array. --Jani [2001-10-17 16:47:11] [EMAIL PROTECTED] The problem exists in the way that php handles the reception of a posted form. If there is more than one element in a form with the same name and it is posted to a php page, php handles this by assuming the last element with that name is the correct value for that variable. In order to provide a proper coexistance with javascript it should treat all variables with that name as elements of an array. Edit this bug report at http://bugs.php.net/?id=13718edit=1 -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DEV] Bug #13718 Updated: form elements with same name problem
ID: 13718 Updated by: hholzgra Reported By: [EMAIL PROTECTED] Status: Bogus Bug Type: Feature/Change Request Operating System: All PHP Version: 4.0.6 New Comment: the simple problem with auto-generating arrays is: form fields without input do not generate output so if you have a form like form input type=text name=foo input type=text name=foo input type=submit /form you will get an array $foo[] with two elements in PHP if both input fields are used but a plain string variable if only one (either the first or the second) is used for the javascript naming problem form.elements['foo[]'] should work find Previous Comments: [2001-10-18 10:17:36] [EMAIL PROTECTED] I do understand that if you were in the middle of a php script, this would be a simple reassigning of the variable. However, this is a preprocessor command, and thus should be handled a little differently. Adding a [] at the tail of a variable and having it come out as an array on the other end seems a like a trick. It has its uses I'll give you that, but if you look at my suggestion you will realize that it would be a nice feature. You guys seem to have take the time to make sure that elements with [] get properly shoved into arrays, so why not this. This is a fairly common situation in html forms. Especially if you are dynamically generating them. What this really comes down to is, are you willing to overlook the fact that something like this does sort of already exist, in favor of another form of functionality? There is one other issue. If you use the variable names that you suggest, it breaks javascript. ie: html body form name=form1 action= method=post Baseball: input type=checkbox name=interest[] value=baseball br Teams: input type=text name=teams[] size=30 onFocus=form1.interest[0].checked=1 br input type=submit value=submit /form /body /html will cause an error, because you don't define arrays in javascript this way. I realize that this seems like a bug in javascript, but actually it isn't. The html 4.01 specification clearly states that: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). Note: this does not suggest that you can add [ or ]. So, in essence you are violating the html specification. If you still do not agree that this would only improve php, I will stop bothering you. [2001-10-17 23:14:48] [EMAIL PROTECTED] No, its not 'how it should work'. Image when you write the following code in php: $interests = something; $interests = new; Would you expect this ending up with $interests being an array(something, new); ? Certainly not. So, for you to have an array, like Jani said, append '[]' and you have what you want. - Markus [2001-10-17 22:19:52] [EMAIL PROTECTED] Here is an example of what I am talking about, try to imagine the interests being dynamically generated, because it is easy if you already know the names of all of the elements and the form itself: form.html: html body form action=post.html method=post Baseball: input type=checkbox name=interests value=baseballbr Teams: input type=text name=teams size=40 onFocus=interests[0].checked='1'brbr Football:input type=checkbox name=interests value=footballbr input type=submit value=Submit /form /body /html post.html: html body ?php /** * This is how it should work, interests should be an array **/ echo(interest 1: $interests[0]br\n); echo(interest 2: $interests[1]br\n); /** * Instead, the value of $interests is that of the last * value posted. **/ echo($interests); ? /body /html [2001-10-17 20:10:49] [EMAIL PROTECTED] Just name them as 'name=varname[]' (add the []'s in the end) and you'll get an array. --Jani [2001-10-17 16:47:11] [EMAIL PROTECTED] The problem exists in the way that php handles the reception of a posted form. If there is more than one element in a form with the same name and it is posted to a php page, php handles this by assuming the last element with that name is the correct value for that variable. In order to provide a proper coexistance with javascript it should treat all variables with that name as elements of an array. Edit this bug report at http://bugs.php.net/?id=13718edit=1 -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail:
[PHP-DEV] Bug #13718 Updated: form elements with same name problem
ID: 13718 User updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Bogus Bug Type: Feature/Change Request Operating System: All PHP Version: 4.0.6 New Comment: I do understand that if you were in the middle of a php script, this would be a simple reassigning of the variable. However, this is a preprocessor command, and thus should be handled a little differently. Adding a [] at the tail of a variable and having it come out as an array on the other end seems a like a trick. It has its uses I'll give you that, but if you look at my suggestion you will realize that it would be a nice feature. You guys seem to have take the time to make sure that elements with [] get properly shoved into arrays, so why not this. This is a fairly common situation in html forms. Especially if you are dynamically generating them. What this really comes down to is, are you willing to overlook the fact that something like this does sort of already exist, in favor of another form of functionality? There is one other issue. If you use the variable names that you suggest, it breaks javascript. ie: html body form name=form1 action= method=post Baseball: input type=checkbox name=interest[] value=baseball br Teams: input type=text name=teams[] size=30 onFocus=form1.interest[0].checked=1 br input type=submit value=submit /form /body /html will cause an error, because you don't define arrays in javascript this way. I realize that this seems like a bug in javascript, but actually it isn't. The html 4.01 specification clearly states that: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). Note: this does not suggest that you can add [ or ]. So, in essence you are violating the html specification. If you still do not agree that this would only improve php, I will stop bothering you. Previous Comments: [2001-10-18 10:46:31] [EMAIL PROTECTED] the simple problem with auto-generating arrays is: form fields without input do not generate output so if you have a form like form input type=text name=foo input type=text name=foo input type=submit /form you will get an array $foo[] with two elements in PHP if both input fields are used but a plain string variable if only one (either the first or the second) is used for the javascript naming problem form.elements['foo[]'] should work find [2001-10-18 10:17:36] [EMAIL PROTECTED] I do understand that if you were in the middle of a php script, this would be a simple reassigning of the variable. However, this is a preprocessor command, and thus should be handled a little differently. Adding a [] at the tail of a variable and having it come out as an array on the other end seems a like a trick. It has its uses I'll give you that, but if you look at my suggestion you will realize that it would be a nice feature. You guys seem to have take the time to make sure that elements with [] get properly shoved into arrays, so why not this. This is a fairly common situation in html forms. Especially if you are dynamically generating them. What this really comes down to is, are you willing to overlook the fact that something like this does sort of already exist, in favor of another form of functionality? There is one other issue. If you use the variable names that you suggest, it breaks javascript. ie: html body form name=form1 action= method=post Baseball: input type=checkbox name=interest[] value=baseball br Teams: input type=text name=teams[] size=30 onFocus=form1.interest[0].checked=1 br input type=submit value=submit /form /body /html will cause an error, because you don't define arrays in javascript this way. I realize that this seems like a bug in javascript, but actually it isn't. The html 4.01 specification clearly states that: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). Note: this does not suggest that you can add [ or ]. So, in essence you are violating the html specification. If you still do not agree that this would only improve php, I will stop bothering you. [2001-10-17 23:14:48] [EMAIL PROTECTED] No, its not 'how it should work'. Image when you write the following code in php: $interests = something; $interests = new; Would you expect this ending up with $interests being an array(something, new); ? Certainly not. So, for you to have an array, like Jani said, append '[]' and you have what you want. - Markus
[PHP-DEV] Bug #13718 Updated: form elements with same name problem
ID: 13718 User updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Bogus Bug Type: Feature/Change Request Operating System: All PHP Version: 4.0.6 New Comment: sorry, I refreshed the page, and it reposted. Thank you for your help, I hope that you will consider my suggestion for future releases. Previous Comments: [2001-10-18 10:53:44] [EMAIL PROTECTED] I do understand that if you were in the middle of a php script, this would be a simple reassigning of the variable. However, this is a preprocessor command, and thus should be handled a little differently. Adding a [] at the tail of a variable and having it come out as an array on the other end seems a like a trick. It has its uses I'll give you that, but if you look at my suggestion you will realize that it would be a nice feature. You guys seem to have take the time to make sure that elements with [] get properly shoved into arrays, so why not this. This is a fairly common situation in html forms. Especially if you are dynamically generating them. What this really comes down to is, are you willing to overlook the fact that something like this does sort of already exist, in favor of another form of functionality? There is one other issue. If you use the variable names that you suggest, it breaks javascript. ie: html body form name=form1 action= method=post Baseball: input type=checkbox name=interest[] value=baseball br Teams: input type=text name=teams[] size=30 onFocus=form1.interest[0].checked=1 br input type=submit value=submit /form /body /html will cause an error, because you don't define arrays in javascript this way. I realize that this seems like a bug in javascript, but actually it isn't. The html 4.01 specification clearly states that: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). Note: this does not suggest that you can add [ or ]. So, in essence you are violating the html specification. If you still do not agree that this would only improve php, I will stop bothering you. [2001-10-18 10:46:31] [EMAIL PROTECTED] the simple problem with auto-generating arrays is: form fields without input do not generate output so if you have a form like form input type=text name=foo input type=text name=foo input type=submit /form you will get an array $foo[] with two elements in PHP if both input fields are used but a plain string variable if only one (either the first or the second) is used for the javascript naming problem form.elements['foo[]'] should work find [2001-10-18 10:17:36] [EMAIL PROTECTED] I do understand that if you were in the middle of a php script, this would be a simple reassigning of the variable. However, this is a preprocessor command, and thus should be handled a little differently. Adding a [] at the tail of a variable and having it come out as an array on the other end seems a like a trick. It has its uses I'll give you that, but if you look at my suggestion you will realize that it would be a nice feature. You guys seem to have take the time to make sure that elements with [] get properly shoved into arrays, so why not this. This is a fairly common situation in html forms. Especially if you are dynamically generating them. What this really comes down to is, are you willing to overlook the fact that something like this does sort of already exist, in favor of another form of functionality? There is one other issue. If you use the variable names that you suggest, it breaks javascript. ie: html body form name=form1 action= method=post Baseball: input type=checkbox name=interest[] value=baseball br Teams: input type=text name=teams[] size=30 onFocus=form1.interest[0].checked=1 br input type=submit value=submit /form /body /html will cause an error, because you don't define arrays in javascript this way. I realize that this seems like a bug in javascript, but actually it isn't. The html 4.01 specification clearly states that: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). Note: this does not suggest that you can add [ or ]. So, in essence you are violating the html specification. If you still do not agree that this would only improve php, I will stop bothering you. [2001-10-17 23:14:48] [EMAIL PROTECTED] No, its not 'how it should work'. Image when you write the following code in php:
[PHP-DEV] Bug #13718 Updated: form elements with same name problem
ID: 13718 User updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Bogus Bug Type: Feature/Change Request Operating System: All PHP Version: 4.0.6 New Comment: wow, I just noticed that you are suggesting that php actually generate an array! I posted two example html files, that clearly show that you are wrong. PHP always treats them as a single variable, no matter how many are actually set. Previous Comments: [2001-10-18 10:54:37] [EMAIL PROTECTED] sorry, I refreshed the page, and it reposted. Thank you for your help, I hope that you will consider my suggestion for future releases. [2001-10-18 10:53:44] [EMAIL PROTECTED] I do understand that if you were in the middle of a php script, this would be a simple reassigning of the variable. However, this is a preprocessor command, and thus should be handled a little differently. Adding a [] at the tail of a variable and having it come out as an array on the other end seems a like a trick. It has its uses I'll give you that, but if you look at my suggestion you will realize that it would be a nice feature. You guys seem to have take the time to make sure that elements with [] get properly shoved into arrays, so why not this. This is a fairly common situation in html forms. Especially if you are dynamically generating them. What this really comes down to is, are you willing to overlook the fact that something like this does sort of already exist, in favor of another form of functionality? There is one other issue. If you use the variable names that you suggest, it breaks javascript. ie: html body form name=form1 action= method=post Baseball: input type=checkbox name=interest[] value=baseball br Teams: input type=text name=teams[] size=30 onFocus=form1.interest[0].checked=1 br input type=submit value=submit /form /body /html will cause an error, because you don't define arrays in javascript this way. I realize that this seems like a bug in javascript, but actually it isn't. The html 4.01 specification clearly states that: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). Note: this does not suggest that you can add [ or ]. So, in essence you are violating the html specification. If you still do not agree that this would only improve php, I will stop bothering you. [2001-10-18 10:46:31] [EMAIL PROTECTED] the simple problem with auto-generating arrays is: form fields without input do not generate output so if you have a form like form input type=text name=foo input type=text name=foo input type=submit /form you will get an array $foo[] with two elements in PHP if both input fields are used but a plain string variable if only one (either the first or the second) is used for the javascript naming problem form.elements['foo[]'] should work find [2001-10-18 10:17:36] [EMAIL PROTECTED] I do understand that if you were in the middle of a php script, this would be a simple reassigning of the variable. However, this is a preprocessor command, and thus should be handled a little differently. Adding a [] at the tail of a variable and having it come out as an array on the other end seems a like a trick. It has its uses I'll give you that, but if you look at my suggestion you will realize that it would be a nice feature. You guys seem to have take the time to make sure that elements with [] get properly shoved into arrays, so why not this. This is a fairly common situation in html forms. Especially if you are dynamically generating them. What this really comes down to is, are you willing to overlook the fact that something like this does sort of already exist, in favor of another form of functionality? There is one other issue. If you use the variable names that you suggest, it breaks javascript. ie: html body form name=form1 action= method=post Baseball: input type=checkbox name=interest[] value=baseball br Teams: input type=text name=teams[] size=30 onFocus=form1.interest[0].checked=1 br input type=submit value=submit /form /body /html will cause an error, because you don't define arrays in javascript this way. I realize that this seems like a bug in javascript, but actually it isn't. The html 4.01 specification clearly states that: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). Note: this does not suggest that you can add [ or ]. So, in
[PHP-DEV] Bug #13718 Updated: form elements with same name problem
ID: 13718 Updated by: hholzgra Reported By: [EMAIL PROTECTED] Status: Bogus Bug Type: Feature/Change Request Operating System: All PHP Version: 4.0.6 New Comment: no, i didn't ;) i just tried to describe what would happen *if* we would follow your suggestion and that it is a not so good idea after all (although we definetly should have a look at the [] syntax regarding standard conformance) Previous Comments: [2001-10-18 10:57:57] [EMAIL PROTECTED] wow, I just noticed that you are suggesting that php actually generate an array! I posted two example html files, that clearly show that you are wrong. PHP always treats them as a single variable, no matter how many are actually set. [2001-10-18 10:54:37] [EMAIL PROTECTED] sorry, I refreshed the page, and it reposted. Thank you for your help, I hope that you will consider my suggestion for future releases. [2001-10-18 10:53:44] [EMAIL PROTECTED] I do understand that if you were in the middle of a php script, this would be a simple reassigning of the variable. However, this is a preprocessor command, and thus should be handled a little differently. Adding a [] at the tail of a variable and having it come out as an array on the other end seems a like a trick. It has its uses I'll give you that, but if you look at my suggestion you will realize that it would be a nice feature. You guys seem to have take the time to make sure that elements with [] get properly shoved into arrays, so why not this. This is a fairly common situation in html forms. Especially if you are dynamically generating them. What this really comes down to is, are you willing to overlook the fact that something like this does sort of already exist, in favor of another form of functionality? There is one other issue. If you use the variable names that you suggest, it breaks javascript. ie: html body form name=form1 action= method=post Baseball: input type=checkbox name=interest[] value=baseball br Teams: input type=text name=teams[] size=30 onFocus=form1.interest[0].checked=1 br input type=submit value=submit /form /body /html will cause an error, because you don't define arrays in javascript this way. I realize that this seems like a bug in javascript, but actually it isn't. The html 4.01 specification clearly states that: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). Note: this does not suggest that you can add [ or ]. So, in essence you are violating the html specification. If you still do not agree that this would only improve php, I will stop bothering you. [2001-10-18 10:46:31] [EMAIL PROTECTED] the simple problem with auto-generating arrays is: form fields without input do not generate output so if you have a form like form input type=text name=foo input type=text name=foo input type=submit /form you will get an array $foo[] with two elements in PHP if both input fields are used but a plain string variable if only one (either the first or the second) is used for the javascript naming problem form.elements['foo[]'] should work find [2001-10-18 10:17:36] [EMAIL PROTECTED] I do understand that if you were in the middle of a php script, this would be a simple reassigning of the variable. However, this is a preprocessor command, and thus should be handled a little differently. Adding a [] at the tail of a variable and having it come out as an array on the other end seems a like a trick. It has its uses I'll give you that, but if you look at my suggestion you will realize that it would be a nice feature. You guys seem to have take the time to make sure that elements with [] get properly shoved into arrays, so why not this. This is a fairly common situation in html forms. Especially if you are dynamically generating them. What this really comes down to is, are you willing to overlook the fact that something like this does sort of already exist, in favor of another form of functionality? There is one other issue. If you use the variable names that you suggest, it breaks javascript. ie: html body form name=form1 action= method=post Baseball: input type=checkbox name=interest[] value=baseball br Teams: input type=text name=teams[] size=30 onFocus=form1.interest[0].checked=1 br input type=submit value=submit /form /body /html will cause an error, because you don't define arrays in javascript this way. I realize that this seems
[PHP-DEV] Bug #13718 Updated: form elements with same name problem
ID: 13718 User updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Bogus Bug Type: Feature/Change Request Operating System: All PHP Version: 4.0.6 New Comment: Oh, I'm sorry, I missunderstood you. I understand what you are getting at, ambiguity can be a problem. I guess I'll just deal with using the suggestion of indexing on a string in javascript. Thank you for all your help. Previous Comments: [2001-10-18 11:33:49] [EMAIL PROTECTED] no, i didn't ;) i just tried to describe what would happen *if* we would follow your suggestion and that it is a not so good idea after all (although we definetly should have a look at the [] syntax regarding standard conformance) [2001-10-18 10:57:57] [EMAIL PROTECTED] wow, I just noticed that you are suggesting that php actually generate an array! I posted two example html files, that clearly show that you are wrong. PHP always treats them as a single variable, no matter how many are actually set. [2001-10-18 10:54:37] [EMAIL PROTECTED] sorry, I refreshed the page, and it reposted. Thank you for your help, I hope that you will consider my suggestion for future releases. [2001-10-18 10:53:44] [EMAIL PROTECTED] I do understand that if you were in the middle of a php script, this would be a simple reassigning of the variable. However, this is a preprocessor command, and thus should be handled a little differently. Adding a [] at the tail of a variable and having it come out as an array on the other end seems a like a trick. It has its uses I'll give you that, but if you look at my suggestion you will realize that it would be a nice feature. You guys seem to have take the time to make sure that elements with [] get properly shoved into arrays, so why not this. This is a fairly common situation in html forms. Especially if you are dynamically generating them. What this really comes down to is, are you willing to overlook the fact that something like this does sort of already exist, in favor of another form of functionality? There is one other issue. If you use the variable names that you suggest, it breaks javascript. ie: html body form name=form1 action= method=post Baseball: input type=checkbox name=interest[] value=baseball br Teams: input type=text name=teams[] size=30 onFocus=form1.interest[0].checked=1 br input type=submit value=submit /form /body /html will cause an error, because you don't define arrays in javascript this way. I realize that this seems like a bug in javascript, but actually it isn't. The html 4.01 specification clearly states that: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). Note: this does not suggest that you can add [ or ]. So, in essence you are violating the html specification. If you still do not agree that this would only improve php, I will stop bothering you. [2001-10-18 10:46:31] [EMAIL PROTECTED] the simple problem with auto-generating arrays is: form fields without input do not generate output so if you have a form like form input type=text name=foo input type=text name=foo input type=submit /form you will get an array $foo[] with two elements in PHP if both input fields are used but a plain string variable if only one (either the first or the second) is used for the javascript naming problem form.elements['foo[]'] should work find The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/?id=13718 Edit this bug report at http://bugs.php.net/?id=13718edit=1 -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DEV] Bug #13718 Updated: form elements with same name problem
ID: 13718 Updated by: mfischer Reported By: [EMAIL PROTECTED] Status: Bogus Bug Type: Feature/Change Request Operating System: All PHP Version: 4.0.6 New Comment: No, its not 'how it should work'. Image when you write the following code in php: $interests = something; $interests = new; Would you expect this ending up with $interests being an array(something, new); ? Certainly not. So, for you to have an array, like Jani said, append '[]' and you have what you want. - Markus Previous Comments: [2001-10-17 22:19:52] [EMAIL PROTECTED] Here is an example of what I am talking about, try to imagine the interests being dynamically generated, because it is easy if you already know the names of all of the elements and the form itself: form.html: html body form action=post.html method=post Baseball: input type=checkbox name=interests value=baseballbr Teams: input type=text name=teams size=40 onFocus=interests[0].checked='1'brbr Football:input type=checkbox name=interests value=footballbr input type=submit value=Submit /form /body /html post.html: html body ?php /** * This is how it should work, interests should be an array **/ echo(interest 1: $interests[0]br\n); echo(interest 2: $interests[1]br\n); /** * Instead, the value of $interests is that of the last * value posted. **/ echo($interests); ? /body /html [2001-10-17 20:10:49] [EMAIL PROTECTED] Just name them as 'name=varname[]' (add the []'s in the end) and you'll get an array. --Jani [2001-10-17 16:47:11] [EMAIL PROTECTED] The problem exists in the way that php handles the reception of a posted form. If there is more than one element in a form with the same name and it is posted to a php page, php handles this by assuming the last element with that name is the correct value for that variable. In order to provide a proper coexistance with javascript it should treat all variables with that name as elements of an array. Edit this bug report at http://bugs.php.net/?id=13718edit=1 -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]