Woocommerce payment gateway integration - integration

Have a problem with latest woocommerce version payment gateway integration.
I recently started using woocommerce for a friend and he was having woocommerce version 1.6.5.2. But now he updated his woocommerce to latest version (2.0.12).
He had some custom made payment gateway that worked on the 1.6 version but now it doesnt.
This is the custom payment gateway code:
/*
Plugin Name ......
.../*
$post_perma = trim( esc_url ( $_SERVER['REQUEST_URI'] ), '/' );
add_action('plugins_loaded', 'woocommerce_rba_etomitreba_init', 0);
if($post_perma == 'uspjeh'||$post_perma == 'greska') {
add_filter('the_content', 'after_processing');
}
function after_processing() {
global $post, $post_perma, $woocommerce;
if($post_perma == 'uspjeh') {
if(isset($_POST['OrderID'])&&isset($_POST['ApprovalCode'])) {
echo '<div class="notify notify-success">Not Important;)</div>';
$order = new WC_Order( $_POST['OrderID'] );
$order->payment_complete();
$order->status = 'completed';
$woocommerce->cart->empty_cart();
unset($_SESSION['order_awaiting_payment']);
}
else {
echo '<div class="notify notify-error">Not Important</div>';
}
}
if($post_perma == 'greska') {
echo '<div class="notify notify-error">DNot Important</div>';
}
}
function woocommerce_rba_etomitreba_init() {
if ( !class_exists( 'WC_Payment_Gateway' ) ) return;
class WC_Raiffeisen_Bank_eToMiTreba extends WC_Payment_Gateway {
public function __construct() {
$this->id = 'rba_etomitreba';
$this->method_title = __( 'Raiffeisen Bank', 'woocommerce' );
$this->icon = apply_filters('woocommerce_cheque_icon', '');
$this->has_fields = false;
// Load the form fields.
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'checkbox',
'label' => __( 'Not Important', 'woothemes' ),
'default' => 'yes'
),
'merchant-id' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'text',
'description' => __( 'Not Important', 'woothemes' ),
'default' => __( '', 'woothemes' )
),
'terminal-id' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'text',
'description' => __( 'Not Important', 'woothemes' ),
'default' => __( '', 'woothemes' )
),
'rsa-private-key' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'textarea',
'description' => __( 'Not Important', 'woothemes' ),
'default' => __( '', 'woothemes' )
),
'title' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'text',
'description' => __( '', 'woothemes' ),
'default' => __( 'Not Important', 'woothemes' )
),
'description' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'textarea',
'description' => __( '', 'woothemes' ),
'default' => 'Not Important.'
)
);
// Load the settings.
$this->init_settings();
$this->title = $this->settings['title'];
$this->description = $this->settings['description'];
// Actions
add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
}
public function process_payment( $order_id ) {
$order = new WC_Order( $order_id );
$order->shipping_first_name;
$order->shipping_last_name;
$order->get_shipping_address();
$url_gateway = 'Not Important';
$merchant_id = 'xxxxx';
$terminal_id = 'xxxxx';
$total = $order->get_total()*100; // kn to lp conversion
$currency_id = 191;
$time = new DateTime('', new DateTimeZone('Europe/Zagreb'));
$purchase_time = $time->format('ymdHis');
$locale = 'hr';
$ordered_items = $order->get_items();
foreach($ordered_items as $item) {
$ordered_items_array[] = $item['name'];
}
$ordered_items = implode(', ',$ordered_items_array);
$purchase_desc = $time->format('d.m.Y. H:i:s').' - '.$order->shipping_first_name.' '.$order->shipping_last_name.' : '.$ordered_items;
$session_id = session_id();
$data = "$merchant_id;$terminal_id;$purchase_time;$order_id;$currency_id;$total;$session_id;";
$priv_key = $this->settings['rsa-private-key'];
$pkeyid = openssl_get_privatekey($priv_key);
openssl_sign($data, $signature, $pkeyid);
openssl_free_key($pkeyid);
$b64sign = base64_encode($signature);
$signature = $b64sign;
//$order->update_status('on-hold', __('Not Important', 'woothemes'));
echo '
<form name="ordersend" action="'.$url_gateway.'" method="post">
<input name="Version" type="hidden" value="1" >
<input name="MerchantID" type="hidden" value="'.$merchant_id.'" >
<input name="TerminalID" type="hidden" value="'.$terminal_id.'" >
<input name="TotalAmount" type="hidden" value="'.$total.'">
<input name="SD" type="hidden" value="'.$session_id.'">
<input name="Currency" type="hidden" value="'.$currency_id.'" >
<input name="Locale" type="hidden" value="'.$locale.'">
<input name="OrderID" type="hidden" value="'.$order_id.'" >
<input name="PurchaseTime" type="hidden" value="'.$purchase_time.'">
<input name="PurchaseDesc" type="hidden" value="'.$purchase_desc.'" >
<input name="Signature" type="hidden" value="'.$signature.'" >
</form>
<script language="javascript">
<!--
document.forms["ordersend"].submit();
--></script>
';
/*
return array (
'result' => 'success'
);*/
}
public function admin_options() {
?>
<img src="<?php echo 'Not Important ?>" width="664" height="114" />
<h3><?php _e('Not Important', 'woothemes'); ?></h3>
<p><?php _e('Not Important'); ?></p>
<table class="form-table">
<?php
// Generate the HTML For the settings form.
$this->generate_settings_html();
?>
</table>
<?php
} // End admin_options()
}
function woocommerce_raiffeisen_bank_etomitreba_gateway($methods) {
$methods[] = 'WC_Raiffeisen_Bank_eToMiTreba';
return $methods;
}
add_filter('woocommerce_payment_gateways', 'woocommerce_raiffeisen_bank_etomitreba_gateway' );
}
Its just a compatibility issue but as i said, i am new to woocommerce and not so experienced with php. Any help would be greatly appreciated.

Change
add_action('woocommerce_update_options_payment_gateways', array(&$this, process_admin_options'));
to
if ( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) ) {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( &$this, 'process_admin_options' ) );
} else {
add_action( 'woocommerce_update_options_payment_gateways', array( &$this, 'process_admin_options' ) );
}

Related

put spans and divs around paginate_links

I wanna style my links and in order to do that I need some spans and divs around it but I dunno how it's done when using paginate_links() from WordPress.
Can you help me to do that?
<div class="pagination">
<?php echo
$pagination = paginate_links( array(
'base' => add_query_arg( 'cpage', '%#%' ),
'format' => '',
'prev_text' => __('← Previous'),
'next_text' => __('Next →'),
'total' => ceil($total / $items_per_page),
'current' => $page,
'type' => 'plain'
));
?>
</div>
so far it looks like that
Just change li to div / span whatever. The main difference is to change your "type" from "plain" to "array" and then you can do what you want with it.
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
$prev_next = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'type' => 'array',
'prev_text' => __('← Previous'),
'next_text' => __('Next →')
) );
if($prev_next){ ?>
<ul>
<?php
foreach($prev_next as $key=>$val){
if (strpos($val,"'page-numbers current'") !== false) {
echo '<li class="active item">'.$val.'</li>';
} elseif (strpos($val,'"next page-numbers"') !== false || strpos($val,'"prev page-numbers"') !== false ) {
echo'<li>'.$val.'</li>';
} else {
echo '<li class="item">'.$val.'</li>';
}
} ?>
</ul>
<?php } ?>

How to use fontawesome in param visual composer?

I code element with visual composer. I want to use fontawesome in element.
Code here show list font-awesome in param visual composer
<code>
array(
'type' => 'iconpicker',
'heading' => esc_html__('Fontawesome', 'interior'),
'param_name' => 'fontawesome_icon',
'settings' => array(
'type' => 'fontawesome'
),
'description' => esc_html__( 'Fontawesome list. Pickup your choice.', 'interior'
),
'dependency' => array(
'element' => 'icon_type',
'value' => array( 'fontawesome-icon' )
)
</code>
I showed list icon in element but i chosen it don't saved and i don't know get value font-awsome display html.
Help me!!!
I have made a code only for Font Awesome Icon... You can try this
below code. it's tested and definitely works. here I have used
"Facebook" in title...Let me know via comment if you found any issue
in code or having any trouble for this.
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if( !class_exists( 'RN_FA_Icon_list' ) ) {
class RN_FA_Icon_list {
private $shortcode;
function __construct() {
/* shortcode base */
$this->shortcode = 'rn_fa_icon_list';
add_action( 'init', array( $this, 'rn_map_shortcode' ) );
add_shortcode( $this->shortcode, array( $this, 'rn_create_shortcode' ) );
}
function rn_map_shortcode( $atts, $content = NULL ) {
if( function_exists( 'vc_map' ) ) {
vc_map(
array(
'name' => esc_html__( 'Font Awesome Icon', 'rn_shortcodes' ),
//'icon' => RN_SHORTCODES_URL . '/admin/img/vc_icons/fancy-list.png',
'base' => $this->shortcode,
'category' => 'Structual',
'class' => 'rn-vc-icon-module rn-structual-module',
'content_element' => true,
'params' => array(
array(
'type' => 'textfield',
'heading' => esc_html__( 'Description', 'rn_shortcodes' ),
'description' => esc_html__( 'Only for internal use. This adds a label to Visual Composer for an easier element identification.', 'rn_shortcodes' ),
'param_name' => 'list_description',
'admin_label' => true,
'group' => 'General'
),
array(
'type' => 'iconpicker',
'heading' => __( 'Icon', 'js_composer' ),
'param_name' => 'icon_fontawesome',
'value' => 'fa fa-adjust',
'group' => 'General',
'settings' => array(
'emptyIcon' => false,
'type' => 'fontawesome',
'iconsPerPage' => 4000,
),
'dependency' => array(
'element' => 'type',
'value' => 'fontawesome',
),
'description' => __( 'Select icon from library.', 'js_composer' ),
),
array(
'type' => 'css_editor',
'param_name' => 'css',
'group' => esc_html__( 'Design Options', 'rn_shortcodes' ),
),
)
)
); /* end mapping */
}
}
function rn_create_shortcode( $atts, $content = NULL ) {
extract( shortcode_atts( array (
'icon_fontawesome' => '',
'css' => ''
), $atts ) );
/* extract list items */
if( function_exists('vc_param_group_parse_atts') && !empty( $values ) ) {
$values = vc_param_group_parse_atts( $values );
}
/* unique listz ID */
$id = uniqid("rn_fa_");
$output = '';
$output .= '<div id="' . esc_attr( $id ) . '">';
$output .= '<i class="' . $icon_fontawesome . '"></i> Facebook';
$output .= '</div>';
return '<div class="wpb_content_element ' . apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, vc_shortcode_custom_css_class( $css, ' ' ), $this->shortcode, $atts ) . '">' . $output . '</div>';
}
}
}
new RN_FA_Icon_list;
?>

Trigger and form codeigniter

I have a database and form with some trigger in phpmyadmin. When I input the value manually on phpmyadmin, the trigger is executed normally. The problem is, when I input the value by form I made with codeigniter, the trigger is not executed, and there is no error. Can anybody help me?
This is the controller
<?php if (!defined('BASEPATH')) exit ('No direct script access allowed');
class Pengujian extends MY_Controller
{
public $data = array(
'modul' => 'pengujian',
'breadcrumb' => 'Pengujian',
'pesan' => '',
'pagination' => '',
'tabel_data' => '',
'main_view' => 'view_pengujian/pengujian_view',
'form_action' => '',
'form_value' => '',
'option_uji' => '',
);
public function __construct()
{
parent::__construct();
$this->load->model('Pengujian_model', 'pengujian', TRUE);
$this->load->model('Peralatan_model', 'peralatan', TRUE);
$this->load->model('Penerangan_model', 'penerangan', TRUE);
$this->load->model('Kemudi_model', 'kemudi', TRUE);
$this->load->model('Suspensi_model', 'suspensi', TRUE);
$this->load->model('Banpelek_model', 'banpelek', TRUE);
$this->load->model('Rangka_model', 'rangka', TRUE);
$this->load->model('Rem_model', 'rem', TRUE);
$this->load->model('Gasbuang_model', 'gasbuang', TRUE);
$this->load->model('Mesin_model', 'mesin', TRUE);
$this->load->model('Lainlain_model', 'lainlain', TRUE);
$this->load->model('Lainlain2_model', 'lainlain2', TRUE);
$this->load->model('Akhir_model', 'akhir', TRUE);
$this->load->helper('form');
//$this->load->model('Penguji_model', 'penguji', TRUE);
}
public function index($offset = 0)
{
$this->session->unset_userdata('no_pengujian_sekarang', '');
$pengujian = $this->pengujian->cari_semua($offset);
if ($pengujian)
{
$tabel = $this->pengujian->buat_tabel($pengujian);
$this->data['tabel_data'] = $tabel;
$this->data['pagination'] = $this->pengujian->paging(site_url('pengujian/halaman'));
}
else
{
$this->data['pesan'] = 'Tidak ada data pengujian';
}
$this->load->view('template', $this->data);
}
public function tambah1()
{
$this->data['breadcrumb'] = 'Pengujian > Tambah > Awal';
$this->data['main_view'] = 'view_pengujian/pengujian_form';
$this->data['form_action'] = 'pengujian/tambah1';
if($this->input->post('submit'))
{
if($this->pengujian->validasi_tambah())
{
if($this->pengujian->tambah1())
{
$this->session->set_flashdata('pesan', ' Proses tambah data berhasil');
redirect('pengujian/tambah2');
}
else
{
$this->data['pesan'] = 'Proses tambah data gagal';
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
public function tambah2()
{
$this->data['breadcrumb'] = 'Pengujian > Tambah > Peralatan';
$this->data['main_view'] = 'view_pengujian/peralatan_form';
$this->data['form_action'] = 'pengujian/tambah2';
if($this->input->post('submit'))
{
if($this->peralatan->validasi_tambah())
{
if($this->peralatan->tambah2())
{
$this->session->set_flashdata('pesan', ' Proses tambah data berhasil');
redirect('pengujian/tambah3');
}
else
{
$this->data['pesan'] = 'Proses tambah data gagal';
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
I have until tambah12 methods, for each method, it must load from 12 models too, and 12 forms.
This is model
private function load_form_rules_tambah()
{
$form = array(
array(
'field' => 'NO_PENGUJIAN',
'label' => 'no pengujian',
'rules' => 'required'
),
);
return $form;
}
public function validasi_tambah()
{
$form = $this->load_form_rules_tambah();
$this->form_validation->set_rules($form);
if($this->form_validation->run())
{
return TRUE;
}
else
{
return FALSE;
}
}
public function tambah1()
{
$pengujian = array(
'NO_PENGUJIAN' => $this->input->post('NO_PENGUJIAN'),
'NO_PEMERIKSAAN' => $this->input->post('NO_PEMERIKSAAN'),
'LOKASI_PENGUJIAN' => $this->input->post('LOKASI_PENGUJIAN'),
'NO_KODE' => $this->input->post('NO_KODE'),
'NO_KENDARAAN' => $this->input->post('NO_KENDARAAN'),
'PEMILIK_KENDARAAN' => $this->input->post('PEMILIK_KENDARAAN'),
'TYPE_MERK_PABRIK' => $this->input->post('TYPE_MERK_PABRIK'),
'JENIS_KENDARAAN' => $this->input->post('JENIS_KENDARAAN'),
'MULAI_DIPERGUNAKAN' => $this->input->post('MULAI_DIPERGUNAKAN'),
'NO_LAPORAN' => $this->input->post('NO_LAPORAN'),
'JENIS_PEMERIKSAAN' => $this->input->post('JENIS_PEMERIKSAAN'),
'JARAK_PEMAKAIAN' => $this->input->post('JARAK_PEMAKAIAN'),
'BERAT_KENDARAAN' => $this->input->post('BERAT_KENDARAAN'),
'PERALATAN' => $this->input->post('PERALATAN'),
'SISTEM_PENERANGAN' => $this->input->post('SISTEM_PENERANGAN'),
'SISTEM_KEMUDI' => $this->input->post('SISTEM_KEMUDI'),
'AS_DAN_SUSPENSI' => $this->input->post('AS_DAN_SUSPENSI'),
'BAN_DAN_PELEK' => $this->input->post('BAN_DAN_PELEK'),
'RANGKA_DAN_BODI' => $this->input->post('RANGKA_DAN_BODI'),
'SISTEM_REM' => $this->input->post('SISTEM_REM'),
'SISTEM_REM_GAS_BUANG' => $this->input->post('SISTEM_REM_GAS_BUANG'),
'MESIN_TRANSMISI' => $this->input->post('MESIN_TRANSMISI'),
'LAIN_LAIN' => $this->input->post('LAIN_LAIN'),
'LAIN_LAIN2' => $this->input->post('LAIN_LAIN2')
);
//$this->load->library('form_validation');
$this->db->insert($this->db_tabel, $pengujian);
if($this->db->affected_rows() > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
and this
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Peralatan_model extends CI_Model
{
public $db_tabel ='peralatan';
//public $offset = 0;
//public function cari_semua($offset = 0);
public function tambah2()
{
$peralatan = array(
'NO_CHASIS' => $this->input->post('NO_CHASIS'),
'PLAT_PABRIK_PEMBUAT' => $this->input->post('PLAT_PABRIK_PEMBUAT'),
'PLAT_NOMOR' => $this->input->post('PLAT_NOMOR'),
'TULISAN' => $this->input->post('TULISAN'),
'PENGHAPUS_KACA_DEPAN' => $this->input->post('PENGHAPUS_KACA_DEPAN'),
'KLAKSON' => $this->input->post('KLAKSON'),
'KACA_SPION' => $this->input->post('KACA_SPION'),
'PANDANGAN_KE_DEPAN' => $this->input->post('PANDANGAN_KE_DEPAN'),
'KACA_PENAHAN_SINAR' => $this->input->post('KACA_PENAHAN_SINAR'),
'ALAT_PENGENDALIAN' => $this->input->post('ALAT_PENGENDALIAN'),
'LAMPU_INDIKASI' => $this->input->post('LAMPU_INDIKASI'),
'SPEEDOMETER' => $this->input->post('SPEEDOMETER'),
'PERLENGKAPAN' => $this->input->post('PERLENGKAPAN')
);
//$this->load->library('form_validation');
$this->db->insert($this->db_tabel, $peralatan);
if($this->db->affected_rows() > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
private function load_form_rules_tambah()
{
$form = array(
array(
'field' => 'NO_PENGUJIAN',
'label' => 'no chasis',
'rules' => 'required'
),
);
return $form;
}
public function validasi_tambah()
{
$form = $this->load_form_rules_tambah();
$this->form_validation->set_rules($form);
if($this->form_validation->run())
{
return TRUE;
}
else
{
return FALSE;
}
}
}
this is the form
<?php
$form = array(
'no pengujian' => array(
'name' => 'NO_PENGUJIAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_PENGUJIAN', isset($form_value['NO_PENGUJIAN']) ? $form_value['NO_PENGUJIAN'] : '')),
'no pemeriksaan' => array(
'name' => 'NO_PEMERIKSAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_PEMERIKSAAN', isset($form_value['NO_PEMERIKSAAN']) ? $form_value['NO_PEMERIKSAAN'] : '')),
'lokasi pengujian' => array(
'name' => 'LOKASI_PENGUJIAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('LOKASI_PENGUJIAN', isset($form_value['LOKASI_PENGUJIAN']) ? $form_value['LOKASI_PENGUJIAN'] : '')),
'no kode' => array(
'name' => 'NO_KODE',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_KODE', isset($form_value['NO_KODE']) ? $form_value['NO_KODE'] : '')),
'no kendaraan' => array(
'name' => 'NO_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_KENDARAAN', isset($form_value['NO_KENDARAAN']) ? $form_value['NO_KENDARAAN'] : '')),
'pemilik kendaraan' => array(
'name' => 'PEMILIK_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('PEMILIK_KENDARAAN', isset($form_value['[PEMILIK_KENDARAAN]']) ? $form_value['PEMILIK_KENDARAAN'] : '')),
'type merk pabrik' => array(
'name' => 'TYPE_MERK_PABRIK',
'size' => '30',
'class' => 'form_field',
'value' => set_value('TYPE_MERK_PABRIK', isset($form_value['TYPE_MERK_PABRIK']) ? $form_value['TYPE_MERK_PABRIK'] : '')),
'jenis kendaraan' => array(
'name' => 'JENIS_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('JENIS_KENDARAAN', isset($form_value['JENIS_KENDARAAN']) ? $form_value['JENIS_KENDARAAN'] : '')),
'mulai dipergunakan' => array(
'name' => 'MULAI_DIPERGUNAKAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('MULAI_DIPERGUNAKAN', isset($form_value['MULAI_DIPERGUNAKAN']) ? $form_value['MULAI_DIPERGUNAKAN'] : '')),
'no laporan' => array(
'name' => 'NO_LAPORAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_LAPORAN', isset($form_value['NO_LAPORAN']) ? $form_value['NO_LAPORAN'] : '')),
'jenis pemeriksaan' => array(
'name' => 'JENIS_PEMERIKSAAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('JENIS_PEMERIKSAAN', isset($_POST['JENIS_PEMERIKSAAN']))),
'jarak pemakaian' => array(
'name' => 'JARAK_PEMAKAIAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('JARAK_PEMAKAIAN', isset($form_value['JARAK_PEMAKAIAN']) ? $form_value['JARAK_PEMAKAIAN'] : '')),
'berat kendaraan' => array(
'name' => 'BERAT_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('BERAT_KENDARAAN', isset($form_value['BERAT_KENDARAAN']) ? $form_value['BERAT_KENDARAAN'] : '')),
'peralatan' => array(
'name' => 'PERALATAN',
'size' => '30',
'value' => set_value('PERALATAN', isset($form_value['PERALATAN']) ? $form_value['PERALATAN'] : '')),
'sistem penerangan' => array(
'name' => 'SISTEM_PENERANGAN',
'size' => '30',
'value' => set_value('SISTEM_PENERANGAN', isset($form_value['SISTEM_PENERANGAN']) ? $form_value['SISTEM_PENERANGAN'] : '')),
'sistem kemudi' => array(
'name' => 'SISTEM_KEMUDI',
'size' => '30',
'value' => set_value('SISTEM_KEMUDI', isset($form_value['SISTEM_KEMUDI']) ? $form_value['SISTEM_KEMUDI'] : '')),
'as dan suspensi' => array(
'name' => 'AS_DAN_SUSPENSI',
'size' => '30',
'value' => set_value('AS_DAN_SUSPENSI', isset($form_value['AS_DAN_SUSPENSI']) ? $form_value['AS_DAN_SUSPENSI'] : '')),
'ban dan pelek' => array(
'name' => 'BAN_DAN_PELEK',
'size' => '30',
'value' => set_value('BAN_DAN_PELEK', isset($form_value['BAN_DAN_PELEK']) ? $form_value['BAN_DAN_PELEK'] : '')),
'rangka dan bodi' => array(
'name' => 'RANGKA_DAN_BODI',
'size' => '30',
'value' => set_value('RANGKA_DAN_BODI', isset($form_value['RANGKA_DAN_BODI']) ? $form_value['RANGKA_DAN_BODI'] : '')),
'sistem rem' => array(
'name' => 'SISTEM_REM',
'size' => '30',
'value' => set_value('SISTEM_REM', isset($form_value['SISTEM_REM']) ? $form_value['SISTEM_REM'] : '')),
'sistem rem gas buang' => array(
'name' => 'SISTEM_REM_GAS_BUANG',
'size' => '30',
'value' => set_value('SISTEM_REM_GAS_BUANG', isset($form_value['SISTEM_REM_GAS_BUANG']) ? $form_value['SISTEM_REM_GAS_BUANG'] : '')),
'mesin transmisi' => array(
'name' => 'MESIN_TRANSMISI',
'size' => '30',
'value' => set_value('MESIN_TRANSMISI', isset($form_value['MESIN_TRANSMISI']) ? $form_value['MESIN_TRANSMISI'] : '')),
'lain lain' => array(
'name' => 'LAIN_LAIN',
'size' => '30',
'value' => set_value('LAIN_LAIN', isset($form_value['LAIN_LAIN']) ? $form_value['LAIN_LAIN'] : '')),
'lain lain2' => array(
'name' => 'LAIN_LAIN2',
'size' => '30',
'value' => set_value('LAIN_LAIN2', isset($form_value['LAIN_LAIN2']) ? $form_value['LAIN_LAIN2'] : '')),
'submit' => array(
'name' => 'submit',
'id' => 'submit',
'value' => 'Simpan'
)
);
?>
<h2><?php echo $breadcrumb ?></h2>
<!-- pesan start -->
<?php if (! empty($pesan)) : ?>
<div class="pesan">
<?php echo $pesan; ?>
</div>
<?php endif ?>
<!-- pesan end -->
<!-- form start -->
<?php echo form_open($form_action); ?>
<p>
<?php echo form_label('No Pengujian', 'NO_PENGUJIAN'); ?>
<?php echo form_input($form['no pengujian']); ?>
</p>
<?php echo form_error('NO_PENGUJIAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Pemeriksaan', 'NO_PEMERIKSAAN'); ?>
<?php echo form_input($form['no pemeriksaan']); ?>
</p>
<?php echo form_error('NO_PEMERIKSAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Lokasi Pengujian', 'LOKASI_PENGUJIAN'); ?>
<?php echo form_input($form['lokasi pengujian']); ?>
</p>
<?php echo form_error('LOKASI_PENGUJIAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Kode', 'NO_KODE'); ?>
<?php echo form_input($form['no kode']); ?>
</p>
<?php echo form_error('NO_KODE', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Kendaraan', 'NO_KENDARAAN'); ?>
<?php echo form_input($form['no kendaraan']); ?>
</p>
<?php echo form_error('NO_KENDARAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Pemilik Kendaraan', 'PEMILIK_KENDARAAN'); ?>
<?php echo form_input($form['pemilik kendaraan']); ?>
</p>
<?php echo form_error('PEMILIK_KENDARAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Type Merk Pabrik', 'TYPE_MERK_PABRIK'); ?>
<?php echo form_input($form['type merk pabrik']); ?>
</p>
<?php echo form_error('TYPE_MERK_PABRIK', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Jenis Kendaraan', 'JENIS_KENDARAAN'); ?>
<?php echo form_input($form['jenis kendaraan']); ?>
</p>
<?php echo form_error('JENIS_KENDARAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Mulai Dipergunakan', 'MULAI_DIPERGUNAKAN'); ?>
<?php echo form_input($form['mulai dipergunakan']); ?>
</p>
<?php echo form_error('MULAI_DIPERGUNAKAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Laporan', 'NO_LAPORAN'); ?>
<?php echo form_input($form['no laporan']); ?>
</p>
<?php echo form_error('NO_LAPORAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Jenis Pemeriksaan', 'JENIS_PEMERIKSAAN'); ?>
<?php echo form_radio('JENIS_PEMERIKSAAN', 'Utama'); ?> Utama
<?php echo form_radio('JENIS_PEMERIKSAAN', 'Ulang'); ?> Ulang
</p>
<p>
<?php echo form_label('Jarak Pemakaian', 'JARAK_PEMAKAIAN'); ?>
<?php echo form_input($form['jarak pemakaian']); ?>
</p>
<?php echo form_error('JARAK_PEMAKAIAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Berat Kendaraan', 'BERAT_KENDARAAN'); ?>
<?php echo form_input($form['berat kendaraan']); ?>
</p>
<?php echo form_error('BERAT_KENDARAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_submit($form['submit']); ?>
<?php echo anchor('pengujian', 'Batal', array('class' => 'cancel')) ?>
</p>
<?php echo form_close(); ?>
<?php echo var_dump($form["no pengujian"]); ?>
and this
<?php
$form = array(
'no pengujian' => array(
'name' => 'NO_PENGUJIAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_PENGUJIAN', isset($form_value['NO_PENGUJIAN']) ? $form_value['NO_PENGUJIAN'] : '')),
'no chasis' => array(
'name' => 'NO_CHASIS',
'size' => '30',
'class' => 'radio',
'value' => set_value('NO_CHASIS', isset($_POST['NO_CHASIS']))),
'plat pabrik pembuat' => array(
'name' => 'PLAT_PABRIK_PEMBUAT',
'size' => '30',
'class' => 'radio',
'value' => set_value('PLAT_PABRIK_PEMBUAT', isset($_POST['PLAT_PABRIK_PEMBUAT']))),
'plat nomor' => array(
'name' => 'PLAT_NOMOR',
'size' => '30',
'class' => 'radio',
'value' => set_value('PLAT_NOMOR', isset($_POST['PLAT_NOMOR']))),
'tulisan' => array(
'name' => 'TULISAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('TULISAN', isset($_POST['TULISAN']))),
'penghapus kaca depan' => array(
'name' => 'PENGHAPUS_KACA_DEPAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('PENGHAPUS_KACA_DEPAN', isset($_POST['PENGHAPUS_KACA_DEPAN']))),
'klakson' => array(
'name' => 'KLAKSON',
'size' => '30',
'class' => 'radio',
'value' => set_value('KLAKSON', isset($_POST['KLAKSON']))),
'kaca spion' => array(
'name' => 'KACA_SPION',
'size' => '30',
'class' => 'radio',
'value' => set_value('KACA_SPION', isset($_POST['KACA_SPION']))),
'pandangan ke depan' => array(
'name' => 'PANDANGAN_KE_DEPAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('PANDANGAN_KE_DEPAN', isset($_POST['PANDANGAN_KE_DEPAN']))),
'kaca penahan sinar' => array(
'name' => 'KACA_PENAHAN_SINAR',
'size' => '30',
'class' => 'radio',
'value' => set_value('KACA_PENAHAN_SINAR', isset($_POST['KACA_PENAHAN_SINAR']))),
'alat pengendalian' => array(
'name' => 'ALAT_PENGENDALIAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('ALAT_PENGENDALIAN', isset($_POST['ALAT_PENGENDALIAN']))),
'lampu indikasi' => array(
'name' => 'LAMPU_INDIKASI',
'size' => '30',
'class' => 'radio',
'value' => set_value('LAMPU_INDIKASI', isset($_POST['LAMPU_INDIKASI']))),
'speedometer' => array(
'name' => 'SPEEDOMETER',
'size' => '30',
'class' => 'radio',
'value' => set_value('SPEEDOMETER', isset($_POST['SPEEDOMETER']))),
'perlengkapan' => array(
'name' => 'PERLENGKAPAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('PERLENGKAPAN', isset($_POST['PERLENGKAPAN']))),
'submit' => array(
'name' => 'submit',
'id' => 'submit',
'value' => 'Simpan'
)
);
?>
<h2><?php echo $breadcrumb ?></h2>
<!-- pesan start -->
<?php if (! empty($pesan)) : ?>
<div class="pesan">
<?php echo $pesan; ?>
</div>
<?php endif ?>
<!-- pesan end -->
<!-- form start -->
<?php echo form_open($form_action); ?>
<p>
<?php echo form_label('No Pengujian', 'NO_PENGUJIAN'); ?>
<?php echo form_input($form['no pengujian']); ?>
</p>
<?php echo form_error('NO_PENGUJIAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Chasis', 'NO_CHASIS'); ?>
<?php echo form_radio('NO_CHASIS', 'Lulus'); ?> Lulus
<?php echo form_radio('NO_CHASIS', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Plat Pabrik Pembuat', 'PLAT_PABRIK_PEMBUAT'); ?>
<?php echo form_radio('PLAT_PABRIK_PEMBUAT', 'Lulus'); ?> Lulus
<?php echo form_radio('PLAT_PABRIK_PEMBUAT', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Plat Nomor', 'PLAT_NOMOR'); ?>
<?php echo form_radio('PLAT_NOMOR', 'Lulus'); ?> Lulus
<?php echo form_radio('PLAT_NOMOR', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Tulisan', 'TULISAN'); ?>
<?php echo form_radio('TULISAN', 'Lulus'); ?> Lulus
<?php echo form_radio('TULISAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Penghapus Kaca Depan', 'PENGHAPUS_KACA_DEPAN'); ?>
<?php echo form_radio('PENGHAPUS_KACA_DEPAN', 'Lulus'); ?> Lulus
<?php echo form_radio('PENGHAPUS_KACA_DEPAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Klakson', 'KLAKSON'); ?>
<?php echo form_radio('KLAKSON', 'Lulus'); ?> Lulus
<?php echo form_radio('KLAKSON', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Kaca Spion', 'KACA_SPION'); ?>
<?php echo form_radio('KACA_SPION', 'Lulus'); ?> Lulus
<?php echo form_radio('KACA_SPION', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Pandangan Ke Depan', 'PANDANGAN_KE_DEPAN'); ?>
<?php echo form_radio('PANDANGAN_KE_DEPAN', 'Lulus'); ?> Lulus
<?php echo form_radio('PANDANGAN_KE_DEPAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Kaca Penahan Sinar', 'KACA_PENAHAN_SINAR'); ?>
<?php echo form_radio('KACA_PENAHAN_SINAR', 'Lulus'); ?> Lulus
<?php echo form_radio('KACA_PENAHAN_SINAR', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Alat Pengendalian', 'ALAT_PENGENDALIAN'); ?>
<?php echo form_radio('ALAT_PENGENDALIAN', 'Lulus'); ?> Lulus
<?php echo form_radio('ALAT_PENGENDALIAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Lampu Indikasi', 'LAMPU_INDIKASI'); ?>
<?php echo form_radio('LAMPU_INDIKASI', 'Lulus'); ?> Lulus
<?php echo form_radio('LAMPU_INDIKASI', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Speedometer', 'SPEEDOMETER'); ?>
<?php echo form_radio('SPEEDOMETER', 'Lulus'); ?> Lulus
<?php echo form_radio('SPEEDOMETER', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Perlengkapan', 'PERLENGKAPAN'); ?>
<?php echo form_radio('PERLENGKAPAN', 'Lulus'); ?> Lulus
<?php echo form_radio('PERLENGKAPAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_submit($form['submit']); ?>
<?php echo anchor('pengujian', 'Batal', array('class' => 'cancel')) ?>
</p>
<?php echo form_close(); ?>
and this is the trigger form php myadmin
CREATE TRIGGER `trigger_peralatan` BEFORE INSERT ON `peralatan`
FOR EACH ROW begin
if (new.NO_CHASIS = "Lulus"
AND new.PLAT_PABRIK_PEMBUAT = "Lulus"
AND new.PLAT_NOMOR = "Lulus"
AND new.TULISAN = "Lulus"
AND new.PENGHAPUS_KACA_DEPAN = "Lulus"
AND new.KLAKSON = "Lulus"
AND new.KACA_SPION = "Lulus"
AND new.PANDANGAN_KE_DEPAN = "Lulus"
AND new.KACA_PENAHAN_SINAR = "Lulus"
AND new.ALAT_PENGENDALIAN = "Lulus"
AND new.LAMPU_INDIKASI = "Lulus"
AND new.SPEEDOMETER = "Lulus"
AND new.PERLENGKAPAN = "Lulus")
then
UPDATE pengujian
SET PERALATAN = "Lulus"
WHERE NO_PENGUJIAN = new.NO_PENGUJIAN;
else
UPDATE pengujian
SET PERALATAN = "Gagal"
WHERE NO_PENGUJIAN = new.NO_PENGUJIAN; end if;
end
and this for the last trigger
CREATE TRIGGER `trigger_nilai` BEFORE INSERT ON `pengujian`
FOR EACH ROW begin
if
(new.AS_DAN_SUSPENSI = "Lulus" AND
new.BAN_DAN_PELEK = "Lulus" AND
new.LAIN_LAIN = "Lulus" AND
new.LAIN_LAIN2 = "Lulus" AND
new.MESIN_TRANSMISI = "Lulus" AND
new.PERALATAN = "Lulus" AND
new.RANGKA_DAN_BODI = "Lulus" AND
new.SISTEM_KEMUDI = "Lulus" AND
new.SISTEM_PENERANGAN = "Lulus" AND
new.SISTEM_REM = "Lulus" AND
new.SISTEM_REM_GAS_BUANG = "Lulus")
then
SET new.PENILAIAN = "Lulus" ;
else
SET new.PENILAIAN = "Gagal" ; end if;
end
this is the insert query
INSERT INTO `pengujian`(`NO_PENGUJIAN`, `NO_PEMERIKSAAN`, `LOKASI_PENGUJIAN`, `NO_KODE`, `NO_KENDARAAN`, `PEMILIK_KENDARAAN`, `TYPE_MERK_PABRIK`, `JENIS_KENDARAAN`, `MULAI_DIPERGUNAKAN`, `TANGGAL_PEMERIKSAAN`, `NO_LAPORAN`, `JENIS_PEMERIKSAAN`, `JARAK_PEMAKAIAN`, `BERAT_KENDARAAN`, `PERALATAN`, `SISTEM_PENERANGAN`, `SISTEM_KEMUDI`, `AS_DAN_SUSPENSI`, `BAN_DAN_PELEK`, `RANGKA_DAN_BODI`, `SISTEM_REM`, `SISTEM_REM_GAS_BUANG`, `MESIN_TRANSMISI`, `LAIN_LAIN`, `LAIN_LAIN2`, `PENILAIAN`, `TANGGAL_PEMERIKSAAN_BERIKUTNYA`, `CATATAN`, `PENGUJI`, `BIAYA_TOTAL`) VALUES ([value-1],[value-2],[value-3],[value-4],[value-5],[value-6],[value-7],[value-8],[value-9],[value-10],[value-11],[value-12],[value-13],[value-14],[value-15],[value-16],[value-17],[value-18],[value-19],[value-20],[value-21],[value-22],[value-23],[value-24],[value-25],[value-26],[value-27],[value-28],[value-29],[value-30])
It's a little confusing...

How to allow save without all inputs filled in sign up form cakephp

I am having this issue: I want to allow persons to sign up based on 3 different roles: #artiste, manager, fan . When you select the 'artiste' role from the dropdown you get a popup that contains the remaining fields.
If a fan or manager is registering however you will not get the remaining inputs. The problem I am having is that when these additional inputs and image are not added the form will not save.. I want to know why this is happening, all the fields that are optional are set as NULL in the database.
here is my form code:
<?php echo $this->Form->create('User', array('class'=>'form-horizontal', 'type'=>'file'));?>
<?php echo $this->Form->input('username', array('placeholder'=>'Username', 'div'=>'form-group', 'label'=>false, 'class'=>'form-control'));
echo $this->Form->input('email', array('placeholder'=>'Email', 'div'=>'form-group', 'label'=>false, 'class'=>'form-control'));
echo $this->Form->input('first_name', array('placeholder'=>'First Name', 'div'=>'form-group', 'label'=>false, 'class'=>'form-control'));
echo $this->Form->input('last_name', array('placeholder'=>'Last Name', 'div'=>'form-group', 'label'=>false, 'class'=>'form-control'));
echo $this->Form->input('middle_name', array('placeholder'=>'Middle Name', 'div'=>'form-group', 'label'=>false, 'class'=>'form-control'));
echo $this->Form->input('phone', array('placeholder'=>'Your Phone Number', 'div'=>'form-group', 'label'=>false, 'class'=>'form-control'));
echo $this->Form->input('password', array('placeholder'=>'Password', 'div'=>'form-group', 'label'=>false, 'class'=>'form-control'));
echo $this->Form->input('password_confirm', array( 'maxLength' => 255, 'title' => 'Confirm password', 'type'=>'password', 'placeholder'=>'Confirm Password', 'div'=>'form-group', 'label'=>false, 'class'=>'form-control'));
//new code
echo '<div class="brandDiv" id="artiste">';
echo '<div class="artiste-child">';
echo '<div class="form-group">';
echo $this->Form->textarea('summary', array('placeholder'=>'Describe yourself, your history in the music business and more', 'div'=>'form-group', 'label'=>false, 'class'=>'form-control textarea2', 'empty' => true));
echo '</div>';
echo '<div class="form-group">';
echo $this->Form->textarea('role_model', array('placeholder'=>'Your role model in life, start this as: My role model is...', 'div'=>'form-group', 'label'=>false, 'class'=>'form-control textarea2', 'empty' => true));
echo '</div>';
echo '<div class="form-group">';
echo $this->Form->textarea('fav_song', array('placeholder'=>'Your favourite song, start this as: My favourite song is...', 'div'=>'form-group', 'label'=>false, 'class'=>'form-control textarea2', 'empty' => true));
echo '</div>';
echo '<div class="form-group">';
echo $this->Form->input('trailer', array('placeholder'=>'Put the last 11 letters and digits of your youtube video url here', 'div'=>'form-group', 'label'=>false, 'class'=>'form-control', 'empty' => true));
echo '</div>';
echo '<div class="form-group">';
echo $this->Form->input('pdf_path', array('type' => 'file','label' => 'Add a profile image', 'empty' => true));
echo '</div>';
echo '<div class="form-group">';
echo $this->Form->input('genre_id', array('options' => $genres,'class'=>'form-control', 'div'=>'form-group', 'label'=>false, 'empty' => true));
echo '</div>';
echo '</div>';
echo '</div>';
//end of new code
echo $this->Html->div('info', 'Are you a music manager, artiste or just a fan? Choose your role');
echo $this->Form->input('role', array(
'options' => array('manager' => 'Manager', '#artiste' => 'Artiste', 'fan' => 'Fan'),'placeholder'=>'Confirm Password', 'div'=>'form-group', 'label'=>false, 'class'=>'form-control'));
echo $this->Form->submit('Sign Up', array('class' => 'form-submit btn btn-default', 'title' => 'Click here to add the user') ); ?>
<?php echo $this->Form->end(); ?>
This is my user model:
<?php
App::uses('AuthComponent', 'Controller/Component');
App::uses('CakeSession', 'Model/Datasource');
class User extends AppModel {
//public $hasOne = array('Product');
public $hasMany = array('Children'=>array(
'className'=>'User',
'foreignKey'=>'parent_id'
),
'Image'=>array(
'className'=>'Image',
),
'Like'=>array(
'className'=>'Like',
),
'Comment'=>array(
'className'=>'Comment',
),
'Customize'=>array(
'className'=>'Customize',
));
public $belongsTo = array(
'Parent'=>array(
'className'=>'User',
'foreignKey'=>'parent_id'
),
'Genre'=> array(
'className'=>'Genre'
)
);
public $avatarUploadDir = 'img/avatars';
public $validate = array(
'genre_id' => array(
'nonEmpty' => array(
'rule' => array('notEmpty'),
'required'=> false,
'message' => 'genre is required',
'allowEmpty' => true
)),
'summary' => array(
'nonEmpty' => array(
'rule' => array('notEmpty'),
'required'=> false,
'message' => 'summary is required',
'allowEmpty' => true
)),
'pdf_path' => array(
'nonEmpty' => array(
'rule' => array('notEmpty'),
'required'=> false,
'message' => 'image is required',
'allowEmpty' => true
)),
'trailer' => array(
'nonEmpty' => array(
'rule' => array('notEmpty'),
'required'=> false,
'message' => 'trailer is required',
'allowEmpty' => true
)),
'fav_song' => array(
'nonEmpty' => array(
'rule' => array('notEmpty'),
'required'=> false,
'message' => 'favourite song is required',
'allowEmpty' => true
)),
'role_model' => array(
'nonEmpty' => array(
'rule' => array('notEmpty'),
'required'=> false,
'message' => 'role model is required',
'allowEmpty' => true
)),
'username' => array(
'nonEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'A username is required',
'allowEmpty' => false
),
'between' => array(
'rule' => array('between', 5, 15),
'required' => true,
'message' => 'Usernames must be between 5 to 15 characters'
),
'unique' => array(
'rule' => array('isUniqueUsername'),
'message' => 'This username is already in use'
),
'alphaNumericDashUnderscore' => array(
'rule' => array('alphaNumericDashUnderscore'),
'message' => 'Username can only be letters, numbers and underscores'
),
),
'password' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A password is required'
),
'min_length' => array(
'rule' => array('minLength', '6'),
'message' => 'Password must have a mimimum of 6 characters'
)
),
'password_confirm' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Please confirm your password'
),
'equaltofield' => array(
'rule' => array('equaltofield','password'),
'message' => 'Both passwords must match.'
)
),
'email' => array(
'required' => array(
'rule' => array('email', true),
'message' => 'Please provide a valid email address.'
),
'unique' => array(
'rule' => array('isUniqueEmail'),
'message' => 'This email is already in use',
),
'between' => array(
'rule' => array('between', 6, 60),
'message' => 'Usernames must be between 6 to 60 characters'
)
),
'role' => array(
'valid' => array(
'rule' => array('inList', array('manager', '#artiste', 'fan')),
'message' => 'Please enter a valid role',
'allowEmpty' => false
)
),
'password_update' => array(
'min_length' => array(
'rule' => array('minLength', '6'),
'message' => 'Password must have a mimimum of 6 characters',
'allowEmpty' => true,
'required' => false
)
),
'password_confirm_update' => array(
'equaltofield' => array(
'rule' => array('equaltofield','password_update'),
'message' => 'Both passwords must match.',
'required' => false,
)
),
'current_password' => array(
'notempty' => array('rule' => 'notEmpty', 'message' => 'please enter your old password'),
'check password' => array('rule' => 'checkPassword',
'message' => 'your password is not correct')
)
);
public function addArtiste($postData = null) {
if (!empty($postData)) {
$postData['User']['parent_id'] = CakeSession::read("Auth.User.id");
$this->create();
if ($this->save($postData)) {
return true;
}
else
{
return false;
}
}
}
public function checkPassword($data) {
$user1=new User();
$user=$user1->read(null, $this->data['User']['id']);
$current_password=AuthComponent::password($data['current_password']);
if($current_password==$user['User']['password']){
return true;
}
}
finally this is my UsersController add action :
public function add() {
//new code
$genres = $this->User->Genre->find('list', array(
'fields' => array('Genre.name')
));
$this->set('genres', $genres);
//end new code
if ($this->request->is('post')) {
$filename = '';
if ($this->request->is('post')) { // checks for the post values
$uploadData = $this->data['User']['pdf_path'];
if ( $uploadData['size'] == 0 || $uploadData['error'] !== 0) { // checks for the errors and size of the uploaded file
return false;
}
$filename = basename($uploadData['name']); // gets the base name of the uploaded file
$uploadFolder = WWW_ROOT. 'files'; // path where the uploaded file has to be saved
$filename = time() .'_'. $filename; // adding time stamp for the uploaded image for uniqueness
$uploadPath = $uploadFolder . DS . $filename;
if( !file_exists($uploadFolder) ){
mkdir($uploadFolder); // creates folder if not found
}
if (!move_uploaded_file($uploadData['tmp_name'], $uploadPath)) {
return false;
}
$this->request->data['User']['image'] = $filename;
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('Congrats! You have registered'));
if ($this->Auth->login()) {
if ($this->Auth->user('role')=='manager') {
$this->Session->setFlash(__('Welcome Manager, '. $this->Auth->user('username')));
$this->redirect(array('action'=>'manager'));
}
if ($this->Auth->login()) {
if ($this->Auth->user('role')=='#artiste') {
$this->Session->setFlash(__('Welcome! '));
$this->redirect(array( 'controller'=>'users', 'action'=>'artiste'));
}
if ($this->Auth->user('role')=='master') {
$this->Session->setFlash(__('Welcome admin, '. $this->Auth->user('username')));
$this->redirect(array('action'=>'index'));
}
else {
$this->Session->setFlash(__('Welcome, '. $this->Auth->user('username')));
$this->redirect(array('action'=>'favourites'));
}
} else {
$this->Session->setFlash(__('Invalid username or password'));
}
}
//$this->redirect(array('action' => 'login'));
} else {
$this->Session->setFlash(__('You could not register, please try again'));
}
}
}
$genre_list = $this->User->Genre->find('all');
$this->set('genre_list', $genre_list);
}

Issue on Adding Taxonomy to Custom Post Type Using Function

Using WordPress 3.7.1 and PHP 5.4.12, I am trying to add Custom Post Type and Taxonomy to my Theme, so far the custom post type method works but the Taxonomy is not adding to the Admin Dashboard.
Here is the code I have:
<?php
function add_post_type($name, $args = array()) {
add_action('init', function() use($name, $args) {
$upper = ucwords($name);
$name = strtolower(str_replace(' ','_',$name));
$args = array_merge(
array(
'public'=> true,
'label' => "All $upper" . 's',
'labels' => array('add_new_item' => "Add New $upper"),
'support' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments')
),
$args
);
register_post_type('$name', $args);
});
}
function add_taxonomy($name, $post_type, $args = array()) {
$name = strtolower($name);
add_action('init', function() use($name, $post_type, $args) {
$args = array_merge(
array(
'label' => ucwords($name),
),
$args
);
register_taxonomy($name, $post_type, $args);
});
}
add_post_type('book', array(
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments')
));
add_taxonomy('fun', 'book');
?>
Can you please let me know what part I am doing wrong?
The $name variable is not parsed, put it between double quotes:
register_post_type( "$name", $args );
edit
add_action( 'init', 'so19966809_init' );
function so19966809_init()
{
register_post_type( 'book', array(
'public'=> true,
'label' => 'All Books',
'labels' => array( 'add_new_item' => 'Add New Book' ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
'taxonomies' => array( 'fun' )
) );
register_taxonomy( 'fun', 'book', array(
'label' => 'Fun',
) );
}