Aloha,
I started learning OOP and for my first class I wanted to build 'form generator'. Class worked beautifully, so I wanted to make it more dynamic.
Story:
while the user hits 'submit' button, I want to display the form AGAIN, filled with whatever user entered (confirmation). Without class I do thing like that by checking hidden file and if it exists, I just print values for each field, eg.
now, I wanted to do the same inside my class, but I don't know how to make the script read that hidden var.PHP Code:<input type="text" name="name" class="form1" value="<? if ($go == '1') { echo $name; } ?>
Part of my class's code - submit function, where i put hidden var the way I would do without any class:
and then in my other functions which print proper fields I check if the $go has a value, and if it has - print fields value.PHP Code:function f_submit($name="Submit", $value="") {
echo "<br><br>";
echo "<input type=\"submit\"";
echo " name=\"" . str_replace(" ", "_", $name) . "\"";
if ($value){
echo " value=\"" .$value. "\"";
} else {
echo " value=\"" .$name. "\"";
}
echo ">";
echo "<input type=\"hidden\" name=\"go\" value=\"1\">";
}
and here this IF condition [if ($go == '1')] simply does not work. How can I make it work?PHP Code:function f_input($title, $name, $value="") {
echo "<br><br>";
echo $title . "<br>";
echo "<input type=\"text\"";
if (!$name){
$name = str_replace(" ", "_", $title);
}
echo " name=\"" .$name. "\"";
echo " value=\"";
if ($go == '1') echo $name;
echo "\"";
}
Actually, this leads to second problem. While contruction
allowed me to print actual value of $name entered by user, the contruction for class will take a value for $name from funtion's argument, NOT from whatever user entered.PHP Code:<input type="text" name="name" class="form1" value="<? if ($go == '1') { echo $name; } ?>
How can I bypass that and make a function and class working?
Thank you a lot for any help.
G.





Bookmarks