Forum Moderators: coopster

Message Too Old, No Replies

Processing forms

         

orion_rus

11:38 pm on Feb 27, 2005 (gmt 0)

10+ Year Member



Hello world. I have following question.
In my project i spend much time for working with forms (loading and saving it in Database). Now i have some ideas how i can automate this process. I don't have enough mind to ask about it early. But everybody teaching on it's own errors).
May be somebody have any automate process for working with forms? if somebody have please put idea here)

My idea is follows.
Let's we need to make form for user data like name surname and gender. we make a global variable
$USER=(array("username"=>array("title"=>"username", "type"=>"text","value"=>""),
"surname"=>array("title"=>"surname","type"=>"text", "value"=>"") and so on
in a form i makeoutput if type=text => input type="text" with such name
in a saving this form i use
foreach ($_POST as $key=>$value)
{$USER[$key]['value']=makesafestring($value);
}
and then
$comma=false;
foreach ($FLAT as $key=>$value)
{if ($comma) {$writestr.=',';}
$writestr.=$key."='".$FLAT[$key]['value']."'";
$comma=true;
}
$q="REPLACE INTO ".TBL_FLATS." SET ".$writestr;
in a loading i use
$q="SELECT * FROM ".TB." WHERE id=".$userid;
$result=$database->query($q);
$user_array=$database->make_array($result);
foreach ($user_array as $key=>$value)
{$user[$key]['value']=makeoutputstring($value);
}

That's all. That are you think what about it?

coopster

5:26 pm on Mar 2, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could always borrow from the PEAR HTML packages ;)

[pear.php.net...]