public function actionAddcontact() { $model = new Contactemail(); $nama = $_POST['nama']; $email = $_POST['email']; if (isset($_POST["idkontak"]) and $_POST["idkontak"] != "") { $test = $model->findOne($_POST["idkontak"]); $test->FIELD2 = $nama; $test->FIELD3 = $email; if ($test->save()) { // update successful } else { // update failed echo "gagal"; echo error_get_last(); } } else { $model->FIELD1 = ''; $model->FIELD2 = $nama; $model->FIELD3 = $email; $model->insert(); } $this->redirect('' . BaseUrl::base() . '/email/contact', 302); }
public function actionUploadcsv() { if (!empty($_FILES['filecsv']['name'])) { $model = new Contactemail(); $path = file_get_contents($_FILES['filecsv']['tmp_name']); //Membuka file dan membacanya $arr = explode("\r\n", $path); $count = count($arr); foreach ($arr as $key => &$value) { if ($key > 0 and $key < $count - 1) { // validate count array must be like this $array = explode(",", $value); $model->FIELD2 = $array[1]; $model->FIELD3 = $array[2]; $model->insert(); } } ?> <script language="javascript"> alert("Upload CSV Success !!!"); document.location="<?php echo BaseUrl::base(); ?> /email/contact"; </script> <?php } else { ?> <script language="javascript"> alert("Tidak ada file dipilih !!!"); document.location="<?php echo BaseUrl::base(); ?> /email/contact"; </script> <?php } }