close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Help with some code, please

Thread began 5/16/2012 1:33 pm by msummers194171 | Last modified 5/25/2012 10:30 am by msummers194171 | 2271 views | 11 replies

msummers194171

Jason - under the general subject of 'help with some code', can you please explain to me this line of code? It's taken from a radio button group created with DB:

if (array_search("1", ((isset($_GET["invalid"]) && ValidatedField("projectsupdate","display"))?ValidatedField("projectsupdate","display"):array())) !== false

My interpretation of this is the following - just tell me if I am correct.

When a field fails validation, the form needs to know whether to display the data in the database or the newly submitted data as the page refreshes and to do that the form submits to itself with a url variable of "invalid". So that line is testing whether it's the current field that failed validation or not (in this case that field is named 'display'). If it did fail validation, then the database data is shown, and if it did not fail validation then the (valid) submitted data is shown. I think I have that right....

What puzzles me is that the false part of the ternary operator is just an empty array. Why is that?

So, breaking it down:

isset($_GET['invalid']) - this is true when there is a field in the posted data that fails validation.

ValidatedField("projectsupdate","display") - I'm not exactly sure what this does, but it's always null for this 'display' field.

in this case, these two tests both fail, meaning that the ternary isset($_GET["invalid"]) && ValidatedField("projectsupdate","display"))?ValidatedField("projectsupdate","display"):array() will always return (for this particular field) the "false" result, i.e., array(). But that array is completely empty!

Since the array is empty, the test array_search("1",array()) will always fail, and so 'checked="checked"' will never get written. And this is in fact the case - that radio group is not populated when the update page loads.

My conclusion is that an empty array at that point is an error. I don't know whether it's my error (although I haven't hacked this part of the code at all) or DB's error.

Sorry this is so long-winded, but it will sure help me understand the code to get your thoughts....

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...