Comment On A New Type of Formation

Andreas had a pretty good idea of what he was getting in to. The job posting subtly included the duty of "helping to straighten up the software environment." The technical screening consisted of three questions: what is HTML, what is PHP, and what is SQL. And the interviewer subtly mentioned that the previous programmer was a "great guy, but had a few quirks." Yes, Andreas knew he was walking into a nicely presented system that's more messed-up than a building flattened with a 2-ton bomb ... shortly after being flattened with a 5-ton bomb. But that's OK; it would be a challenge. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: A New Type of Formation

2006-08-30 13:46 • by kipthegreat
A selecter, huh?  So what's the selectest!

Re: A New Type of Formation

2006-08-30 13:49 • by AndrewVos

Dare I say "Javascript has the best WTF's" ?

Re: A New Type of Formation

2006-08-30 13:52 • by rmr
Rofl, so if I'm reading this right, if he has 10, 210, 310 and 410 checked, and he unchecks 10, he ends up with 234 checked?  Good thing the ids are so high!

What does the g in the eval line do?

Re: A New Type of Formation

2006-08-30 13:54 • by kipthegreat
88963 in reply to 88962
rmr:
Rofl, so if I'm reading this right, if he has 10, 210, 310 and 410 checked, and he unchecks 10, he ends up with 234 checked?  Good thing the ids are so high!

What does the g in the eval line do?


g = global replace.  otherwise, only the first "10," would be replaced.

Re: A New Type of Formation

2006-08-30 13:55 • by sammybaby
Alex Papadimoulis:

The root folder housed over 400 of
files, most belonging to completely different modules. Actually, there
was one subfolder: it contained all the code and pages for the previous
programmer's World of Warcraft clan website.





I was originally going to make a joke about the javascript as an effort to make sure that the checked checkboxes were, like, really checked, so they didn't have a situation like the 2000 Florida vote with the hanging chads and whatnot.

Then I re-read the bit about the WoW site and though, aw, hell, that's funnier than anything I could come up with anyway.

Re: A New Type of Formation

2006-08-30 13:55 • by kipthegreat
I guess he is unfamiliar with $_POST in PHP?

Re: A New Type of Formation

2006-08-30 13:57 • by trippyz
Is it safe to remove my welding goggles yet?

Re: A New Type of Formation

2006-08-30 13:59 • by CodeRage
88967 in reply to 88963
kipthegreat:
rmr:
Rofl, so if I'm reading this right, if he has 10, 210, 310 and 410 checked, and he unchecks 10, he ends up with 234 checked?  Good thing the ids are so high!
What does the g in the eval line do?

g = global replace.  otherwise, only the first "10," would be replaced.

Yeah, this is awesome!  For fun, paste this code on your machine at work, add some checkboxes where the ids are substrings of the other ids, and change the hidden input to text so you can see it as it messes up the list of ids.

And all this for something the browser does for you when it posts the form, had the developer been 1337 enough to give all the checkboxes the same name, with each value being the id.

Re: A New Type of Formation

2006-08-30 14:05 • by Digitalbath
88969 in reply to 88967

CodeRage:
kipthegreat:
rmr:
Rofl, so if I'm reading this right, if he has 10, 210, 310 and 410 checked, and he unchecks 10, he ends up with 234 checked?  Good thing the ids are so high!
What does the g in the eval line do?

g = global replace.  otherwise, only the first "10," would be replaced.

Yeah, this is awesome!  For fun, paste this code on your machine at work, add some checkboxes where the ids are substrings of the other ids, and change the hidden input to text so you can see it as it messes up the list of ids.

And all this for something the browser does for you when it posts the form, had the developer been 1337 enough to give all the checkboxes the same name, with each value being the id.


Yes, but then he wouldn't be able to handle "input" from mutliple pages in his insert.php file.  At least that's what i'm guessing he did.  Based on the prefix of fthe checkboxes, he probably had some huge switch statement in that file that knew what values were selected on what page.  It's the new duct tape...insert.php!


Or, am I completely off here?

Re: A New Type of Formation

2006-08-30 14:08 • by Digitalbath

I did not interpret "in trouble" as getting fired.  If he did not get fired for trying to sell proprietary software on eBay...that might be a bigger WTF than his whole system.

Re: A New Type of Formation

2006-08-30 14:18 • by merreborn
88973 in reply to 88965
kipthegreat:
I guess he is unfamiliar with $_POST in PHP?


Unnecessary:  assuming the point of this was to convert a POST to a GET, all he had to do was change
<form method="POST"> to <form method="GET">


I'm pretty sure GET is the default anyway.  I can't for the life of me figure out why the fuck he thought he needed the javascript.

Re: A New Type of Formation

2006-08-30 14:18 • by rocksanddirt
88974 in reply to 88960
As javascript in itself was designed with good intentions, there are many facets about the language and the varying browser capabilities that can eventually drive your code into WTFland for the next developer...

Re: A New Type of Formation

2006-08-30 14:20 • by Gnictigezoink
Holy crap.

Err. Unholy Crap.

'Nother instance of "TTWTASO" design pattern (trash the whole thing and start over)

Re: A New Type of Formation

2006-08-30 14:24 • by wyz

The story around it is differenct, or this could be jscript from the place I at now as an on-site contractor!


This job was presumably modifying about 8 web pages. But it turned out the pages had server-side jscript rendering client-side jscript with this kind of garbage code, plus putting values in and out of XML strings by someone not knowing how to use XML. That just my rant on the web pages! 


In fact, some samples were submitted to WTF, but Alex only had sympathy for me. Don't recall if it was duplicate stuff or wasn't humorous enough to use. But it has kept some of my sanity reading WTF and seeing I'm not the only one dealing with bad coding and applications.


(Someone had to ask real nice to get me to come here and rescue a project that was sinking. The first guy placed here couldn't figure out what to do.)


 

Re: A New Type of Formation

2006-08-30 14:36 • by Aximilation
Oh yes, forget the whole $_REQUEST.....very nice. I've always wanted to create the new and improved version of that. Lol...
It's almost as bad as the new link tag seen elsewhere on this site last week...
<a onclick="location='http://www.aximilation.com'; return false;" href="#">The <em>new</em> link!</a>
(I'm making a t-shirt!)

Re: A New Type of Formation

2006-08-30 14:41 • by obediah
88979 in reply to 88969
Digitalbath:

Yes, but then he wouldn't be able to handle "input" from mutliple pages in his insert.php file.  At least that's what i'm guessing he did.  Based on the prefix of fthe checkboxes, he probably had some huge switch statement in that file that knew what values were selected on what page.  It's the new duct tape...insert.php!


Or, am I completely off here?



This is what happens when someone hears the term 'MVC' in passing and then reads a random blog post. Because nothing controls like a single file with 20,000 if statements.

Re: A New Type of Formation

2006-08-30 14:41 • by Anon
Alex Papadimoulis:

<script type="text/javascript"> <!--

function onCheck(id)
{
  checkedValues = document.selecter.checkedValues;
  checkedBox = document.selecter["check_"+id];
 
  if (!checkedBox.checked)
    checkedValues.value =
           eval("checkedValues.value.replace(/" +id + ',' + "/g,'')");
  else
    checkedValues.value+=(id+',');
}
     
function submit()
{
  document.location.href = 'insert.php?chosen=' +
     document.selecter.checkedValues.value;
  return false;
}


//--
></script>

<form id="selecter" name="selecter">
  <input type="hidden" id="checkedValues" name="checkedValues" />
  <input class="button" type="button" value="Submit" onclick="submit()" />

  <input id="check_4273844" onclick="onCheck('4273844')" type="checkbox"
         name="check_4273844" value="ON"
/>
  ...
  <input id="check_4273843" onclick="onCheck('4273843')" type="checkbox"
         name="check_4273843" value="ON"
/>
  ...
  <input id="check_4273842" onclick="onCheck('4273842')" type="checkbox"
         name="check_4273842" value="ON"
/>
  ...
</form>


Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.

Re: A New Type of Formation

2006-08-30 14:42 • by biziclop
88981 in reply to 88978
Aximilation:
Oh yes, forget the whole $_REQUEST.....very nice. I've always wanted to create the new and improved version of that. Lol...
It's almost as bad as the new link tag seen elsewhere on this site last week...
<a onclick="location='http://www.aximilation.com'; return false;" href="#">The <em>new</em> link!</a>
(I'm making a t-shirt!)


Resistance is futile.

Re: A New Type of Formation

2006-08-30 14:43 • by foo
It's so beautiful! I'm crying... no wait... that's blood... FROM MY EYES!

give him a break

2006-08-30 14:43 • by maht
the guy *almost* invented Ajax

Re: A New Type of Formation

2006-08-30 14:44 • by Anon
88985 in reply to 88980
Anonymous:

Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.



Wait, I was wrong.  That doesn't say "checked" it says "on".  This was so stupid I mentally filled in what he should have been doing instead of what he actually did.


 


Wow, that's a lot of work to be so wrong.

Re: A New Type of Formation

2006-08-30 14:50 • by Tomer Chachamu
88987 in reply to 88980
Actually, 'value="ON"' does not mean the box is checked. It just means that if it *is* checked, the value to send to the server is "ON".

Considering that that value presumbly isn't used (since checkedValues.value holds the list of checked checkboxes) you have to wonder why it's there. Just another copy-paste job, I suppose...

Re: A New Type of Formation

2006-08-30 14:52 • by snoofle
88989 in reply to 88985
Anonymous:
Anonymous:

Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.



Wait, I was wrong.  That doesn't say "checked" it says "on".  This was so stupid I mentally filled in what he should have been doing instead of what he actually did.


Wow, that's a lot of work to be so wrong.



Web-neophyte here - I thought check boxes could only be true/false, or possibly [un]checked. "On" ???

Re: A New Type of Formation

2006-08-30 14:53 • by ole gustie
88990 in reply to 88980
Anonymous:
Alex Papadimoulis:

<script type="text/javascript"> <!--

function onCheck(id)
{
  checkedValues = document.selecter.checkedValues;
  checkedBox = document.selecter["check_"+id];
 
  if (!checkedBox.checked)
    checkedValues.value =
           eval("checkedValues.value.replace(/" +id + ',' + "/g,'')");
  else
    checkedValues.value+=(id+',');
}
     
function submit()
{
  document.location.href = 'insert.php?chosen=' +
     document.selecter.checkedValues.value;
  return false;
}


//--
></script>

<form id="selecter" name="selecter">
  <input type="hidden" id="checkedValues" name="checkedValues" />
  <input class="button" type="button" value="Submit" onclick="submit()" />

  <input id="check_4273844" onclick="onCheck('4273844')" type="checkbox"
         name="check_4273844" value="ON"
/>
  ...
  <input id="check_4273843" onclick="onCheck('4273843')" type="checkbox"
         name="check_4273843" value="ON"
/>
  ...
  <input id="check_4273842" onclick="onCheck('4273842')" type="checkbox"
         name="check_4273842" value="ON"
/>
  ...
</form>


Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.



 


Huh?  value="on" doesn't autocheck a box on the page load.  I think you are thinking of


 <input id="check_4273842" onclick="onCheck('4273842')" type="checkbox"
         name="check_4273842" checked
/>

Or am I missing something (trust me, its happened before)?

Re: A New Type of Formation

2006-08-30 14:59 • by ole gustie
88993 in reply to 88989
snoofle:
Anonymous:
Anonymous:

Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.



Wait, I was wrong.  That doesn't say "checked" it says "on".  This was so stupid I mentally filled in what he should have been doing instead of what he actually did.


Wow, that's a lot of work to be so wrong.



Web-neophyte here - I thought check boxes could only be true/false, or possibly [un]checked. "On" ???



Check boxes pass whatever is in the "value" attribute to the form action page when they are checked.  If they are not checked, they pass nothing.  If more than one checkboxes have the same name,  all that are checked are passed in a single variable as a comma seperated list.  Basically, the guy/gal wrote a bunch of crap code to do what standard html forms already do.

Re: A New Type of Formation

2006-08-30 15:02 • by Tukaro
It burns.

It burns. So. Much.

Please. Someone make it stop!

Re: A New Type of Formation

2006-08-30 15:10 • by snoofle
88996 in reply to 88993
ole gustie:
snoofle:
Anonymous:
Anonymous:

Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.



Wait, I was wrong.  That doesn't say "checked" it says "on".  This was so stupid I mentally filled in what he should have been doing instead of what he actually did.


Wow, that's a lot of work to be so wrong.



Web-neophyte here - I thought check boxes could only be true/false, or possibly [un]checked. "On" ???



Check boxes pass whatever is in the "value" attribute to the form action page when they are checked.  If they are not checked, they pass nothing.  If more than one checkboxes have the same name,  all that are checked are passed in a single variable as a comma seperated list.  Basically, the guy/gal wrote a bunch of crap code to do what standard html forms already do.



Thanks - I know just enough about all-things-web to realize how little I know about all-things-web (I tend to stay on the server-side of things - where I know what I'm doing).

Re: A New Type of Formation

2006-08-30 15:24 • by Marcos
88997 in reply to 88993
> If more than one checkboxes have the same name,  all that are
checked are passed in a
> single variable as a comma seperated list. 

Not true. If more than one checkbox with the same name is checked, then each value is included as a separate name=value pair in the HTTP request.  For instance, if the form has a method of GET and the browser uses the old ampersand separator instead of the newfangled semicolon, a form with three checkboxes named "box" checked might take you to this URL:

http://foo.com/mySpiffyPage.php?box=yup&box=nope&box=is_too

How that is presented on the server side depends on the language and API being used.  I've seen ASP's that seem to indicate that VB in an ASP will give you a comma-separated string, though I don't know how you then deal with commas in an individual value.   Most APIs provide a means of getting the list of values as an array;  Perl's CGI::param automatically returns an array in list context if there's more than one value, for instance.  PHP apparently discards all but the last value unless the name ends with [], which isn't even legal HTML.  Of course, there are various add-on solutions to this problem that all involve manually reprocessing the form input...




Re: A New Type of Formation

2006-08-30 15:31 • by Otto
88998 in reply to 88993
Anonymous:
Check boxes pass whatever is in the "value"
attribute to the form action page when they are checked.  If they are
not checked, they pass nothing.  If more than one checkboxes have the
same name,  all that are checked are passed in a single variable as a
comma seperated list.  Basically, the guy/gal wrote a bunch of crap
code to do what standard html forms already do.




I knew this didn't sound right, so I tried it. What I got in the URL for a GET request looked like this:

key=test&key=test2



Now, your language/CGI parser library may change this into something
nicer like a comma separated list for you, but the data is actually
sent as multiple key=value pairs, only using the same keys.



Re: A New Type of Formation

2006-08-30 15:36 • by Romeo
89000 in reply to 88990
Anonymous:
Anonymous:
Alex Papadimoulis:

<script type="text/javascript"> <!--

function onCheck(id)
{
  checkedValues = document.selecter.checkedValues;
  checkedBox = document.selecter["check_"+id];
 
  if (!checkedBox.checked)
    checkedValues.value =
           eval("checkedValues.value.replace(/" +id + ',' + "/g,'')");
  else
    checkedValues.value+=(id+',');
}
     
function submit()
{
  document.location.href = 'insert.php?chosen=' +
     document.selecter.checkedValues.value;
  return false;
}


//--
></script>

<form id="selecter" name="selecter">
  <input type="hidden" id="checkedValues" name="checkedValues" />
  <input class="button" type="button" value="Submit" onclick="submit()" />

  <input id="check_4273844" onclick="onCheck('4273844')" type="checkbox"
         name="check_4273844" value="ON"
/>
  ...
  <input id="check_4273843" onclick="onCheck('4273843')" type="checkbox"
         name="check_4273843" value="ON"
/>
  ...
  <input id="check_4273842" onclick="onCheck('4273842')" type="checkbox"
         name="check_4273842" value="ON"
/>
  ...
</form>


Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.



 


Huh?  value="on" doesn't autocheck a box on the page load.  I think you are thinking of


 <input id="check_4273842" onclick="onCheck('4273842')" type="checkbox"
         name="check_4273842" checked
/>

Or am I missing something (trust me, its happened before)?



Sure you're not missing anything.

WTF on WTF

Re: A New Type of Formation

2006-08-30 15:40 • by ole gustie
89002 in reply to 88998

Thanks for the correction.  I guess you learn something new everyday.  I am mainly a client app programmer, so my experience is limited to a couple ASP and coldFusion (gross, I know) hobby sites I help my fellow geeks maintain.


And the answer to your question is that you learn to keep commas out of the indivdual checkbox values pretty quickly.

Re: A New Type of Formation

2006-08-30 15:45 • by trippyz
89003 in reply to 88987
>Actually, 'value="ON"' does not mean the box is checked. It just means that if it *is* checked, the value to send to the server is "ON".

My eyes are checkered, does that mean they are on?

Re: A New Type of Formation

2006-08-30 15:56 • by qbolec
Alex Papadimoulis:

      

function submit()
{
document.location.href = 'insert.php?chosen=' +
document.selecter.checkedValues.value;
return false;
}



I'm afraid of:

      

//insert.php
mysql_query("INSERT INTO MyOrder (ID) VALUES ($chosen)");


Re: A New Type of Formation

2006-08-30 16:09 • by Volmarias
89008 in reply to 89006
Good god, I actually tore at my skin with my fingernails when I read this.

Re: A New Type of Formation

2006-08-30 16:17 • by cedric
I could imagine why one would want to reconstruct the querystring and bypass the normal form submission. For instance if there is another javascript function attached to the onSubmit event and for some reason you don't want it to run when you click on that button.

The eval on the string replace is a bit weird. It looks like a workaround for someone who don't know about the RegExp() object (you can't use variables with the // notation). But you don't really need a regular expression in the first place.

Re: A New Type of Formation

2006-08-30 16:18 • by CodeRage
89012 in reply to 89006
Just to clarify from the PHP people... Is there some reason you wouldn't just use the following ... like I'd do with a Java/Servlet back-end?  Is there some reason building a comma separated string would make things easier in PHP?  I would just use the HttpServletRequest to give me an array of the "chosen" parameters...

<form id="selecter" name="selecter" action="insert.php">
  <input class="button" type="submit" value="Submit" />
  ...
  <input type="checkbox" name="chosen" value="4273844" />
  ...
  <input type="checkbox" name="chosen" value="4273843" />
  ...
  <input type="checkbox" name="chosen" value="4273842" />
  ...
</form>

Re: A New Type of Formation

2006-08-30 16:19 • by UTU
89013 in reply to 88997
Anonymous:
PHP apparently discards all but the last value unless the name ends with [], which isn't even legal HTML.


Umm.. how so? If my memory serves me correctly, "name"-attribute of input-elements is of type CDATA, which means "a sequence of characters from
the document character set"... so ending a name with [] is just about as allowed in HTML as ... well, just about anything :)

Re: A New Type of Formation

2006-08-30 16:21 • by smbell
89014 in reply to 89008
Volmarias:
Good god, I actually tore at my skin with my fingernails when I read this.



Oooh, I need to get a webcam at my desk too.

Re: A New Type of Formation

2006-08-30 16:21 • by Kelsey
89015 in reply to 88989
Young Padewan - checkboxes have three states - true, false, and FileNotFound.
"On" is indeed the real WTF here.

Re: A New Type of Formation

2006-08-30 16:23 • by WWWWolf
89016 in reply to 89006
qbolec:
Alex Papadimoulis:

      

function submit()
{
document.location.href = 'insert.php?chosen=' +
document.selecter.checkedValues.value;
return false;
}



I'm afraid of:

      

//insert.php
mysql_query("INSERT INTO MyOrder (ID) VALUES ($chosen)");


Yeah, let's combine a great big web app design flaw with a PHP-specific design flaw: SQL injection annnnnd register_globals... =)

Re: A New Type of Formation

2006-08-30 16:26 • by Licky Lindsay
89018 in reply to 89002
ole gustie:
I am mainly a client app programmer, so my
experience is limited to a couple ASP and coldFusion (gross, I know)
hobby sites I help my fellow geeks maintain.




You would be very surprised (well, no, you wouldn't really) how many
people who work with one of those languages every day, and are paid to
do so, actually think that the browser sends a comma-separated list.



captcha: whiskey

Re: A New Type of Formation

2006-08-30 16:26 • by UTU
89019 in reply to 89012
CodeRage:
Just to clarify from the PHP people... Is there some reason you wouldn't just use the following ... like I'd do with a Java/Servlet back-end?  Is there some reason building a comma separated string would make things easier in PHP?  I would just use the HttpServletRequest to give me an array of the "chosen" parameters...

<form id="selecter" name="selecter" action="insert.php">
  <input class="button" type="submit" value="Submit" />
  ...
  <input type="checkbox" name="chosen" value="4273844" />
  ...
  <input type="checkbox" name="chosen" value="4273843" />
  ...
  <input type="checkbox" name="chosen" value="4273842" />
  ...
</form>



Yes, there is a reason. See http://fi2.php.net/manual/en/faq.html.php#faq.html.arrays for explanation. However, if your example were like 'name="chosen[]"', there would be no problem; we'd have array $_GET["chosen"] to use :)

Re: A New Type of Formation

2006-08-30 16:32 • by Licky Lindsay
89022 in reply to 89013
Anonymous:
Anonymous:
PHP apparently discards
all but the last value unless the name ends with [], which isn't even
legal HTML.


Umm.. how so? If my memory serves me
correctly, "name"-attribute of input-elements is of type CDATA, which
means "a sequence of characters from
the document character set"... so ending a name with [] is just about
as allowed in HTML as ... well, just about anything :)




PHP isn't the only "framework" that uses that kind of thing either. Struts, for instance, uses the hell out of it.



Captcha: error

Re: A New Type of Formation

2006-08-30 16:35 • by Ann Coulter
89023 in reply to 88990
Anonymous:
Anonymous:
Alex Papadimoulis:

<script type="text/javascript"> <!--

function onCheck(id)
{
  checkedValues = document.selecter.checkedValues;
  checkedBox = document.selecter["check_"+id];
 
  if (!checkedBox.checked)
    checkedValues.value =
           eval("checkedValues.value.replace(/" +id + ',' + "/g,'')");
  else
    checkedValues.value+=(id+',');
}
     
function submit()
{
  document.location.href = 'insert.php?chosen=' +
     document.selecter.checkedValues.value;
  return false;
}


//--
></script>

<form id="selecter" name="selecter">
  <input type="hidden" id="checkedValues" name="checkedValues" />
  <input class="button" type="button" value="Submit" onclick="submit()" />

  <input id="check_4273844" onclick="onCheck('4273844')" type="checkbox"
         name="check_4273844" value="ON"
/>
  ...
  <input id="check_4273843" onclick="onCheck('4273843')" type="checkbox"
         name="check_4273843" value="ON"
/>
  ...
  <input id="check_4273842" onclick="onCheck('4273842')" type="checkbox"
         name="check_4273842" value="ON"
/>
  ...
</form>


Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.



 


Huh?  value="on" doesn't autocheck a box on the page load.  I think you are thinking of


 <input id="check_4273842" onclick="onCheck('4273842')" type="checkbox"
         name="check_4273842" checked
/>

Or am I missing something (trust me, its happened before)?



Well, if you're going to use xhtml you should make it

<input id="check_4273842" onclick="onCheck('4273842')" type="checkbox"
         name="check_4273842" checked
="checked"/>

Re: A New Type of Formation

2006-08-30 16:36 • by WHO WANTS TO KNOW?
89024 in reply to 89019

Actually, PHP even has a design flaw that makes this CHILDS PLAY!  Then again, the new PROPER way isn't much harder.  PHP was built from the ground up to work with this stuff.


Steve

Re: A New Type of Formation

2006-08-30 16:38 • by ammoQ
89025 in reply to 89019
Anonymous:

Yes, there is a reason. See http://fi2.php.net/manual/en/faq.html.php#faq.html.arrays for explanation. However, if your example were like 'name="chosen[]"', there would be no problem; we'd have array $_GET["chosen"] to use :)


Hard to believe. How can a programming language especially made for web programming require such client-visible workarounds to accomplish such basic tasks? Even Oracle's Web toolkit (web programming in PL/SQL, introduced around '99) does it better.

Re: A New Type of Formation

2006-08-30 16:40 • by ammoQ
89026 in reply to 89022
Anonymous:


PHP isn't the only "framework" that uses that kind of thing either. Struts, for instance, uses the hell out of it.

Maybe, but struts has a higher level of abstraction.

Re: A New Type of Formation

2006-08-30 16:51 • by Rich
89028 in reply to 89013
PHP will only accept arrays of inputs if the input is named with a [] suffix. This is a pet peeve of mine, I feel that a proper server side web scripting language *should* be able to handle whatever form data is sent at it sanely.

If I remember ASP correctly (it's been a while), if you read the input directly, you get a comma separated list but you can also read the input as an array [Don't remember how but it's fairly simple]. I think the comma separated list is an awful holdover from htx/idc of the original IIS (Makes me feel queasy just thinking about it).

Rich

Re: A New Type of Formation

2006-08-30 16:52 • by savar
89030 in reply to 89025
ammoQ:


Hard to believe. How can a programming language especially made for web programming require such client-visible workarounds to accomplish such basic tasks? Even Oracle's Web toolkit (web programming in PL/SQL, introduced around '99) does it better.


It's not a work-around, it's just how things are done. PHP isn't an amazingly clever language, but what's wrong with using [] to return an array? It's no more client-visible than using the same name without [] for each element.

Re: A New Type of Formation

2006-08-30 16:58 • by NZ'er
89033 in reply to 89019
Anonymous:
CodeRage:
Just to clarify from the PHP people... Is there some reason you wouldn't just use the following ... like I'd do with a Java/Servlet back-end?  Is there some reason building a comma separated string would make things easier in PHP?  I would just use the HttpServletRequest to give me an array of the "chosen" parameters...

<form id="selecter" name="selecter" action="insert.php">
  <input class="button" type="submit" value="Submit" />
  ...
  <input type="checkbox" name="chosen" value="4273844" />
  ...
  <input type="checkbox" name="chosen" value="4273843" />
  ...
  <input type="checkbox" name="chosen" value="4273842" />
  ...
</form>



Yes, there is a reason. See http://fi2.php.net/manual/en/faq.html.php#faq.html.arrays for explanation. However, if your example were like 'name="chosen[]"', there would be no problem; we'd have array $_GET["chosen"] to use :)


Cheers for this!  I am relitivly new to PHP programming and was trying to do somthing similar (trying to get PHP to accept an array of inputs, not the horrible javascript thing) and ran out of energy to Google it and find out. So this just saved me some time.  I have done similar things in perl and PL/SQL and both seem simpler to me but I guess it is just a quirk of the language.

« PrevPage 1 | Page 2 | Page 3Next »

Add Comment