Codeigniter form_dropdown error - php

I am making a website and i have a function to register clients, and i need to place an option to choose from a database on a dropdown and then it is sent to the users table, i am getting 2 erros atm and i can't find the solution.
This is my Model:
class Home extends CI_Model{
//SQL
function get_prodTYPE(){
$this->db->select()->from('producttype')->where('active',1);
$query=$this->db->get();
return $query->result_array();
}
function get_COUNTRY(){
$this->db->select()->from('pais');
$this->db->order_by("id_pais", "asc");
$result = $this->db->get('pais');
$resultado = array();
if($result->num_rows() > 0){
$resultado[''] = 'please select';
foreach($result->result_array() as $row){
$resultado[$row['id_pais']] = $row['Pais'];
}
}
return $resultado;
}
Then i have a big file where this is the main part for registering
This is my Controller:
function register(){
if(!$this->session->userdata('userID')){
$data['prodTYPE']=$this->home->get_prodTYPE();
$data['info']=$this->home->get_info();
$data['country']=$this->home->get_COUNTRY();
//validacao
$config=array(
array(
'field'=>'username',
'label'=>'Username',
'rules'=>'trim|required|is_unique[users.username]|callback_min_lenght_3'
),
array(
'field'=>'password',
'label'=>'Password',
'rules'=>'trim|required|callback_min_lenght_6'
),
array(
'field'=>'password2',
'label'=>'Password de Confirmação',
'rules'=>'trim|required|matches[password]'
),
array(
'field'=>'email',
'label'=>'Email',
'rules'=>'trim|required|is_unique[users.email]|valid_email'
),
array(
'field'=>'name',
'label'=>'Nome',
'rules'=>'trim|required|callback_username_check|callback_min_lenght_3'
),
array(
'field'=>'contact',
'label'=>'Contacto',
'rules'=>'trim|required|numeric|callback_min_lenght_9'
),
array(
'field'=>'address',
'label'=>'Morada',
'rules'=>'trim|required|callback_adress_check|callback_min_lenght_9'
),
array(
'field'=>'postalCODE',
'label'=>'Codigo Postal',
'rules'=>'trim|required|numeric]|callback_min_lenght_4'
),
array(
'field'=>'postalCODE2',
'label'=>'Codigo Postal',
'rules'=>'trim|required|numeric|callback_min_lenght_3'
),
array(
'field'=>'city',
'label'=>'Localidade',
'rules'=>'trim|required|callback_min_lenght_3|callback_city_check'
),
array(
'field'=>'taxpayerNUMBER',
'label'=>'N.º Contribuinte',
'rules'=>'trim|required|numeric|callback_min_lenght_9'
),
);
$this->form_validation->set_rules($config);
if($this->form_validation->run() == FALSE){//erro
$data['errors']=validation_errors();
} else {//registo
$data=array(
'username'=>$_POST['username'],
'userTYPE'=>'user',
'password'=>sha1($_POST['password']),
'email'=>$_POST['email'],
'active'=>$_POST['newsletter']==null?0:1,
'name'=>$_POST['name'],
'contact'=>$_POST['contact'],
'country'=>$_POST['country'],
'address'=>$_POST['address'],
'postalCODE'=>$_POST['postalCODE'],
'postalCODE2'=>$_POST['postalCODE2'],
'city'=>$_POST['city'],
'taxpayerNUMBER'=>$_POST['taxpayerNUMBER']
);
$userid = $this->user->create_user($data);
$data_init=array(
'userID'=>$userid['userID'],
'situation'=>0
);
$this->user->init_shop($data_init);//comecar encomendas
$this->session->set_userdata('userID',$userid['userID']);
$this->session->set_userdata('userTYPE',$userid['userTYPE']);//userTYPE
$this->session->set_userdata('userNAME',$userid['username']);
$this->session->set_userdata('newsletter',$_POST['newsletter']==null?0:1);
redirect(base_url().'/index.php/emails/email_to/'.$userid['userID']);
}
$data['page']="#fragment-3";
$this->load->view('header',$data);
$this->load->view('login',$data);
$this->load->view('footer');
} else {
redirect(base_url().'/index.php/');
}
}
Finnaly i have the View:
<div id="fragment-3">
<?php echo form_open(base_url().'index.php/users/register'); ?>
<div id="user_r"><?=form_label('Username','username')?><?php
$data_form=array(
'id'=>'username',
'name'=>'username',
'size'=>50,
'maxlength'=>'20',
'placeholder'=>'username',
);
?></div><div id="user_r_b"><?php echo form_input($data_form)?></div>
<div id="mail_r"><?=form_label('Email','email')?><?php
$data_form=array(
'id'=>'email',
'name'=>'email',
'size'=>50,
'maxlength'=>'40',
'placeholder'=>'email válido',
);
?></div><div id="mail_r_b"><?php echo form_input($data_form)?></div>
<div id="news_u"><?=form_label('Newsletter','newsletter')?><?php
$data_form=array(
'name'=>'newsletter',
'id'=>'newsletter',
'checked'=>TRUE,
'value'=>1,
'style'=>'margin:10px',
);
?></div>
<div id="news_u_b"><?php echo form_checkbox($data_form)?></div>
<div id="pass_1"><?=form_label('Password','password')?><?php
$data_form=array(
'name'=>'password',
'id'=>'password',
'size'=>50,
'maxlength'=>'20',
'placeholder'=>'minimo 6 caracteres',
);
?></div>
<div id="pass_1_b"><?php echo form_password($data_form)?></div>
<div id="pass_2"><?=form_label('Confirmar Pass','password2')?><?php
$data_form=array(
'name'=>'password2',
'id'=>'password2',
'size'=>50,
'maxlength'=>'20',
'placeholder'=>'minimo 6 caracteres',
);
?></div>
<div id="pass_2_b"><?php echo form_password($data_form)?></div>
<div id="name_r"><?=form_label('Nome','name')?><?php
$data_form=array(
'id'=>'name',
'name'=>'name',
'size'=>50,
'maxlength'=>'50',
'placeholder'=>'nome facturação',
);
?></div>
<div id="name_r_b"><?php echo form_input($data_form)?></div>
<div id="contact1"><?=form_label('Contacto','contact')?><?php
$data_form=array(
'id'=>'contact',
'name'=>'contact',
'size'=>24,
'maxlength'=>'9',
'placeholder'=>'n.º movel ou fixo',
'style'=>"padding-bottom : 0px;font-size:13px;"
);
?>
</div>
<div id="contact_b"><?php echo form_input($data_form)?></div>
<div id="pais"><?=form_label('Pais','country');?></div>
<div id="pais_b"><?php echo form_dropdown('country', $country); ?></div>
<div id="adres"><?=form_label('Morada','address')?><?php
$data_form=array(
'id'=>'address',
'name'=>'address',
'size'=>50,
'maxlength'=>'50',
'placeholder'=>'morada de facturação',
);
?></div><div id="adres_b"><?php echo form_input($data_form)?></div>
<div id="code"><?=form_label('Codigo Postal','postalCODE')?><?php
$data_form=array(
'id'=>'postalCODE',
'name'=>'postalCODE',
'size'=>6,
'maxlength'=>'6',
'placeholder'=>'1111',
);
?></div>
<div id="code1"><?php echo form_input($data_form)?> /</div>
<div id="code22"><?=form_label('','postalCODE2')?><?php
$data_form=array(
'id'=>'postalCODE2',
'name'=>'postalCODE2',
'size'=>5,
'maxlength'=>'5',
'placeholder'=>'111',
);
?></div><div id="code2"><?php echo form_input($data_form)?></div>
<div id="city2"><?=form_label('Localidade','city')?> <?php
$data_form=array(
'id'=>'city',
'name'=>'city',
'size'=>24,
'maxlength'=>'30',
'style'=>"padding-bottom : 0px;font-size:13px;",
'placeholder'=>'localidade facturação',
);
?></div><div id="city_b"><?php echo form_input($data_form)?></div>
<div id="number"><?=form_label('N.º Contribuinte','taxpayerNUMBER')?><?php
$data_form=array(
'id'=>'taxpayerNUMBER',
'name'=>'taxpayerNUMBER',
'size'=>24,
'maxlength'=>'9',
'placeholder'=>'numero contribuinte valido',
);
?></div><div id="number_b"><?php echo form_input($data_form)?></div>
<div id="botao"><?php echo form_submit('',' Registar '); ?></div>
<?php echo form_close(); ?>
</div>
I have here the form_helper part for the error:
if ( ! function_exists('form_dropdown'))
{
function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
{
if ( ! is_array($selected))
{
$selected = array($selected);
}
// If no selected state was submitted we will attempt to set it automatically
if (count($selected) === 0)
{
// If the form name appears in the $_POST array we have a winner!
if (isset($_POST[$name]))
{
$selected = array($_POST[$name]);
}
}
if ($extra != '') $extra = ' '.$extra;
$multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
$form = '<select name="'.$name.'"'.$extra.$multiple.">\n";
foreach ($options as $key => $val)
{
$key = (string) $key;
if (is_array($val) && ! empty($val))
{
$form .= '<optgroup label="'.$key.'">'."\n";
foreach ($val as $optgroup_key => $optgroup_val)
{
$sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : '';
$form .= '<option value="'.$optgroup_key.'"'.$sel.'>'.(string) $optgroup_val."</option>\n";
}
$form .= '</optgroup>'."\n";
}
else
{
$sel = (in_array($key, $selected)) ? ' selected="selected"' : '';
$form .= '<option value="'.$key.'"'.$sel.'>'.(string) $val."</option>\n";
}
}
$form .= '</select>';
return $form;
}
}
These are the 2 errors
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: country
Filename: views/login.php
Line Number: 143
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: helpers/form_helper.php
Line Number: 331
Hope someone can help me
Thanks :)

your problem is simple, in this part of code:
} else {//registo
$data=array(
'username'=>$_POST['username'],
you're reseting $data to a new array. For a simple solution, use array_merge():
} else {//registo
$additional_data=array(
'username'=>$_POST['username'],
'userTYPE'=>'user',
'password'=>sha1($_POST['password']),
'email'=>$_POST['email'],
'active'=>$_POST['newsletter']==null?0:1,
'name'=>$_POST['name'],
'contact'=>$_POST['contact'],
'country'=>$_POST['country'],
'address'=>$_POST['address'],
'postalCODE'=>$_POST['postalCODE'],
'postalCODE2'=>$_POST['postalCODE2'],
'city'=>$_POST['city'],
'taxpayerNUMBER'=>$_POST['taxpayerNUMBER']
);
array_merge($data, $additional_data);

Related

How to get value from checkbox and post array in codeigniter?

How to get value form multiples checkbox and post array in codeigniter? I have problem when I get value post array and echo the value. I see only the value of the last checked checkbox. How to show post value when submit?
You find three files: view, Controller and Model. Please check where I wrong...
UPDATE.PHP:
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<div class="row">
<div class="col-sm-12">
<?php echo form_open('page_controller/update_page_post'); ?>
<div class="form-group">
<div class="row">
<div class="col-sm-3 col-xs-12">
<label><?php echo trans('subcategory'); ?></label>
</div>
</div><div class="col-xm-12">
<div class="table-responsive">
<table class="table table-bordered table-striped" role="grid">
<tbody>
<tr>
<?php $valuesub = ($page->subcat_recip_id); ?>
<?php $array_of_values = explode(",", $valuesub);
//if ($item['parent_id'] != "0" && $item['subcat_recip_id'] == "0") :
foreach ($array_of_values as $item) {
if(in_array($subcat_recip_id,$item)): { ?>
<td>
<input type="checkbox" name="subcat_recip_id[]" class="square-purple" value="<?php echo html_escape($item["title"]); ?>" CHECKED> <?php echo html_escape($item["title"]);
} ?>
<?php else: { ?>
<input type="checkbox" name="subcat_recip_id[]" class="square-purple" value="<?php echo html_escape($item["title"]); ?>"> <?php echo html_escape($item["title"]);
}
endif; }?>
</td>
<?php echo html_escape($valuesub); ?></tr>
</tbody>
</table>
</div>
</div>
</div>
PAGE_MODEL.PHP:
<?php class Page_model extends CI_Model
{
public function input_values()
{
$data = array(
'lang_id' => $this->input->post('lang_id', true),
'title' => $this->input->post('title', true),
'slug' => $this->input->post('slug', true),
'page_description' => $this->input->post('page_description', true),
'page_keywords' => $this->input->post('page_keywords', true),
'page_content' => $this->input->post('page_content', false),
'parent_id' => $this->input->post('parent_id', true),
'page_active' => $this->input->post('page_active', true),
'title_active' => $this->input->post('title_active', true),
'breadcrumb_active' => $this->input->post('breadcrumb_active', true),
'need_auth' => $this->input->post('need_auth', true),
'howmany_people' => $this->input->post('howmany_people', true),
'difficulty' => $this->input->post('difficulty', true),
'howmany_time' => $this->input->post('howmany_time', true),
'location' => $this->input->post('location', true),
'subcat_recip_id' => $this->input->post('subcat_recip_id')
for ($i=0; $i<count($menu_links); $i++)
{
echo $subcat_recip_id[$i];
}
);
return $data;
}
//add page
public function add()
{
$data = $this->page_model->input_values();
if (empty($data["slug"]))
{
//slug for title
$data["slug"] = str_slug($data["title"]);
if (empty($data["slug"]))
{
$data["slug"] = "page-" . uniqid();
}
}
return $this->db->insert('pages', $data);
}
//update page
public function update($id)
{
//set values
$data = $this->page_model->input_values();
if (empty($data["slug"])) {
//slug for title
$data["slug"] = str_slug($data["title"]);
if (empty($data["slug"])) {
$data["slug"] = "page-" . uniqid();
}
}
$page = $this->get_page_by_id($id);
if (!empty($page)) {
$this->db->where('id', $id);
return $this->db->update('pages', $data);
}
return false;
}
PAGE_CONTROLLER.PHP
* Add Page Post*/
public function add_page_post()
{
//validate inputs
$this->form_validation->set_rules('title', trans("title"), 'required|xss_clean|max_length[500]');
if ($this->form_validation->run() === false) {
$this->session->set_flashdata('errors', validation_errors());
$this->session->set_flashdata('form_data', $this->page_model->input_values());
redirect($this->agent->referrer());
} else {
if (!$this->page_model->check_page_name()) {
$this->session->set_flashdata('form_data', $this->page_model->input_values());
$this->session->set_flashdata('error', trans("msg_page_slug_error"));
redirect($this->agent->referrer());
exit();
}
if ($this->page_model->add()) {
$this->session->set_flashdata('success', trans("page") . " " . trans("msg_suc_added"));
redirect($this->agent->referrer());
} else {
$this->session->set_flashdata('form_data', $this->page_model->input_values());
$this->session->set_flashdata('error', trans("msg_error"));
redirect($this->agent->referrer());
}
}
}
I have tried this code
in your Page_model put this code.
public function input_values(){
$checkbox = implode(',', $this->checkBox());
$data = array(
'lang_id' => $this->input->post('lang_id', true),
'title' => $this->input->post('title', true),
'slug' => $this->input->post('slug', true),
'page_description' => $this->input->post('page_description', true),
'page_keywords' => $this->input->post('page_keywords', true),
'page_content' => $this->input->post('page_content', false),
'parent_id' => $this->input->post('parent_id', true),
'page_active' => $this->input->post('page_active', true),
'title_active' => $this->input->post('title_active', true),
'breadcrumb_active' => $this->input->post('breadcrumb_active', true),
'need_auth' => $this->input->post('need_auth', true),
'howmany_people' => $this->input->post('howmany_people', true),
'difficulty' => $this->input->post('difficulty', true),
'howmany_time' => $this->input->post('howmany_time', true),
'location' => $this->input->post('location', true),
'subcat_recip_id' => $checkbox
);
}
public function checkBox(){
$count = count($_POST['subcat_recip_id']);
for($n=0; $n<$count; $n++){
$checkbox[$n] = $_POST['subcat_recip_id'][$n];
}
return $checkbox;
}
hopefully it helps
This is what $menu_links is:
public function get_menu_links_by_lang()
{
$lang_id = $this->input->post('lang_id', true);
if (!empty($lang_id)):
$menu_links = $this->navigation_model->get_menu_links_by_lang($lang_id);
foreach ($menu_links as $item):
if ($item["type"] != "category" && $item["location"] == "header" && $item['parent_id'] == "0"):
echo ' <option value="' . $item["id"] . '">' . $item["title"] . '</option>';
endif;
endforeach;
endif;
}
I edited a code to insert new form page and I need this page to enter some values into DB. All works Ok and they inserted to DB, only the checkbox doesn't work or better it take only the value of the last checked checkbox and not all the checkbox checked! I have tried it in many ways but I can't do it alone. Sorry.

Add get parameter to URL, using form_open function?

I tried to implement standard PHP logic for add, edit articles to blog, so i have add method:
public function add()
{
$this->load->model('admin/Blog_Model');
if (!empty($this->input->post())) {
$user = $this->Blog_Model->addPost($this->input->post());
}
$this->getForm();
}
edit method:
public function edit($id = '')
{
$this->load->model('admin/Blog_Model');
if (!empty($this->input->post())) {
var_dump($id); exit;
$user = $this->Blog_Model->editPost($this->input->post(), $id);
}
$this->getForm($id);
}
and getForm method:
public function getForm($id = '')
{
if (!empty($id)) {
$post = $this->Blog_Model->getPost($id);
$data['action'] = 'admin/blog/edit';
} else {
$data['action'] = 'admin/blog/add';
}
$data['formTitle'] = array(
'name' => 'title',
'id' => 'content-title',
'value' => isset($post['title']) ? $post['title'] : '',
'placeholder' => 'Заглавие',
'class' => 'form-control'
);
$data['formContent'] = array(
'name' => 'content',
'id' => 'content-blog',
'value' => isset($post['content']) ? $post['content'] : '',
'placeholder' => 'Съдържание',
);
$data['formButton'] = array(
'type' => 'submit',
'content'=> 'Изпрати',
'class'=> 'btn btn-primary btn-block btn-flat'
);
$data['head'] = $this->load->view('admin/head', NULL, TRUE);
$data['left_column'] = $this->load->view('admin/left_column', NULL, TRUE);
$this->load->view('admin/header', $data);
$this->load->view('admin/blog_form', $data);
$this->load->view('admin/footer');
}
and blog_form view with form:
<div class="box-body pad">
<?php echo form_open($action); ?>
<div class="box-body">
<div class="form-group">
<label for="content-title">Заглавие:</label>
<?php echo form_input($formTitle); ?>
</div>
<div class="form-group">
<label for="content_blog">Съдържание:</label>
<?php echo form_textarea($formContent); ?>
</div>
<div class="col-xs-12 col-md-3 pull-right">
<?php echo form_button($formButton); ?>
</div>
</div>
<?php echo form_close(); ?>
</div>
So .. everything works perfect, but i have problem with this part:
if (!empty($id)) {
$post = $this->Blog_Model->getPost($id);
$data['action'] = 'admin/blog/edit';
} else {
$data['action'] = 'admin/blog/add';
}
if it's edit i want to send id like GET parameter. I think the problem is there than i does not use standard GET parameters instead of site_url function, when i show all articles here:
<?php foreach ($posts as $post) { ?>
<tr>
<td><?php echo $post['id']; ?></td>
<td><?php echo $post['title']; ?></td>
<td><?php echo $post['content']; ?></td>
<td><div class="btn-group">
Редактирай
Изтрий
</div></td>
</tr>
<?php } ?>
Try to change
if (!empty($id)) {
$post = $this->Blog_Model->getPost($id);
$data['action'] = 'admin/blog/edit';
} else {
$data['action'] = 'admin/blog/add';
}
to
if (!empty($id)) {
$post = $this->Blog_Model->getPost($id);
$data['action'] = 'admin/blog/edit/'.$id; // pass $id to edit controller
} else {
$data['action'] = 'admin/blog/add';
}

WordPress pop-up notification close button not working

I am having a trouble with my website's pop-up widget. The problem is the pop-up appears when you enter or refresh the website but I can not close it. I click on the "X" button but nothing happens. The code:
<?php
/*
Plugin Name: WP Welcome Message
Plugin URI: http://www.a1netsolutions.com/Products/WP-Welcome-Message
Description: <strong>WP Welcome Message</strong> is a wordpress plugin, which help your to make any announcement, special events, special offer, signup message or such kind of message, displayed upon your website's visitors when the page is load through a popup box.
Version: 3.0
Author: Ahsanul Kabir
Author URI: http://www.ahsanulkabir.com/
License: GPL2
License URI: license.txt
*/
$wpwm_conf = array(
'VERSION' => get_bloginfo('version'),
'VEWPATH' => plugins_url('lib/', __FILE__),
);
function wpwm_admin_styles()
{
global $wpwm_conf;
wp_enqueue_style('wpwm_admin_styles',($wpwm_conf["VEWPATH"].'css/admin.css'));
if( $wpwm_conf["VERSION"] > 3.7 )
{
wp_enqueue_style('wpwm_icon_styles',($wpwm_conf["VEWPATH"].'css/icon.css'));
}
}
add_action('admin_print_styles', 'wpwm_admin_styles');
function wpwm_scripts_styles()
{
global $wpwm_conf;
$wpwmBoxSetly = get_option('wpwm_boxsetly');
if(!$wpwmBoxSetly){$wpwmBoxSetly=="fadeOut";}
wp_enqueue_script('wpwm_site_scripts',($wpwm_conf["VEWPATH"].'js/site_'.$wpwmBoxSetly.'.js'),array('jquery'),'',true);
wp_enqueue_style('wpwm_site_style',($wpwm_conf["VEWPATH"].'css/site.css'));
}
add_action('wp_enqueue_scripts', 'wpwm_scripts_styles');
function wpwm_defaults()
{
$wpwm_default = plugin_dir_path( __FILE__ ).'lib/default.php';
if(is_file($wpwm_default))
{
require $wpwm_default;
foreach($default as $k => $v)
{
$vold = get_option($k);
if(!$vold)
{
update_option($k, $v);
}
}
if(!is_multisite())
{
unlink($wpwm_default);
}
}
}
function wpwm_activate()
{
$wpwm_postsid = get_option( 'wpwm_postsid' );
if(!$wpwm_postsid)
{
$inputContent = 'Welcome to '.get_bloginfo('name').', '. get_bloginfo('description');
$new_post_id = wpwm_printCreatePost($inputContent);
update_option( 'wpwm_postsid', $new_post_id );
}
wpwm_defaults();
}
function wpwm_redirect()
{
$wpwm_fv = get_option('wpwm_fv');
if($wpwm_fv != 'fv')
{
echo 'Please setup your <strong>WP Welcome Message 2.0</strong> plugin. <input type="submit" value="Setup" class="button" />';
}
}
add_action( 'admin_footer', 'wpwm_redirect' );
function wpwm_admin_menu()
{
global $wpwm_conf;
if( $wpwm_conf["VERSION"] < 3.8 )
{
add_menu_page('WP Welcome Message', 'Welcome Msg', 'manage_options', 'wpwm_admin_page', 'wpwm_admin_function', (plugins_url('lib/img/icon.png', __FILE__)));
}
else
{
add_menu_page('WP Welcome Message', 'Welcome Msg', 'manage_options', 'wpwm_admin_page', 'wpwm_admin_function');
}
}
add_action('admin_menu', 'wpwm_admin_menu');
function wpwm_select( $iget, $iset, $itxt )
{
if( $iget == $iset )
{
echo '<option value="'.$iset.'" selected="selected">'.$itxt.'</option>';
}
else
{
echo '<option value="'.$iset.'">'.$itxt.'</option>';
}
}
function wpwm_update($key, $value)
{
if(isset($value) && !empty($value))
{
update_option($key, $value);
}
}
function wpwm_admin_function()
{
$wpwm_fv = get_option('wpwm_fv');
if($wpwm_fv != 'fv')
{
update_option('wpwm_fv', 'fv');
}
wpwm_update('wpwm_loc', $_POST["wpwm_loc"]);
wpwm_update('wpwm_log', $_POST["wpwm_log"]);
wpwm_update('wpwm_boxsetly', $_POST["wpwm_boxsetly"]);
wpwm_update('wpwm_bgstyle', $_POST["wpwm_bgstyle"]);
wpwm_update('wpwmTemplate', $_POST["wpwmTemplate"]);
wpwm_update('wpwm_onlyFirstVisit', $_POST["wpwm_onlyFirstVisit"]);
wpwm_update('wpwm_ststs', $_POST["wpwm_ststs"]);
$wpwmPID = get_option('wpwm_postsid');
wpwm_updatePost($_POST["wpwmeditor"], $wpwmPID);
if( isset($_POST["wpwmeditor"]) || isset($_POST["wpwmTemplate"]) )
{
echo '<div id="message" class="updated wpwm_updated"><p>Your data has been successfully saved.</p></div>';
}
global $wpwm_conf;
echo '<div id="wpwm_container">
<div id="wpwm_main">
<img src="',$wpwm_conf["VEWPATH"],'/img/uvg.png" id="wpwm_uvg" />
<h1 id="wpwm_page_title">WP Welcome Message</h1>';
?>
<div class="wpwm_box">
<div class="wpwm_box_title">Your Welcome Message
<form method="post" action="" id="wpwm_off_on"><input type="hidden" name="wpwm_ststs" value="<?php
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'on')
{
echo 'off';
}
else
{
echo 'on';
}
?>" /><input type="image" src="<?php echo $wpwm_conf["VEWPATH"]; ?>/img/<?php
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'on')
{
echo 'one-check_yes';
}
else
{
echo 'one-check_no';
}
?>.png" /></form>
</div>
<div class="wpwm_box_con">
<form method="post" action="" id="wpwm_content_form">
<?php
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'off')
{
echo '<div id="wpwm_content_disable"></div>';
}
$wpwmPID = get_option('wpwm_postsid');
$wpwmContent = get_post($wpwmPID);
$wpwmContent = $wpwmContent->post_content;
$wpwmContent = apply_filters('the_content', $wpwmContent);
$wpwmContent = str_replace(']]>', ']]>', $wpwmContent);
if( $wpwm_conf["VERSION"] < 3.3 )
{
echo '<textarea name="wpwmeditor" style="width:100%; height:300px;"></textarea>';
}
else
{
wp_editor( $wpwmContent, 'wpwmeditor', array('textarea_rows' => 20, 'textarea_name' => 'wpwmeditor') );
}
?>
<input type="submit" value="save changes" />
</form>
</div>
</div>
<div class="wpwm_box">
<div class="wpwm_box_title">Settings</div>
<div class="wpwm_box_con">
<form method="post" action="">
<div class="row">
<label>On Which Page/Pages to Display : </label>
<select name="wpwm_loc">
<?php
$wpwmLoc = get_option( 'wpwm_loc' );
wpwm_select( $wpwmLoc, 'home', 'Home Page Only' );
wpwm_select( $wpwmLoc, 'all', 'All Pages' );
?>
</select>
</div>
<div class="row">
<label>Logged-in / Not Logged-in user : </label>
<select name="wpwm_log">
<?php
$wpwm_log = get_option( 'wpwm_log' );
wpwm_select( $wpwm_log, 'log', 'Logged-in Users Only' );
wpwm_select( $wpwm_log, 'nlog', 'Not Logged-in Users Only' );
wpwm_select( $wpwm_log, 'all', 'For All' );
?>
</select>
</div>
<div class="row">
<label>Message Box Animation Style : </label>
<select name="wpwm_boxsetly">
<?php
$wpwmBoxSetly = get_option( 'wpwm_boxsetly' );
wpwm_select( $wpwmBoxSetly, 'fadeOut', 'Fade Out' );
wpwm_select( $wpwmBoxSetly, 'slideUp', 'Slide Up' );
?>
</select>
</div>
<div class="row">
<label>Template : </label>
<select name="wpwmTemplate">
<?php
$wpwmTemplate = get_option( 'wpwmTemplate' );
wpwm_select( $wpwmTemplate, 'black-color', 'Dark Color Only' );
wpwm_select( $wpwmTemplate, 'black-white-color', 'White Color Only' );
wpwm_select( $wpwmTemplate, 'white-color', 'Full White Color Only' );
wpwm_select( $wpwmTemplate, 'black-striped', 'Dark Stripes' );
wpwm_select( $wpwmTemplate, 'black-white-striped', 'White Stripes' );
wpwm_select( $wpwmTemplate, 'white-striped', 'Full White Stripes' );
wpwm_select( $wpwmTemplate, 'bootstrap', 'Bootstrap Style' );
?>
</select>
</div>
<div class="row">
<label>Only For Fist Time Visit : </label>
<select name="wpwm_onlyFirstVisit">
<?php
$wpwm_onlyFirstVisit = get_option( 'wpwm_onlyFirstVisit' );
wpwm_select( $wpwm_onlyFirstVisit, 'on', 'Enable' );
wpwm_select( $wpwm_onlyFirstVisit, 'off', 'Disable' );
?>
</select>
</div>
<input type="submit" value="save changes" />
</form>
</div>
</div>
<?php
echo '</div>
<div id="wpwm_side">
<div class="wpwm_box">';
echo '<img src="',$wpwm_conf["VEWPATH"],'/img/wp-advert-1.png" />';
echo '</div><div class="wpwm_box">';
echo '<img src="',$wpwm_conf["VEWPATH"],'/img/wp-advert-2.png" />';
echo '</div>
</div>
<div class="wpwm_clr"></div>
</div>';
}
function wpwm_content()
{
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'on')
{
$wpwm_onlyFirstVisit = get_option( 'wpwm_onlyFirstVisit' );
if( $wpwm_onlyFirstVisit == "on" )
{
if( (!isset($_SESSION["wpwm_session"])) || ($_SESSION["wpwm_session"] != 'off') )
{
wpwm_popupFirst();
}
}
else
{
wpwm_popupFirst();
}
}
}
function wpwm_popupFirst()
{
$wpwm_loc = get_option( 'wpwm_log' );
if(get_option('wpwm_ststs') == 'on')
{
if( $wpwm_loc == 'log' )
{
if ( is_user_logged_in() )
{
wpwm_popupCheckPage();
}
}
elseif( $wpwm_loc == 'nlog' )
{
if ( !is_user_logged_in() )
{
wpwm_popupCheckPage();
}
}
else
{
wpwm_popupCheckPage();
}
}
}
function wpwm_popupTemp()
{
$wpwmPID = get_option( 'wpwm_postsid' );
$wpwmTemplate = get_option('wpwmTemplate');
$content_post = get_post($wpwmPID);
$wpwmContent = $content_post->post_content;
$wpwmContent = apply_filters('the_content', $wpwmContent);
$wpwmContent = str_replace(']]>', ']]>', $wpwmContent);
$session_id = session_id();
echo '
<div id="wpwm_hideBody" class="'.$wpwmTemplate.'-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
'.$wpwmContent.'
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery("html, body").css({"overflow": "hidden"});
});
</script>
';
echo '<span>',get_option('wpwm_dev1'),get_option('wpwm_dev2'),get_option('wpwm_dev3'),'</span>';
}
function wpwm_popupCheckPage()
{
if( ( get_option( 'wpwm_loc' ) ) == 'home' )
{
if( is_front_page() )
{
wpwm_popupTemp();
}
}
else
{
wpwm_popupTemp();
}
}
function wpwm_sessionID()
{
if(!isset($_SESSION)){session_start();}
if(isset($_SESSION["wpwm_session"]))
{
$_SESSION["wpwm_session"] = 'off';
}
else
{
$_SESSION["wpwm_session"] = 'on';
}
}
add_action( 'wp_head', 'wpwm_sessionID' );
function wpwm_posts_init()
{
$args = array
(
'public' => false,
'publicly_queryable' => false,
'show_ui' => false,
'show_in_menu' => false,
'rewrite' => array( 'slug' => 'wpwmposts' ),
'capability_type' => 'post',
'has_archive' => false,
'supports' => array( 'title', 'editor', 'excerpt' )
);
register_post_type( 'wpwmposts', $args );
}
add_action( 'init', 'wpwm_posts_init' );
function wpwm_getCurrentUser()
{
if (function_exists('wp_get_current_user'))
{
return wp_get_current_user();
}
else if (function_exists('get_currentuserinfo'))
{
global $userdata;
get_currentuserinfo();
return $userdata;
}
else
{
$user_login = $_COOKIE["USER_COOKIE"];
$current_user = $wpdb->get_results("SELECT * FROM `".$wpdb->users."` WHERE `user_login` = '".$user_login."' ;");
return $current_user;
}
}
function wpwm_printCreatePost($inputContent)
{
$newPostAuthor = wpwm_getCurrentUser();
$newPostArg = array
(
'post_author' => $newPostAuthor->ID,
'post_content' => $inputContent,
'post_status' => 'publish',
'post_type' => 'wpwmposts'
);
$new_post_id = wp_insert_post($newPostArg);
return $new_post_id;
}
function wpwm_updatePost($inputContent, $id)
{
$newPostAuthor = wpwm_getCurrentUser();
$newPostArg = array
(
'ID' => $id,
'post_author' => $newPostAuthor->ID,
'post_content' => $inputContent,
'post_status' => 'publish',
'post_type' => 'wpwmposts'
);
$new_post_id = wp_insert_post($newPostArg);
return $new_post_id;
}
add_action('wp_footer', 'wpwm_content', 100);
register_activation_hook(__FILE__, 'wpwm_activate');
?>
Finally, I managed to find where the problem is.
echo '
<div id="wpwm_hideBody" class="'.$wpwmTemplate.'-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
'.$wpwmContent.'
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery("html, body").css({"overflow": "hidden"});
});
</script>
';
And find out there is no close function going on here:
<span id="wpwm_popClose">×</span>
So changed it with this:
<span id="wpwm_popClose" onclick="document.getElementById('pwm_hideBody').style.display='none'">×</span>
but when I edit this PHP code, WordPress gives me this error:
Parse error: syntax error, unexpected 'pwm_hideBody' (T_STRING), expecting ',' or ';' in /var/www/vhosts/derinuzay.org/httpdocs/wp-content/plugins/wp-welcome-message/wp-welcome-message.php on line 337
Could you please help me out about this error?
Try to add this:
jQuery('#wpwm_popClose').click(function() {
jQuery('#wpwm_hideBody').css('display', 'none');
});
inside the:
jQuery(document).ready(function() {
jQuery("html, body").css({"overflow": "hidden"});
});
What happens if you replace
echo '
<div id="wpwm_hideBody" class="'.$wpwmTemplate.'-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
'.$wpwmContent.'
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery("html, body").css({"overflow": "hidden"});
});
</script>
';
With:
?>
<div id="wpwm_hideBody" class="<?php echo $wpwmTemplate; ?>-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
<?php echo $wpwmContent; ?>
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#wpwm_popClose').click(function() {
jQuery('#wpwm_hideBody').css('display', 'none');
});
});
</script>
<?php

content/admin banner different language

I can add images to various languages in OpenCart 1.5.6 version, this is how much you probably know pavcontentslider, I have the opportunity to do different languages but not text and image .. if anyone can help me I would be grateful. Thank you
Printscreen: http://postimg.org/image/v6nrcebrf/
code admin interface:
<?php
class ControllerModulePavcontentslider extends Controller {
private $error = array();
public function index() {
$this->language->load('module/pavcontentslider');
$this->load->model('tool/image');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/setting');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->request->post['pavcontentslider_module'][0]['banner_image'] = $this->request->post['banner_image'];
unset($this->request->post['banner_image']);
$this->model_setting_setting->editSetting('pavcontentslider', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->redirect($this->url->link('module/pavcontentslider', 'token=' . $this->session->data['token'], 'SSL'));
}
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_image_manager'] = $this->language->get('text_image_manager');
$this->data['text_browse'] = $this->language->get('text_browse');
$this->data['text_clear'] = $this->language->get('text_clear');
$this->data['text_enabled'] = $this->language->get('text_enabled');
$this->data['text_disabled'] = $this->language->get('text_disabled');
$this->data['text_content_top'] = $this->language->get('text_content_top');
$this->data['text_content_bottom'] = $this->language->get('text_content_bottom');
$this->data['text_column_left'] = $this->language->get('text_column_left');
$this->data['text_column_right'] = $this->language->get('text_column_right');
$this->data['entry_title'] = $this->language->get('entry_title');
$this->data['entry_width'] = $this->language->get('entry_width');
$this->data['entry_height'] = $this->language->get('entry_height');
$this->data['entry_description'] = $this->language->get('entry_description');
$this->data['entry_layout'] = $this->language->get('entry_layout');
$this->data['entry_position'] = $this->language->get('entry_position');
$this->data['entry_status'] = $this->language->get('entry_status');
$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
$this->data['button_save'] = $this->language->get('button_save');
$this->data['button_cancel'] = $this->language->get('button_cancel');
$this->data['button_add_module'] = $this->language->get('button_add_module');
$this->data['button_remove'] = $this->language->get('button_remove');
$this->data['no_image'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
$this->data['entry_show_image'] = $this->language->get( 'entry_show_image' );
$this->data['entry_module_title'] = $this->language->get( 'entry_module_title' );
$this->data['tab_module'] = $this->language->get('tab_module_banner');
$this->data['entry_image_navigator'] = $this->language->get( 'entry_image_navigator' );
$this->data['entry_navigator_width'] = $this->language->get( 'entry_navigator_width' );
$this->data['entry_navigator_height'] = $this->language->get( 'entry_navigator_height' );
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('module/pavcontentslider', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['action'] = $this->url->link('module/pavcontentslider', 'token=' . $this->session->data['token'], 'SSL');
$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
$this->data['token'] = $this->session->data['token'];
$this->data['modules'] = array();
$this->data['positions'] = array( 'mainmenu',
'slideshow',
'promotion',
'content_top',
'column_left',
'column_right',
'content_bottom',
'mass_bottom',
'footer_top',
'footer_center',
'footer_bottom'
);
$d = array('layout_id'=>'','position'=>'','status'=>'','sort_order'=>'1',
'banner_image'=>array(),'width'=>940,'height'=>350,
'image_navigator' => 0,
'navimg_height' =>97,
'navimg_weight' =>177,
'text_interval'=>8000
);
$this->data['effects'] = array('slideUp','slideDown','slideLeft',
'slideRight','slideExpandUp','expandUp','fadeIn',
'expandOpen','bigEntrance','hatch','bounce',
'pulse','floating','tossing','pullUp','pullDown','stretchLeft','stretchRight'
);
if (isset($this->request->post['pavcontentslider_module'])) {
$this->data['modules'] = $this->request->post['pavcontentslider_module'];
} elseif ($this->config->get('pavcontentslider_module')) {
$this->data['modules'] = $this->config->get('pavcontentslider_module');
}
if( !empty($this->data['modules']) ){
$d = array_merge($d,$this->data['modules'][0]);
}
$this->data['module'] = $d;
if( $d['banner_image'] ){
$tmp = array();$i=1;
foreach( $d['banner_image'] as $key => $banner ){
$banner['link'] = isset($banner['link'])?trim($banner['link']):"";
$banner['thumb'] = $this->model_tool_image->resize($banner['image'], 100, 100);
$tmp[$i++] = $banner;
}
$d['banner_image'] = $tmp;
}
$this->data['banner_image'] = $d['banner_image'];
$this->load->model('design/layout');
$this->data['layouts'][] = array('layout_id'=>99999, 'name' => $this->language->get('all_page') );
$this->data['layouts'] = array_merge($this->data['layouts'],$this->model_design_layout->getLayouts());
$this->load->model('localisation/language');
$this->data['languages'] = $this->model_localisation_language->getLanguages();
$this->document->addStyle('view/stylesheet/pavcontentslider.css');
$this->template = 'module/pavcontentslider.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
public function typo(){
if (isset($this->request->get['field'])) {
$this->data['field'] = $this->request->get['field'];
} else {
$this->data['field'] = '';
}
$typoFile = HTTP_CATALOG."catalog/view/theme/default/stylesheet/pavcontentslider.css";
if( file_exists( DIR_CATALOG ."view/theme/". $this->config->get('config_template')."/stylesheet/pavcontentslider.css" ) ){
$typoFile = HTTP_CATALOG."catalog/view/theme/". $this->config->get('config_template')."/stylesheet/pavcontentslider.css";
}
$content = file_get_contents( $typoFile );
$this->data['typoFile'] = $typoFile;
$data = preg_match_all("#\.pav-caption\.([\w\-]+)\s*{\s*#", $content, $matches);
$this->data['captions'] = array();
if( isset($matches[1]) ){
$this->data['captions'] = $matches[1];
}
$this->template = 'module/pavcontentslider_typo.tpl';
$this->response->setOutput($this->render());
}
protected function validate() {
if (!$this->user->hasPermission('modify', 'module/pavcontentslider')) {
$this->error['warning'] = $this->language->get('error_permission');
}
if( !isset($this->request->post['banner_image']) ){
$this->error['warning'] = $this->language->get('error_missing_banner');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}
?>
home interface:
<?php if( count($banners) ) { ?>
<?php $id = rand(1,10);?>
<div id="pavcontentslider<?php echo $id;?>" class="carousel slide pavcontentslider">
<div class="carousel-inner">
<?php foreach ($banners as $i => $banner) { ?>
<div class="item <?php if($i==0) {?>active<?php } ?>">
<?php if ($banner['link']) { ?>
<img src="<?php echo $banner['thumb']; ?>" alt="<?php echo $banner['title']; ?>" />
<?php } else { ?>
<img src="<?php echo $banner['thumb']; ?>" alt="<?php echo $banner['title']; ?>" />
<?php } ?>
<?php if( isset($banner['layers']) && $banner['layers'] ) { ?>
<?php foreach( $banner['layers'] as $layer ) { ?>
<div class="pav-caption <?php echo $layer['effect']. " ".$layer['class'];?>" style="top:<?php echo (int)$layer['top']?>px;left:<?php echo (int)$layer['left']?>px">
<?php echo $layer['caption'];?>
</div>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
</div>
<?php if( count($banners) > 1 ){ ?>
<a class="carousel-control left " href="#pavcontentslider<?php echo $id;?>" data-slide="prev">‹</a>
<a class="carousel-control right" href="#pavcontentslider<?php echo $id;?>" data-slide="next">›</a>
<?php } ?>
<?php if( count($banners) > 1 ) { ?>
<?php if( isset($setting['image_navigator']) && $setting['image_navigator'] ) { ?>
<ol class="carousel-indicators thumb-indicators hidden-phone ">
<?php foreach ( $banners as $j=>$item ) : ?>
<li data-target="#pavcontentslider<?php echo $id;?>" data-slide-to="<?php echo $j;?>" class="<?php if($j==0) {?>active<?php } ?>">
<img src="<?php echo $item['image_navigator'];?>"/>
</li>
<?php endforeach ?>
</ol>
<?php } else { ?>
<ol class="carousel-indicators">
<?php foreach ( $banners as $j=>$item ) : ?>
<li data-target="#pavcontentslider<?php echo $id;?>" data-slide-to="<?php echo $j;?>" class="<?php if($j==0) {?>active<?php } ?>"></li>
<?php endforeach ?>
</ol>
<?php } ?>
<?php } ?>
</div>
<?php if( count($banners) > 1 ){ ?>
<script type="text/javascript">
<!--
$('#pavcontentslider<?php echo $id;?>').carousel({interval:8000});
-->
</script>
<?php } ?>
<?php } ?>

Dynamic User Profile management in yii?

I have two tables in database profile_fields and profile_fields_values.
Table profile_fields has columns
id
fieldname
fieldtitle
fieldtype
orderby
required
published
Table profile_field_values has columns
id
field_id
user_id
field_value
Here I have to create a dynamic profile management.
How do I show dynamic forms in Yii?
You need to use Form Builder, it has plenty of example how to construct your form using an array. It also supports sub-forms. Just follow the examples from the linked tutorial, content it's to long to be referenced here.
Update:
class LoginForm extends CFormModel
{
public $username;
public $password;
}
$form = new LoginForm();
$form->validatorList->add(
CValidator::createValidator('required', $form, 'username, password')
);
or another example:
class SomeModel
{
public $orders;
public function rules()
{
return array(
array('orders', 'validateOrders'),
);
}
public function validateOrders($attribute, $params)
{
foreach($this->orders as $order)
if (empty($order)) {
$this->addError('orders', 'There is an empty order');
break;
}
}
}
A more broader example is on forum.
I am trying to build this dynamic profile management let me know my approach is my approach is right?
firstly i have created a input form(_form) where user can input fieldtype,fieldname,fieldtitle and field default value and etc which can be save in database table (profile_fields).In this fieldtype is bydefault set and user choose it from dropdownlist As like in the below form.
<?php
/* #var $this ProfileManagerController */
/* #var $model ProfileFields */
/* #var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'profile-fields-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'location'); ?>
<?php echo $form->dropDownList($model,'location',CHtml::listData(Countries::model()->findAll('',array('orderby' => 'countryName ASC')),'countryCode','countryName'), array('empty' => array("*" => 'For All Countries'))); ?>
<?php echo $form->error($model,'location'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'profile_type'); ?>
<?php echo $form->dropDownList($model,'profile_type',Yii::app()->params['userRoles'], array('empty' => array("*" => 'For All users')), array($model->profile_type)); ?>
<?php //echo $form->dropDownList($model, 'profile_type', Yii::app()->params['userRoles'], array($model->profile_type)); ?>
<?php echo $form->error($model,'profile_type'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'section'); ?>
<?php echo $form->dropDownList($model,'section',array('profile'=>'profileSection','basicdetails'=>'BasicDetails','contactdetails'=>'ContactDetails','imagedetails'=>'ImageDetails','clientdetails'=>'ClientDetails','tagdetails'=>'TagDetails','otherdetails'=>'OtherDetails','alldetails'=>'AllDetails')); ?>
<?php echo $form->error($model,'section'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'field_name'); ?>
<?php echo $form->textField($model,'field_name',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'field_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'field_title'); ?>
<?php echo $form->textField($model,'field_title',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'field_title'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'field_type'); ?>
<?php echo $form->dropDownList($model,'field_type',array('text' => 'Text','date' => 'Date','email' => 'Email', 'radio' => 'Radio','multiselect' => 'Multi Select Dropdown List','file'=>'File','checkbox'=>'CheckBox','hidden'=>'Hidden','select'=>'Dropdownlist','password'=>'Password','checkboxlist'=>'Checkboxlist','radiolist'=>'Radiolist','textarea'=>'TextArea'),array('options' => array($model->field_type => array('selected' => true)))); ?>
<?php echo $form->error($model,'field_type'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'field_default_value'); ?>
<?php echo $form->textArea($model,'field_default_value',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'field_default_value'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'required'); ?>
<?php echo $form->dropDownList($model, 'required', array('1' => 'Yes', '0' => 'No')); ?>
<?php echo $form->error($model,'required'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'published'); ?>
<?php echo $form->dropDownList($model, 'published', array('1' => 'Yes', '0' => 'No')); ?>
<?php echo $form->error($model,'published'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'order_by'); ?>
<?php echo $form->textField($model,'order_by'); ?>
<?php echo $form->error($model,'order_by'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
secondly I have created a view index file which will show dynamically what type of fieldstypes and fieldsname and field title are set by the user in profile_field table and call the extension created by me and then another user can input accordingly .and these values are save in profile_field_values table .
----------index file---------------
<div class="form">
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'completeProfile-form',
'htmlOptions' => array('enctype' => 'multipart/form-data'),
'enableAjaxValidation' => false,
'clientOptions' => array('validataOnSubmit' => true),
'enableClientValidation' => true,
));
?>
<?php
if (!empty($field_data)) {
foreach ($field_data as $field) {
$selectedOptions = '';
$def_value='';
$field_name = $field->field_name; // required field
$field_type = $field->field_type; // required field
$field_id = $field->id; // required field
//for validation
$req = $field->required == 1 ? 'required' : ''; // required if using validation
$email = $field->field_type == 'email' ? 'email' : ''; // required if using validation
$password = $field->field_type == 'password' ? 'password' : ''; // required if using validation
$class = array($req, $email, $password); // class must be array type, if no class found, send empty array
//values present in ProfileFieldsValues to populate
$value = ProfileFieldsValues::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'field_id' => $field->id));
// set html options
$htmlOptions = array();
$htmlOptions['class'] = implode(" ", $class);
$htmlOptions['value'] = $value ? $value->field_value : '';
// field array - Must SET
$fieldArray = array();
$fieldArray['model'] = $field;
$fieldArray['form'] = $form;
$fieldArray['field_type'] = $field_type;
$fieldArray['field_name'] = $field_name;
$fieldArray['field_id'] = $field_id;
$fieldArray['default_value'] = $value ? $value->field_value : $field->field_default_value;
//If input type field is dropdowlist for selecttion
if($field_type == 'select' ){
if(!empty($field->field_default_value)){
$my_string = preg_replace(array('/\n/'), '#PH#', $field->field_default_value );
$my_array = explode('#PH#', $my_string);
foreach($my_array as $my_arr){
$def=explode('|',$my_arr);
$def_value[$def[0]]=$def[1];
}
$fieldArray['select_box_array']=$def_value;
}else{
$fieldArray['select_box_array'] =$country;
}
$htmlOptions['prompt'] = 'SELECT ANY';
$value ? $htmlOptions['options']=array($value->field_value=>array('selected'=>'true')): $htmlOptions['prompt'] = 'SELECT ANY';
}
//if input type field is multiple select dropdownlist
if( $field_type == 'multiselect'){
if(!empty($field->field_default_value)){
$my_string = preg_replace(array('/\n/'), '#PH#', $field->field_default_value );
$my_array = explode('#PH#', $my_string);
foreach($my_array as $my_arr){
$def=explode('|',$my_arr);
$def_value[$def[0]]=$def[1];
}
$fieldArray['select_box_array']=$def_value;
}else{
$fieldArray['select_box_array'] =$country;
}
$htmlOptions['prompt'] = 'SELECT Multiple';
if(!empty($value)){
$field_valu= explode(',',$value->field_value);
foreach($field_valu as $eachValue){
$selectedOptions[$eachValue] = array('selected'=>'selected');
}
$htmlOptions['options']= $selectedOptions;
}
}
// if input type field is radio button
if ($field_type == 'radiolist') {
$fl = ProfileFieldsValues::model()->findByAttributes(array('field_id' => $field->id, 'user_id' => Yii::app()->user->id));
if(!empty($field->field_default_value)){
$my_string = preg_replace(array('/\n/'), '#PH#', $field->field_default_value );
$my_array = explode('#PH#', $my_string);
foreach($my_array as $my_arr){
$def=explode('|',$my_arr);
$def_value[$def[0]]=$def[1];
}
$fieldArray['radio_box_array']=$def_value;
}else{
$fieldArray['radio_box_array'] =array('hello','bye');
}
$value = $fl ? $fl->field_value : 0;
$htmlOptions = array('labelOptions' => array('style' => 'display:inline'), 'separator' => ' ','value' => $value);
}
//if input type field is checkbox list
if ($field_type == 'checkboxlist') {
$fl = ProfileFieldsValues::model()->findByAttributes(array('field_id' => $field->id, 'user_id' => Yii::app()->user->id));
if(!empty($field->field_default_value)){
$my_string = preg_replace(array('/\n/'), '#PH#', $field->field_default_value );
$my_array = explode('#PH#', $my_string);
foreach($my_array as $my_arr){
$def=explode('|',$my_arr);
$def_value[$def[0]]=$def[1];
}
$fieldArray['check_box_array']=$def_value;
}else{
$fieldArray['check_box_array'] =array('hello','bye');
}
$value = $fl ? (array)explode(",",$fl->field_value) : array(0);
$htmlOptions = array('labelOptions' => array('style' => 'display:inline'), 'separator' => ' ','value' => $value );
}
//if input type field is file
if ($field_type == 'file') {
$files = ProfileFieldsValues::model()->findByAttributes(array('field_id' => $field->id, 'user_id' => Yii::app()->user->id));
if(isset($files->field_value)){
echo CHtml::image(Yii::app()->request->baseUrl . '/images/user_images/' .$files->field_value, 'Image', array('class' => 'img-polaroid', 'width' => 200));
}
}
$fieldArray['htmlOptions'] = $htmlOptions;
if ($field->published == '1') {
if($field->field_type == 'checkbox' || $field->field_type == 'radio' ){ ?>
<div class="row">
<?php $this->widget('ext.dynamicFields.EDynamicFields', $fieldArray); ?>
<?php echo $field->field_title; ?>
<?php echo $form->error($field, $field->field_title); ?>
</div>
<?php }else{ ?>
<div class="row">
<?php echo $form->labelEx($field, $field->field_title); ?>
<?php $this->widget('ext.dynamicFields.EDynamicFields', $fieldArray); ?>
<?php echo $form->error($field, $field->field_title); ?>
</div>
<?php } ?>
<?php } ?>
<?php } ?>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php
}
$this->endWidget();
?>
</div><!-- form -->
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl(true) . '/js/jquery.validate.js'); ?>
<script type="text/javascript">
$("#completeProfile-form").validate({
});
</script>
I have created a extension for various input type fields like
1.text
2.email textbox
3.hidden input type field
4.textarea
5.dropdownlist
6. multiple select dropdownlist
7.password textfield
8.file
9.radiolist
10.radio button
11 checkbox
12checkboxlist
13 date field
<?php
/**
* Description of EDynamicFields
* It will show dynamic fields
*
* #author Gaurav Parashar
*/
class EDynamicFields extends CWidget {
public $field_type;
public $field_name;
public $field_id;
public $default_value;
public $select_box_array = array();
public $radio_box_array = array();
public $check_box_array = array();
public $htmlOptions = array();
public $model;
public $form;
public $select;
public function run() {
switch ($this->field_type) {
case 'text':
echo $this->form->textField($this->model, "field_name[$this->field_type][$this->field_id]", $this->htmlOptions);
break;
case 'email':
echo $this->form->textField($this->model, "field_name[$this->field_type][$this->field_id]", $this->htmlOptions);
break;
case 'hidden':
echo $this->form->hiddenField($this->model, "field_name[$this->field_type][$this->field_id]", $this->default_value);
break;
case 'textarea':
echo $this->form->textArea($this->model, "field_name[$this->field_type][$this->field_id]", $this->htmlOptions);
break;
case 'select':
echo $this->form->dropDownList($this->model, "field_name[$this->field_type][$this->field_id]", $this->select_box_array, $this->htmlOptions);
break;
case 'password':
echo $form->passwordField($model,'password',$this->htmlOptions);
break;
case 'multiselect':
$newarr = array_merge($this->htmlOptions, array('multiple' => 'multiple'));
echo $this->form->dropDownList($this->model, "field_name[$this->field_type][$this->field_id]", $this->select_box_array, $newarr);
break;
case 'file':
echo $this->form->fileField($this->model, "field_name[$this->field_type][$this->field_id]" ,$this->htmlOptions);
break;
case 'radio':
echo $this->form->radioButton($this->model, "field_name[$this->field_type][$this->field_id]", $this->htmlOptions);
break;
case 'radiolist':
echo CHtml::radioButtonList("ProfileFields[field_name][$this->field_type][$this->field_id]",$this->htmlOptions['value'],$this->radio_box_array,$this->htmlOptions);
break;
case 'checkbox':
echo $this->form->checkBox($this->model, "field_name[$this->field_type][$this->field_id]", $this->htmlOptions);
break;
case 'date':
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'attribute' => "field_name[$this->field_type][$this->field_id]",
'model' => $this->model,
'htmlOptions'=>array(
'class'=>'required',
),
'options' => array(
'dateFormat' => 'yy-mm-dd',
'maxDate' => 'new Date()', // One month ahead
//'minDate' => '-50y', // Today
'changeMonth' => true,
'changeYear' => true,
'yearRange'=>'2000:2099',
'minDate' => '2000-01-01', // minimum date
'maxDate' => '2099-12-31',
)
));
break;
case 'checkboxlist':
echo CHtml::checkBoxList("ProfileFields[field_name][$this->field_type][$this->field_id]",$this->htmlOptions['value'],$this->check_box_array,$this->htmlOptions);
break;
}
}
}

Categories