[thelist] stoopid PHP form problem

Stephen Rider evolt_org at striderweb.com
Tue Oct 23 15:09:06 CDT 2007


I've been beating my head against this for a long time now.  I  
suspect it's some stupidly simply thing I'm missing, and thought some  
extra eyes might flush it out quickly.

I have a form (generated by PHP) that calls the same page for  
processing.  At the top of the page is a bit of code that checks for  
POST and does its thing if there is POST data.

The generated HTML for the form is thus:
=====
<form action="dunce.php" method="post">
<fieldset>
	<h2>Dunce Cap</h2>
	<table>
		<tr>
			<th>Tag Name</th><th>Image File</th><th>Title (optional)</th></tr>
		<tr>
			<td><input type="text" name="dunce_options[commtags][0][name]"  
value="dunce" /></td>
			<td><input type="text" name="dunce_options[commtags][0][image]"  
value="dunce.jpg" /></td>
			<td><input type="text" name="dunce_options[commtags][0][title]"  
value="Dunce!" /></td>
			</tr>
		<tr>
			<td><input type="text" name="dunce_options[commtags][1][name]"  
value="" /></td>
			<td><input type="text" name="dunce_options[commtags][1][image]"  
value="" /></td>
			<td><input type="text" name="dunce_options[commtags][1][title]"  
value="" /></td>
		</tr>
	</table>
</fieldset>
<div class="submit">
	<input type="submit" name="dunce_options_submit" value="Update  
Options &raquo;" /></div>
</form>
=====

The PHP that handles the form is this:
=====
<?php
if ($_POST['dunce_options_submit']) {
	$tags = array();
	for ($i = 0; $i < count($dunce_options['commtags']); $i++) {
		$tag = $dunce_options['commtags'][$i];
		if (!empty($tag['name']) && !empty($tag['image'])) {
			$tag['name'] = htmlentities($tag['name']);
			$tag['image'] = htmlentities($tag['image']);
			$tag['title'] = htmlentities($tag['title']);
			$tags[] = $tag;
		}
	}
	$dunce_options['commtags'] = $tags;
	update_option('dunce_options', $dunce_options);
?>
	<p><strong>Options Saved</strong></p>
<?php
}
?>
=====

As you can see this is trying to post a multidimensional array to the  
database.  The entries should be something like (for example):

dunce_options[commtags][0][name][dunce]

...but it seems the $tags[] array never gets populated.  As the form  
automatically populates with default values, it seems that _at least_  
that should get posted!  The entire array that gets posted to  
dunce_options in the database is this:

a:1:{s:8:"commtags";a:0:{}}

If anyone can help I would appreciate it.  Thanks.

Stephen



More information about the thelist mailing list