Need help with foreach function...
Posted: Wed Aug 27, 2008 11:53 am
I have a dynamically loaded form... I am using a readdir function to populate a simple form. For example, in a folder called "content" I have 3 files: 1.html, 2.html, and 3.html. I have manipulated the readdir function to loop return just the file names (i.e. 1,2,3) using trim. For each page name returned, I have 3 elements in a form: $file (1, 2, or 3), $keywords, and $description.
i.e. (my readdir loop will return 3 form elements):
---------------------------------------------------------------
My "somefile.php" file will create another page, let's call "include.php," using fopen with a final goal of writing a switch function to "include.php" so that "include.php" looks something like this:
-----------------------------------------------------------
Here's where I am hung up...
In "somefile.php" I am working with a foreach function to get the $_POST['file'], $_POST['keywords'], and $_POST['description'] for each form element so as to format it to look like this:
Sorry for such a long explanation but any help would be much appreciated!
Thanks! Dan
i.e. (my readdir loop will return 3 form elements):
Code: Select all
<form action="somefile.php">
<input type="hidden" name="file[]" value="<?=$file?>">
<!--user input -->
<textarea name="keywords[]" cols="75" rows="5"></textarea>
<textarea name="description[]" cols="75" rows="5"></textarea>
<input type="submit" name="Submit" value="Go">
<!--user input -->
<input type="hidden" name="file[]" value="<?=$file?>">
<!--user input -->
<textarea name="keywords[]" cols="75" rows="5"></textarea>
<textarea name="description[]" cols="75" rows="5"></textarea>
<input type="submit" name="Submit" value="Go">
<!--user input -->
<input type="hidden" name="file[]" value="<?=$file?>">
<!--user input -->
<textarea name="keywords[]" cols="75" rows="5"></textarea>
<textarea name="description[]" cols="75" rows="5"></textarea>
<input type="submit" name="Submit" value="Go">
<!--user input -->
</form>
My "somefile.php" file will create another page, let's call "include.php," using fopen with a final goal of writing a switch function to "include.php" so that "include.php" looks something like this:
Code: Select all
<?
switch($_GET['do']){
case '1':
$keywords = '1's keywords';
$description = '1's description';
break;
case '2':
$keywords = '2's keywords';
$description = '2's description';
break;
case '3':
$keywords = '3's keywords';
$description = '3's description';
break;
}
Here's where I am hung up...
In "somefile.php" I am working with a foreach function to get the $_POST['file'], $_POST['keywords'], and $_POST['description'] for each form element so as to format it to look like this:
Code: Select all
<?
$fp = fopen('', w);
fwrite($fp, '<?');
fwrite($fp, "\n");
fwrite($fp, 'switch(\$_GET['do']');
fwrite($fp, "\n");
fwrite($fp, "case '1':");
fwrite($fp, "\n");
fwrite($fp, "\$keywords = '1's keywords';");
...
...
etc...
fclose($fp);
?>
Thanks! Dan