public function testValidate() { $_GET['siteID'] = "test_all"; $_GET['landingForm']['email'] = '*****@*****.**'; $_GET['landingForm']['phone'] = '+77012240824'; $valid_form = new LandingForm(); $valid_form->load(); $this->assertTrue($valid_form->validate()); $_GET['landingForm']['phone'] = '87012240824'; $valid_form2 = new LandingForm(); $valid_form2->load(); $this->assertTrue($valid_form2->validate()); $_GET['landingForm']['email'] = 'not_email'; $_GET['landingForm']['phone'] = '+77012240824321'; $invalid_form = new LandingForm(); $invalid_form->load(); $this->assertFalse($invalid_form->validate()); unset($_GET['landingForm']); $empty_form = new LandingForm(); $empty_form->load(); $this->assertFalse($empty_form->validate()); /*$_GET['landingForm']['name'] = 'Name'; $invalid_form2 = new LandingForm(); $invalid_form2->load(); $this->assertFalse($invalid_form2->validate());*/ $_GET['landingForm']['phone'] = '87017777777'; $valid_form3 = new LandingForm(); $valid_form3->load(); $this->assertTrue($valid_form3->validate()); unset($_GET['landingForm']); $_GET['landingForm']['email'] = '*****@*****.**'; $valid_form4 = new LandingForm(); $valid_form4->load(); $this->assertTrue($valid_form4->validate()); }
<?php header('Content-Type: application/javascript'); define('DEBUG', true); require __DIR__ . "/LandingForm.php"; $data = ["success" => false, "errors" => []]; try { $form = new LandingForm(); $form->load(); if ($form->validate()) { $email = $form->send(); $database = $form->save(); $telegram = $form->sendTelegram(); $data['success'] = true; if (DEBUG) { $data['telegram'] = $telegram; $data['email'] = $email; $data['database'] = $database; } } $data["errors"] = array_merge($data["errors"], $form->getErrors()); } catch (Exception $e) { $data['errors'][] = $e->getMessage(); } echo $_GET['callback'] . '(' . json_encode($data) . ')';