Part of my html:
#!text/html
<div class="field email">
<label for="users[email]">E-mail:</label><span class="error">* <?php print $this->get('error[email]'); ?></span>
<input type="text" name="users[email]" value="<?php print $this->get('users[email]'); ?>"/>
</div>
Part of my code:
$user = fRequest::get('users');
if($user!=NULL){
$error=Array(
'email'=>'campo obrigatrio', // required field
'password'=>'campo obrigatrio' // required field
);
$errors=count($error);
foreach($user as $key=>$value){
if($value!='' && array_key_exists($key, $error)){
if($key=="email" && !eregi("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$", $value)) {
$error[$key]='e-mail invlido'; // invalid e-mail
}
else {
$error[$key]="";
$errors--;
}
}
}
if($errors<=0){
$result = User::save($user);
} else {
$template->set('users', $user );
}
} else {
$error=Array();
}
By the flourish_demo_site & documentation I could understand that I can get the data from $_POST (HTTP), but I would like to get the data from a variable array and save them.
class User extends fActiveRecord
function save($data){
...
fORMDatabase::attach($mydb);
fORM::mapClassToTable('User', 'users');
$user = fRecordSet::build('User');
try {
$user = new User();
$user->setEmail($data["email"])
How can I populate without having to do one-by-one?
$data produces:
[users] {
[ID] => "",
[email] => "myemail@myhost.com",
[password] => "123456"
}
This might not be the best way to do that, but I like to have a separated file to render the template, verify the data and produces error messages to the user, and them have all set to save them.
By the way, congratulations for such a nice library, and thank you.