public function save(){ $name = $this->f3->get('POST.name'); $email = $this->f3->get('POST.email'); $comments = $this->f3->get('POST.comments'); $v = new Valitron\Validator(array('Name' => $name,'Email'=>$email,'Comments'=>$comments)); $v->rule('required', ['Name','Email','Comments']); $v->rule('email',[Email]); if ($v->validate()) { $contact = new Contact($this->db); $data = array( 'name' => $name, 'email' => $email, 'comments' => $comments, 'contact_date' => date('Y-m-d H:i:s') ); $contact->insert($data); $response = array( 'status' => true, 'message' => 'Your message saved!' ); }else{ $response = array( 'status' => false, 'errors' => $v->errors() ); } echo json_encode($response); }
public function index() { $vars = array('title' => 'Contact', 'description' => '...'); $isPost = $this->request->isPost(); $contact = new Contact(); $errors = array(); $success = false; if ($isPost) { foreach ($contact->getFields() as $key => $value) { try { $contact->{$key} = $this->request->post($key, ''); } catch (Exception $e) { $errors[$key] = $e->getMessage(); } } if (empty($errors)) { $success = $contact->insert(); } } $form = $contact->getForm('insert', ROOT_HTTP . $this->lang->getUserLang() . '/contact/post', $this->request, $isPost, $errors); $vars['form'] = $form; $vars['isPost'] = $isPost; $vars['errors'] = $errors; $vars['success'] = $success; $this->render('contact', $vars); }
/** * @depends testInsertUser */ public function testInsertContact($user) { $contact = new Contact(); $contact->address = 'test'; $contact->email = '*****@*****.**'; $contact->user_id = $user->id; $contact->insert(); $this->assertGreaterThan(0, $contact->id); return $contact; }
/** * @test */ public function testLoginForm() { $contact = new Contact(); // New AR // $contact = $this->contacts('simple_contact_1'); // Single row with AR // $contact = $this->contacts['simple_contact_1']; // Single row $data = $contact->findAll(); $count_is_greater_than_zero = count($contact->findAll()) > 0; $this->assertTrue($count_is_greater_than_zero); // INSERT ONE NEW RECORD /* $contact->insert(array("c_name"=>"test1", "c_email"=>"*****@*****.**", "c_subject"=>"test1 subject","c_body"=>"Hi, testing body 1.")); $contact = new Contact(); // New AR $contact = new Contact(); // New AR $contact->unsetAttributes(); $contact->setIsNewRecord(true); $contact->insert(array('attributes'=>array( 'c_name' => 'test3', 'c_email' => '*****@*****.**', 'c_subject' => 'test3', 'c_body' => 'test3' )));*/ // $contact->c_id = NULL; $contact->c_name = 'test3'; $contact->c_email = '*****@*****.**'; $contact->c_subject = 'test3'; $contact->c_body = 'test3'; $contact->insert(); $data = $contact->findAll(); $this->assertEquals(count($data), 3); /*$entries = $contact->findAll(); $count_is_greater_than_zero = (count($entries) > 0); echo count($entries).' - '. $count_is_greater_than_zero; // Add new records first // $contact->add("test1", "*****@*****.**", "test1 subject","Hi, testing body 1."); // $contact->add("Tom", "Hi, I'm Tom."); $entries = $contact->findAll(); $count_is_greater_than_zero = (count($entries) > 0); $this->assertTrue($count_is_greater_than_zero);*/ // $this->expectOutputString('two entries'); // fwrite(STDERR, ' Contact login form '.count($entries).' - '. $count_is_greater_than_zero); /*$this->assertIsA($entries, 'array'); // $contact = new Contact(); $contact->deleteAll(); // Delete all the entries first so we know it's an empty table $entries = $contact->viewAll(); $this->assertEqual($entries, array());*/ }
/** * Handle User Edit form submission * * @param <type> $w */ function useradd_POST(Web &$w) { $errors = $w->validate(array(array("login", ".+", "Login is mandatory"), array("password", ".+", "Password is mandatory"), array("password2", ".+", "Password2 is mandatory"))); if ($_REQUEST['password2'] != $_REQUEST['password']) { $errors[] = "Passwords don't match"; } if (sizeof($errors) != 0) { $w->error(implode("<br/>\n", $errors), "/admin/useradd"); } // first saving basic contact info $contact = new Contact($w); $contact->fill($_REQUEST); $contact->dt_created = time(); $contact->private_to_user_id = null; $contact->insert(); // now saving the user $user = new User($w); $user->login = $_REQUEST['login']; $user->setPassword($_REQUEST['password']); $user->is_active = !empty($_REQUEST['is_active']) ? $_REQUEST['is_active'] : 0; $user->is_admin = !empty($_REQUEST['is_admin']) ? $_REQUEST['is_admin'] : 0; $user->is_group = 0; $user->dt_created = time(); $user->contact_id = $contact->id; $user->insert(); $w->ctx("user", $user); // now saving the roles $roles = $w->Auth->getAllRoles(); foreach ($roles as $r) { if (!empty($_REQUEST["check_" . $r])) { if ($_REQUEST["check_" . $r] == 1) { $user->addRole($r); } } } $w->callHook("admin", "account_changed", $user); $w->msg("User " . $user->login . " added", "/admin/users"); }
public function addContact($mysql, $name, $email, $phone, $ownerid) { $con = new Contact(); $con->read($ownerid, $name, $email, $phone); switch($con->insert($mysql)) { case Contact::DATABASE_ERROR : { echo "<p>A Database error has occured.</p>"; return; } case Contact::INVALID_DATA : { echo "<p>Invalid operation requested.</p>"; return; } case Contact::INSERT_SUCCESS : { echo "<p>Contact added successfully.</p>"; break; } default : break; } }
try { ActiveRecord::execute("CREATE TABLE IF NOT EXISTS user ("); ActiveRecord::execute("select * from aaa"); } catch (Exception $e) { var_export($e); } ActiveRecord::execute("CREATE TABLE IF NOT EXISTS user (\n\t\t\t\tid INTEGER PRIMARY KEY, \n\t\t\t\tname TEXT, \n\t\t\t\tpassword TEXT \n\t\t\t);"); ActiveRecord::execute("CREATE TABLE IF NOT EXISTS contact (\n\t\t\t\tid INTEGER PRIMARY KEY, \n\t\t\t\tuser_id INTEGER, \n\t\t\t\temail TEXT,\n\t\t\t\taddress TEXT\n\t\t\t);"); $user = new User(); $user->name = 'demo'; $user->password = md5('demo'); var_dump($user->insert()); $contact = new Contact(); $contact->address = 'test'; $contact->email = '*****@*****.**'; $contact->user_id = $user->id; var_dump($contact->insert()); /* $contact = new Contact(); $contact->address = 'test'; $contact->email = '*****@*****.**'; $contact->user_id = 2; var_dump($contact->insert()); */ $user = new User(); var_dump($user->notnull('id')->orderby('id desc')->find()); echo "\nContact of User # {$user->id}\n"; var_dump($user->contacts); $contact = new Contact(); //var_dump($contact->find()); var_dump($contact->user);
<?php require_once __DIR__ . '/../autoload.php'; $name = $_POST['name']; $mail = $_POST['mail']; $text = $_POST['text']; $data = date("Y-m-d H:i:s"); if (!empty($name) && !empty($text) && !empty($mail)) { $contact = new Contact(); $contact->insert($data, $name, $text, $mail); } $response = ['name' => $name, 'mail' => $mail, 'text' => $text, 'data' => $data]; echo json_encode($response);
<?php require_once 'config/config.conf.php'; $result = null; $errors = array(); $contact = new Contact(); // On a appuyé sur le bouton Envoyer, le formulaire a été soumis if (!empty($_POST)) { foreach ($_POST as $key => $value) { try { $contact->{$key} = $value; } catch (Exception $e) { $errors[$key] = $e->getMessage(); } } if (empty($errors)) { $result = $contact->insert(); } } $vars = array('contact' => $contact, 'errors' => $errors, 'result' => $result); Model::displayTemplate('contact.tpl', $vars);
function addContact($photo, $name, $lastname, $cellphone, $phone, $email, $description) { $status = Contact::insert($photo, $name, $lastname, $cellphone, $phone, $email, $description); return $status; }
//Attempt to add the user to the database, carry out finishing tasks like emailing the user (if required) if ($user->userCakeAddUser()) { if ($user->mail_failure) { array_push($warning_messages, lang("ACTIVATION_MAIL_NOT_SENT", array($_POST['username'], $_POST['email']))); } // Retrieve the User_ID from the database $userdetails = fetchUserDetails($user->clean_username); if (!empty($userdetails)) { $contact = new Contact(true, $userdetails['User_ID'], $_POST); $personal = new Personal(true, $userdetails['User_ID'], $_POST); $status = new Status(true, $userdetails['User_ID'], $_POST); if ($_POST['group_id'] == 1 || $_POST['group_id'] == 2) { $studies = new Studies_Undergr(true, $userdetails['User_ID'], $_POST); } $inserted = array(); $inserted['contact'] = $contact->insert(); $inserted['personal'] = $personal->insert(); $inserted['status'] = $status->insert(); if ($_POST['group_id'] == 1 || $_POST['group_id'] == 2) { $inserted['studies'] = $studies->insert(); } // TODO Failure handling here is non-existent // Need to better handle the case when database insertion partially fails $success = true; foreach ($inserted as $key => $value) { if ($value == false) { array_push($warning_messages, lang("COULD_NOT_SAVE_IN_DATABASE", array($key))); } } } }