Restructuring HTML output from embedded record lists
Still working on the implementation of "fields" which are actually embedded record lists based on relational db tables. I've now added some additional properties through which record lists, and their child records, can tell when they are embedded in a "parent" object, and write themselves out accordingly; their New, Edit, Delete and Save buttons now call alternative JavaScript functions, which means I'll be able to stash those changes and submit them as a block along with changes to the main db record. There are still some issues with regard to the unique suffixes; I'm not quite sure I'm getting the right combination of parent suffix and (unique) child suffix which will allow my expanding embedded form elements to be well-formed, valid and distinct.
While working on the problem of validating "generated source" (pages constructed dynamically through AJAX calls), I discovered that the source code of my pages was rendered as if it were HTML 4, with self-closing tags losing their closure slash; this made it impossible to validate the dynamic source. It turns out that if you serve a page as text/html, Firefox renders the underlying source in this manner. Sending an XHTML header solved that problem, but then IE8 would not render the page at all, so I've included this little block of code:
<?php
//Send an XHTML header if the browser isn't IE.
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
if(strpos($user_agent, 'MSIE') === FALSE) {
header('Content-type: application/xhtml+xml; charset=utf-8');
}
?>
Very sad that in 2009 I'm still doing browser sniffing, but at least there's only IE to worry about. Everything else works fine. Actually, IE still fails to handle dynamic modification of elements that were themselves added to the DOM through AJAX, so it looks like it's useless for this project, but so what.