Kamis, 28 November 2013

jquery $.ajax php side POST serialized form

$.ajax({
        type: 'POST',
        url: 'entry.php',
        cache: false,
        data: $(".contact_form").serializeArray(),
        success: function (data) {
            if (data == "error") {
                $('.success_box').hide();
                $('.error_box').show();
            }
            else {
                $('#sname').val('');
                $('#email').val('');
                $('#title').val('');
                $('#message').val('');
                $('#photo1').val('');
                $('#photo2').val('');
                $('.error_box').hide();
                $('.success_box').show();
            }
        }
    });

CSS Input Type Selectors - Possible to have an “or” or “not” syntax?

If i have a HTML form with the following inputs:
 type="text" />
 type="password" />
 type="checkbox" />
I want to apply a style to all input's that are either type="text" or type="password".
Alternatively i would settle for all input's where type != "checkbox".
Seems i like to have to do this:
input[type='text'], input[type='password']
{
   // my css
}
Isn't there a way to do:
input[type='text',type='password']
{
   // my css
}
or
input[type!='checkbox']
{
   // my css
}
Had a look around, and it doesn't seem like there is a way to do this with a single CSS selector.
Not a big deal of course, but im just a curious cat.
Any ideas?

Rabu, 27 November 2013

Deleting a File using php/codeigniter


you can use the "file helper" in codeigniter.
http://codeigniter.com/user_guide/helpers/file_helper.html
and like this :
$this->load->helper("file");
delete_files($path);
Late Edit: delete_filesmethod uses a path to wipe out all of its contents via unlink() and same you can do within CI. Like this:
unlink($path); 
a valid path.

example :
$path_file = './riskv2-assets/captcha/';
delete_files($path_file);

Jumat, 22 November 2013

Tutorial CodeIgniter : Penerapan Rekursif Untuk Membuat Menu Bertingkat di CodeIgniter

1. Kita siapkan dulu sebuah tabel menu dengan struktur parent child, artinya ada sebuah field yang dijadikan sebagai acuan parent-nya. Desain tabelnya hampir sama dengan postingan saya beberapa waktu lalu yang juga membahas tentang tree menu di CodeIgniter.

CREATE TABLE IF NOT EXISTS `tbl_menu` (
  `id_menu` int(11) NOT NULL AUTO_INCREMENT,
  `id_parent` varchar(11) DEFAULT NULL,
  `menu` varchar(50) NOT NULL,
  PRIMARY KEY (`id_menu`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;

INSERT INTO `tbl_menu` (`id_menu`, `id_parent`, `menu`) VALUES
(1, '0', 'Beranda'),
(2, '0', 'Profil'),
(3, '0', 'Galeri'),
(4, '0', 'Hubungi Kami'),
(5, '2', 'Visi'),
(6, '2', 'Misi'),
(7, '2', 'Struktur Organisasi'),
(8, '2', 'Sejarah Singkat'),
(9, '3', 'Kemahasiswaan'),
(10, '3', 'Lembaga'),
(11, '3', 'Kegiatan Tahunan'),
(12, '10', 'Lala Lele'),
(13, '10', 'Lala Karet'),
(14, '10', 'Lala Gabus'),
(15, '10', 'Lala Gosong');

<?php
class model_Menu extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }
   
    function getMenu($parent,$hasil){

        $w = $this->db->query("SELECT * from tbl_menu where id_parent='".$parent."'");
        if(($w->num_rows())>0)
        {
            $hasil .= "<ul class='easyui-tree' animate='true'>";
        }
        foreach($w->result() as $h)
        {
            $hasil .= "<li><span>".$h->menu."</span>";
            $hasil = $this->getMenu($h->id_menu,$hasil);
            $hasil .= "</li>";
        }
        if(($w->num_rows)>0)
        {
            $hasil .= "</ul>";
        }
        return $hasil;
    }
   
}

3. _Controller nya


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Dashboard extends CI_Controller {
    public function index()
    {
       $this->load->model('model_Menu');
      
       $data['menu'] = $this->model_Menu->getMenu(0,"");
       $this->template->load('frontend','view_dashboard',$data);
    }

Minggu, 17 November 2013

[CodeIgniter] Upload dan Resize Gambar Secara Otomatis

Saya sering mondar-mandir membaca pertanyaan-pertanyaan member di group CodeIgniter Indonesia dan tak jarang ada yang bertanya atau mempertanyakan bagaimana cara mengupload gambar dan meresize gamber tersebut secara otomatis. Nah, maka dari itu kali ini saya akan memberikan sedikit bahkan secuil contoh penggunaannya.

Buat project baru dengan codeigniter, kemudian buka controller welcome.php, kemudian isi seperti berikut.


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Welcome extends CI_Controller {
 
    public function __construct()
    {
        parent::__construct();
        $this->load->helper(array('form', 'url', 'html'));
        $this->load->library(array('upload','image_lib'));
    }
    
    public function index()
    {
        $data = array();
        $data['error'] = '';
        $data['output'] = '';
         
        if(isset($_FILES['userfile']))
        {
            $this->upload->initialize(array(
                'upload_path' => './assets/',
                'allowed_types' => 'png|jpg|gif',
                'max_size' => '5000',
                'max_width' => '3000',
                'max_height' => '3000'
            ));
         
            if($this->upload->do_upload())
            {
                $data_upload = $this->upload->data();
                $this->image_lib->initialize(array(
                    'image_library' => 'gd2',
                    'source_image' => './assets/'. $data_upload['file_name'],
                    'maintain_ratio' => false,
                    'create_thumb' => true,
                    'quality' => '20%',
                    'width' => 240,
                    'height' => 172
                ));
                 
                if($this->image_lib->resize())
                {
                    $output = '<h4>Thumb - hasil Resize</h4>';
                    $output .= img('./assets/'.$data_upload['raw_name'].'_thumb'.$data_upload['file_ext']);
                    $output .= '<h4 style="margin-top: 30px">Gambar Original</h4>';
                    $output .= img('./assets/'.$data_upload['file_name']);
                     
                    $data['output'] = $output;
                }
                else
                {
                    $data['error'] = $this->image_lib->display_errors();
                }
                 
            }
            else
            {
                $data['error'] = $this->upload->display_errors();
            }
        }
         
        $this->load->view('welcome_message', $data);
    }
}
 
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
 
Kemudian buka folder views/welcome_message.php dan isi seperti berikut.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Welcome to CodeIgniter</title>
 
    <style type="text/css">
 
    ::selection{ background-color: #E13300; color: white; }
    ::moz-selection{ background-color: #E13300; color: white; }
    ::webkit-selection{ background-color: #E13300; color: white; }
 
    body {
        background-color: #fff;
        margin: 40px;
        font: 13px/20px normal Helvetica, Arial, sans-serif;
        color: #4F5155;
    }
 
    a {
        color: #003399;
        background-color: transparent;
        font-weight: normal;
    }
 
    h1 {
        color: #444;
        background-color: transparent;
        border-bottom: 1px solid #D0D0D0;
        font-size: 19px;
        font-weight: normal;
        margin: 0 0 14px 0;
        padding: 14px 15px 10px 15px;
    }
 
    code {
        font-family: Consolas, Monaco, Courier New, Courier, monospace;
        font-size: 12px;
        background-color: #f9f9f9;
        border: 1px solid #D0D0D0;
        color: #002166;
        display: block;
        margin: 14px 0 14px 0;
        padding: 12px 10px 12px 10px;
    }
 
    #body{
        margin: 0 15px 0 15px;
    }
     
    p.footer{
        text-align: right;
        font-size: 11px;
        border-top: 1px solid #D0D0D0;
        line-height: 32px;
        padding: 0 10px 0 10px;
        margin: 20px 0 0 0;
    }
     
    #container{
        margin: 10px;
        border: 1px solid #D0D0D0;
        -webkit-box-shadow: 0 0 8px #D0D0D0;
    }
    </style>
</head>
<body>
 
<div id="container">
    <h1>Upload dan Resize Gambar Otomatis <span style="float: right">Dida Nurwanda</span></h1>
 
    <div id="body">
        <form method="post" enctype="multipart/form-data">       
             
            <?php echo $error; ?>
             
            <div>
                <label for="userfile">Pilih gambar yang akan di upload : </label>
                <br />
                <input type="file" name="userfile" />
            </div>
             
            <div style="margin-top:20px">
                <input type="submit" value="Upload" />
            </div>
         
        </form>
         
        <div>
            <?php echo $output; ?>
        </div>
    </div>
 
    <p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>
 
</body>
</html>
 


Selesai deh, kodenya berantakan tapi mudah di pahami. Kalo bingung mau nambah-nambahin silahkan bertanya :D
 
Berikut penampakannya.
Download
Password : didanurwanda.blogspot.com