Hiya!
I am trying to write a script that [a] asks a user how many input elements they require for a form, and the names of those input elements.
I am completely stuck! I did this first for the dynamic generation:
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" >
<input type='text' name='inputfield'/></p>
<input name="inputname" cols="50" rows="25"></textarea>
<input type='submit' name='submit' value='Submit' />
<? php
if(isset($_POST['submit'])){
$required = $_POST['inputfield'];
$x = 0;
while ($x <= $required){
echo "<p><input type=\"text\" size=\"25\"</p>?>";
++$x;
}
elseif(empty($required)){
echo "<p>Please enter an input element count.</p>";
}
}
?>
I keep returning the error:
Parse error: parse error, unexpected T_IF
I had a think about how to get names for input elements from users. I thought about using:
$inputnames = $_POST['inputname'];
$chars = preg_split('/ /', $inputnames, -1, PREG_SPLIT_OFFSET_CAPTURE);
//Where user has specified names into the text area of the previous code.
I thought about putting the $chars values into their own variables, but I do not know how to create dynamic variables.
This is a mess at the moment!
Could any of you peeps see a better way?
Any help appreciated!
trufla