I'm building a Joomla component and trying to use Joomla toolbars, problem is the buttons are not working properly, at least the publish and unpublish buttons are not (edit) - when I use the publish or unpublish button from the tool bar, the page reloads, it gives success message but the states remain the same.
Here's my code:
The Table File
<?php
defined( '_JEXEC' ) or die("Restricted Access");
class WetvprogramschedulerTableDay extends JTable {
public function __construct(&$db)
{
parent::__construct('#__wetv_programs_days', 'program_day_id', $db);
}
}
?>
The single record Model
<?php
defined( '_JEXEC' ) or die("Restricted Access");
jimport('joomla.application.component.modeladmin');
class WetvprogramschedulerModelDay extends JModelAdmin {
public function getTable($type = 'Day', $prefix = 'WetvprogramschedulerTable', $config = array()) {
return JTable::getInstance($type, $prefix, $config);
}
public function getForm($data = array(), $loadData = true) {
$form = $this->loadForm();
return $form;
}
}
?>
Edit
The List Model
<?php
defined( '_JEXEC' ) or die("Restricted Access");
jimport('joomla.application.component.modellist');
class WetvprogramschedulerModelDays extends JModelList {
public function __construct($config = array()) {
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'program_day',
'program_day_image',
'published'
);
}
parent::__construct($config);
}
public function getItems() {
// Run the query returned from getListQuery()
$items = parent::getItems();
// Prepare urls for View
// Doing this means we don't have to do it in the view
foreach ($items as &$item) {
$item->url = 'index.php?option=com_wetvprogramscheduler&task=day.edit&program_day_id=' . $item->program_day_id;
}
return $items;
}
public function getListQuery() {
$query = parent::getListQuery();
$query->select('*');
$query->from('#__wetv_programs_days');
// use state obtained from populateState()
$published = $this->getState('filter.published');
if ($published == '') {
$query->where('(published = 1 OR published = 0)');
} else if ($published != '*') {
$published = (int) $published;
$query->where("(published = '{$published}')");
}
$search = $this->getState('filter.search');
$db = $this->getDbo();
if (!empty($search)) {
$search = '%' . $db->getEscaped($search, true) . '%';
$field_searches =
"(program_day_image LIKE '{$search}' OR " .
"program_day LIKE '{$search}')";
$query->where($field_searches);
}
// Column ordering
$orderCol = $this->getState('list.ordering');
$orderDirn = $this->getState('list.direction');
if ($orderCol != '') {
$query->order($db->getEscaped($orderCol.' '.$orderDirn));
}
return $query;
}
protected function populateState($ordering = null, $direction = null) {
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
$this->setState('filter.search', $search);
/*
*Check both both session and form variable to see if
*There is a value for the filter_published variable
*/
$published = $this->getUserStateFromRequest($this->context.'.filter.published', 'filter_published');
// If filter_published value, set it in model state.
//so we can get value when we get state.
$this->setState('filter.published', $published);
parent::populateState($ordering, $direction);
}
}
?>
The Controller
<?php
defined( '_JEXEC' ) or die("Restricted Access");
jimport('joomla.application.component.controlleradmin');
class WetvprogramschedulerControllerDays extends JControllerAdmin {
protected $text_prefix = 'COM_WETVPROGRAMSCHEDULER_DAYS';
public function getModel($name = 'Day', $prefix = 'WetvprogramschedulerModel', $config = array('ignore_request' => true)) {
$model = parent::getModel($name, $prefix, $config);
return $model;
}
}
?>
view.html.php
<?php
defined( '_JEXEC' ) or die("Restricted Access");
jimport( 'joomla.application.component.view');
class WetvprogramschedulerViewDays extends JView {
protected $items;
protected $pagination;
public function display($tpl = null) {
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->addToolbar();
parent::display($tpl);
}
public function addToolbar() {
JToolBarHelper::title(JText::_('COM_WETVPROGRAMSCHEDULER_DAYS_TITLE'));
JToolBarHelper::addNew('day.add');
JToolBarHelper::editList('day.edit');
JToolBarHelper::divider();
JToolBarHelper::publishList('days.publish');
JToolBarHelper::unpublishList('days.unpublish');
JToolBarHelper::divider();
JToolBarHelper::archiveList('days.archive');
JToolBarHelper::trash('days.trash');
}
}
?>
default.php
<?php defined( '_JEXEC' ) or die("Restricted Access"); ?>
<form action="index.php?option=com_wetvprogramscheduler&view=days" method="post" name="adminForm" id="adminForm">
<table class="adminlist">
<thead>
<tr>
<th width="1%">
<input type="checkbox" name="checkall-toggle" value="" onclick="checkAll(this)" />
</th>
<th><?php echo JText::_('COM_WETVPROGRAMSCHEDULER_FIELD_DAY_NAME_LABEL') ?></th>
<th><?php echo JText::_('COM_WETVPROGRAMSCHEDULER_FIELD_DAY_IMAGE_LABEL') ?></th>
<th><?php echo JText::_('JSTATUS') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($this->items as $i => $item): ?>
<tr class="row<?php echo $i % 2 ?>">
<td class="center">
<?php echo JHtml::_('grid.id', $i, $item->progam_day_id); ?>
</td>
<td>
<a href="<?php echo $item->url; ?>">
<?php echo $this->escape($item->program_day) ?></a>
</td>
<td><?php echo $this->escape($item->program_day_image) ?></td>
<td class="center">
<?php echo JHtml::_('jgrid.published',
$item->published, $i, 'days.', true, 'cb'); ?>
</td>
</tr>
<?php endforeach ?>
</tbody>
<tfoot>
<tr>
<td colspan="4">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
</tfoot>
</table>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<?php echo JHtml::_('form.token'); ?>
</form>
Here's the sql statement for the table.
CREATE TABLE IF NOT EXISTS #__wetv_programs_days (
program_day_id BIGINT(20) NOT NULL AUTO_INCREMENT,
program_day VARCHAR(9) NOT NULL,
program_day_image VARCHAR(255) NOT NULL,
program_day_access int(11) DEFAULT '1',
program_day_alias varchar(255) DEFAULT NULL,
published tinyint(1) DEFAULT '0',
checked_out int(11) DEFAULT '0',
checked_out_time datetime DEFAULT '0000-00-00 00:00:00',
program_day_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (program_day_id),
UNIQUE (program_day),
UNIQUE (program_day_alias)
);
Missing "r" from progam_day_id in default.php in the checkbox cell.
It should be program_day_id
Related
I want to activate and deactivate a category status from the admin side if user is active, then show that category in front side.
How can I activate and deactivate categories?
I want a button to click active and deactivate categories from the admin side.
Controller Code:-
function update_status(){
if(isset($_REQUEST['svalue']))
{
$this->load->model('categorymodel','category');
$set_status=$this->category->update_status();
if($set_status>0){
$this->session->set_flashdata('message',"category has been updated.");
}else{
$this->session->set_flashdata('message',"category has not been updated.");
}
}
return redirect("admin/category");
}
Model Code:-
function update_status(){
$sid=$_REQUEST['sid'];
$svalue=$_REQUEST['svalue'];
if ($svalue=='active') {
$status='inactive';
} else {
$status='active';
}
$data = array(
'status' => $status
);
$this->db->where('id',$sid);
return $this->db->update('category',$data);
}
View Part:-
<td>
<?php
$status = $data->status;
if ($status == 'active') {
?>
Active
<?php
} else {
?>
Inactive
<?php
}
?>
</td>
Database Table:-
Id Primary int(11)
category_name varchar(255)
slug varchar(255)
category_image text
created_at timestamp
updated_at datetime
status enum('inactive', 'active')
Currently you have following code in View.
<td>
<?php $status = $data->status;
if ($status == 'active') {?>
Active
<?php } else {?>
Inactive
<?php } ?>
<td>
You should change as below
<td>
<?php $status = $data->status;
if ($status == 'active') {?>
<a title="Click to Deactivate" href="<?php echo base_url();?>admin/category/update_status?sid=<?php echo $data->id;?>&svalue=inactive" class="btn btn success">Active</a>
<?php } else {?>
<a title="Click to Activate" href="<?php echo base_url();?>admin/category/update_status?sid=<?php echo $data->id;?>&svalue=active" class="btn btn-danger">Inactive</a>
<?php } ?>
<td>
quantity not update only If I add an item with the exact same options more than once to my cart, it replaces instead of increasing the qty of the existing item
This is cart view code
`<table class="table table-bordered table-hover">
<thead ><!-- Table head -->
<tr>
<th class="active">Sl</th>
<th class="active col-sm-4">Product</th>
<th class="active col-sm-2">Real Price</th>
<th class="active ">Qty</th>
<th class="active ">Disc Price</th>
<th class="active">Total</th>
<th class="active">Action</th>
</tr>
</thead><!-- / Table head -->
<tbody><!-- / Table body -->
<?php $cart = $this->cart->contents() ;
?>
<?php $counter =1 ; ?>
<?php if (!empty($cart)): foreach ($cart as $item) : ?>
<tr class="custom-tr">
<td class="vertical-td">
<?php echo $counter ?>
</td>
<td class="vertical-td"><?php echo $item['name'] ?></td>
<td class="vertical-td"><?php echo $item['pkprice'] ?></td>
<td class="vertical-td">
<input type="text" name="qty" style="width: 50px" value="<?php echo $item['qty'] ?>" onblur ="order(this);" id="<?php echo 'qty'.$item['rowid'] ?>" class="form-control">
</td>
<td>
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox" id="<?php echo 'opt'.$item['rowid'] ?>" onclick="return price_checkbox(this)" name="custom_price"
<?php echo $item['price_option'] == 'custom_price' ? 'checked':'' ?>
data-placement="top" data-toggle="tooltip" data-original-title="Custom Price">
</span>
<input type="text" name="price" value="<?php echo $item['price'] ?>" onblur ="order(this);" id="<?php echo 'pri'.$item['rowid'] ?>" class="form-control"
<?php echo $item['price_option'] == 'custom_price' ? '':'disabled' ?> >
</div>
<input type="hidden" name="product_code" value="<?php echo $item['id'] ?>" id="<?php echo 'code'.$item['rowid'] ?>">
</td>
<td class="vertical-td"><?php echo number_format($item['subtotal'], 2, '.', ',') ?></td>
<td class="vertical-td">
<?php echo btn_delete('admin/order/delete_cart_item/' . $item['rowid']); ?>
</td>
</tr>
<?php
$counter++;
endforeach;
?><!--get all sub category if not this empty-->
<?php else : ?> <!--get error message if this empty-->
<td colspan="6">
<strong>There is no record for display</strong>
</td><!--/ get error message if this empty-->
<?php endif; ?>
</tbody><!-- / Table body -->
`
This is Controller Code
public function add_cart_item_by_barcode(){
$product_code = $this->input->post('barcode', true);
$result = $this->order_model->validate_add_cart_item($product_code);
if($result){
$price = $this->check_product_rate($result->product_id, $qty=1);
//product tax check
$tax = $this->product_tax_calculate($result->tax_id, $qty=1, $price);
$data = array(
'id' => $result->product_code,
'qty' => 1,
'price' => $price,
'buying_price' => $result->buying_price,
'name' => $result->product_name,
'pkprice' => $result->p_price,
'tax' => $tax,
'price_option' => 'general'
);
$this->cart->update($data);
$this->session->set_flashdata('cart_msg', 'add');
}
redirect('admin/order/new_order/'.$flag ='add');
}
public function check_product_rate($product_id=null, $qty=null)
{
//tier Price check
$tire_price = $this->order_model->get_tire_price($product_id, $qty);
if($tire_price)
{
return $price = $tire_price->tier_price ;
}
//special offer check
$this->tbl_special_offer('special_offer_id');
$offer_price = $this->global_model->get_by(array("product_id"=>$product_id), true);
if(!empty($offer_price)) {
$today = strtotime(date('Y-m-d'));
$start_date = strtotime($offer_price->start_date);
$end_date = strtotime($offer_price->end_date);
if (($today >= $start_date) && ($today <= $end_date)) {
return $price = $offer_price->offer_price;
}
}
//return regular rate
$this->tbl_product_price('product_price_id');
$general_price = $this->global_model->get_by(array("product_id"=>$product_id), true);
return $product_price = $general_price->selling_price;
}
/*** Product tax calculation ***/
public function product_tax_calculate($tax_id, $qty ,$price)
{
$this->tbl_tax('tax_id');
$tax = $this->global_model->get_by(array('tax_id'=>$tax_id), true);
//1 = tax in %
//2 = Fixed tax Rate
if($tax){
if($tax->tax_type == 1)
{
$subtotal = $price * $qty;
$product_tax = $tax->tax_rate * ($subtotal / 100);
//return $result = round($product_tax, 2);
return $result = $product_tax;
}else
{
//$product_tax = $tax->tax_rate * $qty;
$product_tax = $tax->tax_rate * $qty;
return $result = $product_tax;
}
}
}
/*** Update Product Cart ***/
public function update_cart_item()
{
$rowid = $this->input->post('rowid');
$qty = $this->input->post('qty');
$product_price = $this->input->post('price');
$product_code = $this->input->post('product_code');
$custom_price = $this->input->post('custom_price');
if($qty !=0 )
{
//tbl product
$this->tbl_product('product_id');
$result = $this->global_model->get_by(array('product_code'=> $product_code ), true);
//product Inventory Check
$this->tbl_inventory('inventory_id');
$product_inventory = $this->global_model->get_by(array('product_id'=> $result->product_id ), true);
if($qty > $product_inventory->product_quantity)
{
$type = 'error';
$message = 'Sorry! This product has not enough stock.';
set_message($type, $message);
echo 'false';
return;
}
if($custom_price == "on")
{
$price = $product_price;
$price_option = 'custom_price';
}
else
{
//product price check
$price = $this->check_product_rate($result->product_id, $qty);
$price_option = 'general';
}
//product tax check
$tax = $this->product_tax_calculate($result->tax_id, $qty, $price);
$data = array(
'rowid' => $rowid,
'qty' => $qty,
'price' => $price,
'tax' => $tax,
'price_option' => $price_option
);
}else
{
$data = array(
'rowid' => $rowid,
'qty' => $qty,
);
}
$this->cart->update($data);
if($this->input->post('ajax') != '1'){
redirect('admin/order/new_order'); // If javascript is not enabled, reload the page with new data
}else{
echo 'true'; // If javascript is enabled, return true, so the cart gets updated
}
}
/*** Show cart ***/
function show_cart(){
$this->load->view('admin/order/cart/cart');
}
/*** cart Summery ***/
function show_cart_summary(){
$this->load->view('admin/order/cart/cart_summary');
}
/*** Delete Cart Item ***/
public function delete_cart_item($id)
{
$data = array(
'rowid' => $id,
'qty' => 0,
);
$this->cart->update($data);
$this->session->set_flashdata('cart_msg', 'delete');
redirect('admin/order/new_order/'.$flag ='delete');
}
This is working fine when add product or change its quantity all perfect working but If I add an item with the exact same options more than once to my cart, it replaces instead of increasing the qty of the existing item
Have you tried this?
<?php foreach ($this->cart->contents() as $items): ?>
<?php echo form_hidden($counter.'[rowid]', $items['rowid']); ?> // write this
and then this
<td><?php echo form_input(array('name' => $counter.'[qty]', 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5')); ?></td>
instead of-
<?php echo form_input(array('name' =>'rowid1[]', 'type'=>'text', 'value' => $items['rowid'], 'maxlength' => '3', 'size' => '5')); ?>
I hope this works
Check what query is generated when update query is fire, i think any signal quote is added in your query.
for check the last database query use this function:-
print_r($this->db->last_query());
After a lot of struggled i get my code correctly here is the correct code of insert and update
function add_cart_item_by_barcode(){
$product_code = $this->input->post('barcode', true);
$result = $this->order_model->validate_add_cart_item($product_code);
$rowid = $this->input->post('rowid');
$cart = $this->cart->contents();
foreach ($cart as $cart) {
if($product_code == $cart['id']){
$rowid=$cart['rowid'];
$qty=$cart['qty'];
$data=array(
'rowid'=>$rowid,
'qty'=>$qty+1
);
$data=$this->cart->update($data);
$this->session->set_flashdata('cart_msg', 'add');
redirect('admin/order/new_order/'.$flag ='add');
}
}
if ($result) {
// update rate
$price = $this->check_product_rate($result->product_id, $qty=1);
//product tax check
$tax = $this->product_tax_calculate($result->tax_id, $qty=1, $price);
$data = array(
'id' => $result->product_code,
'qty' => $qty,
'price' => $price,
'buying_price' => $result->buying_price,
'name' => $result->product_name,
'pkprice' => $result->p_price,
'tax' => $tax,
'price_option' => 'general'
);
$this->cart->insert($data);
$this->session->set_flashdata('cart_msg', 'add');
}
redirect('admin/order/new_order/'.$flag ='add');
}
I have trouble with loading the table to the form_dropdown. I have tried any solution from the same trouble with me but its not working.
Here's the controller code:
<?php
class Registrasi extends Superuser_Controller
{
public $data = array(
'halaman' => 'registrasi',
'main_view' => 'program/administrasi/registrasi_list',
'title' => 'Data Registrasi',
);
public function __construct()
{
parent::__construct();
$this->load->model('program/administrasi/Registrasi_model', 'registrasi_model');
}
public function index()
{
$registrasi = $this->registrasi_model->get_all_registrasi_data();
$this->data['registrasiData'] = $registrasi;
$this->load->view($this->layout, $this->data);
}
public function tambah()
{
$this->data['namaNegara'] = $this->registrasi_model->get_nama_negara();
$this->data['main_view'] = 'program/administrasi/registrasi_form';
$this->data['form_action'] = site_url('program/administrasi/registrasi/tambah');
// Data untuk form.
if (! $_POST) {
$registrasi = (object) $this->registrasi_model->default_value;
} else {
$registrasi = $this->input->post(null, true);
}
// Validasi.
if (! $this->registrasi_model->validate('form_rules')) {
$this->data['values'] = (object) $registrasi;
$this->load->view($this->layout, $this->data);
return;
}
}
}
Here's the model code:
<?php
class Registrasi_model extends MY_Model
{
protected $_tabel = 'tb_registrasi';
protected $form_rules = array(
array(
'field' => 'Negara_Tujuan',
'label' => 'Negara Tujuan',
'rules' => 'trim|xss_clean|required|max_length[50]'
)
);
public $default_value = array(
'Negara_Tujuan' => ''
);
public function get_nama_negara()
{
$query = $this->db->query('SELECT Nama_Negara FROM tb_negara_tujuan');
return $query->result();
}
}
Here's the view code:
<div class="container">
<h2>Form Registrasi</h2>
<hr>
<?php echo form_open($form_action, array('id'=>'myform', 'class'=>'myform', 'role'=>'form')) ?>
<div class="container">
<div class="row">
<div class="form-group has-feedback <?php set_validation_style('Negara_Tujuan')?>">
<?php echo form_label('Negara Tujuan', 'negara_tujuan', array('class' => 'control-label')) ?>
<?php
foreach($namaNegara as $row)
{
echo form_dropdown('NegaraTujuan', $row->Nama_Negara);
}
?>
<?php set_validation_icon('Negara_Tujuan') ?>
<?php echo form_error('Negara_Tujuan', '<span class="help-block">', '</span>');?>
</div>
<?php echo form_button(array('content'=>'Simpan', 'type'=>'submit', 'class'=>'btn btn-primary', 'data-confirm'=>'Anda yakin akan menyimpan data ini?')) ?>
</div>
</div>
<?php echo form_close() ?>
</div>
The trouble I'm having is: Invalid argument supplied for foreach()
Your controller code must be :-
public function tambah()
{
$namaNegara[''] = 'select a option';
$namaNegaras = $this->registrasi_model->get_nama_negara();
foreach($namaNegaras as $namaNegaranew)
{
$namaNegara[$namaNegaranew->id] = $namaNegaranew->Nama_Negara ;
}
$this->data['namaNegara'] = $namaNegara;
$this->data['main_view'] = 'program/administrasi/registrasi_form';
$this->data['form_action'] = site_url('program/administrasi/registrasi/tambah');
// Data untuk form.
if (! $_POST) {
$registrasi = (object) $this->registrasi_model->default_value;
} else {
$registrasi = $this->input->post(null, true);
}
// Validasi.
if (! $this->registrasi_model->validate('form_rules')) {
$this->data['values'] = (object) $registrasi;
$this->load->view($this->layout, $this->data);
return;
}
}
And in view in place of
<?php
foreach($namaNegara as $row)
{
echo form_dropdown('NegaraTujuan', $row->Nama_Negara);
}
?>
Simply use
<?php echo form_dropdown('NegaraTujuan', $namaNegara , set_value('NegaraTujuan')); ?>
I think i have the answer for my problem:
Controller code (still same, no change whatsoever)
Model code: change the function into
public function get_nama_negara()
{
$query = $this->db->query('SELECT Nama_Negara FROM tb_negara_tujuan');
$dropdowns = $query->result();
foreach ($dropdowns as $dropdown)
{
$dropdownlist[$dropdown->Nama_Negara] = $dropdown->Nama_Negara;
}
$finaldropdown = $dropdownlist;
return $finaldropdown;
}
View code:
<div class="container">
<h2>Form Registrasi</h2>
<hr>
<?php echo form_open($form_action, array('id'=>'myform', 'class'=>'myform', 'role'=>'form')) ?>
<div class="container">
<div class="row">
<div class="form-group has-feedback <?php set_validation_style('Negara_Tujuan')?>">
<?php echo form_label('Negara Tujuan', 'negara_tujuan', array('class' => 'control-label')) ?>
<?php echo form_dropdown('NegaraTujuan', $namaNegara, set_value('NegaraTujuan'), 'class="dropdown"'); ?>
<?php set_validation_icon('Negara_Tujuan') ?>
<?php echo form_error('Negara_Tujuan', '<span class="help-block">', '</span>');?>
</div>
<?php echo form_button(array('content'=>'Simpan', 'type'=>'submit', 'class'=>'btn btn-primary', 'data-confirm'=>'Anda yakin akan menyimpan data ini?')) ?>
</div>
</div>
<?php echo form_close() ?>
</div>
i want to upload the image profile and the user id from my android application to database. i tried this method and it work in local but when i test it with (POSTMAN) a rest client it doesn't work. i think because i call a view.
this is my code please help me.
my controller
class Users extends REST_Controller {
function __construct()
{ parent::__construct();
$this->load->model('Users_model','',TRUE);}public function index_get()
{
$this->load->view('users');
}
public function save_image_post()
{
$id = $_POST["id"];
$url = $this->do_upload();
$this->Users_model->save_image($id, $url);
//$this->Users_model->save_image($url);
}
private function do_upload()
{
$type = explode('.', $_FILES["pic"]["name"]);
$type = strtolower($type[count($type)-1]);
$url = "./images/".uniqid(rand()).'.'.$type;
if(in_array($type, array("jpg", "jpeg", "gif", "png")))
if(is_uploaded_file($_FILES["pic"]["tmp_name"]))
if(move_uploaded_file($_FILES["pic"]["tmp_name"],$url))
return $url;
return "";
}
}
this is my model:
public function save_image($id,$url)
{
$this->db->set('id', $id);
$this->db->set('image_user', $url);
$this->db->insert('users');
}
this is my view:
<!DOCTYPE html><html lang="en"><head></head><body>
<?php echo form_open_multipart('api/users/save_image/'); ?>
<table class="table">
<tr>
<td>Id</td>
<td><?php echo form_input('id'); ?></td>
</tr>
<tr>
<td>Image</td>
<td><?php echo form_upload('pic'); ?></td>
</tr>
<tr><td></td>
<td><?php echo form_submit('submit', 'Save', 'class="btn btn-primary"'); ?></td>
</tr>
</table></body></html>
HI
i want to insert data using form in CI but i am facing the problem
Here is my model code
function add_form() {
$this->load->database();
$id = $this->input->post('id');
$name = $this->input->post('name');
$age = $this->input->post('age');
$data = array(
'name' => $this->input->post('name'),
'age' => $this->input->post('age'),
);
$this->db->insert('user',$data);
}
Here is my controller code
function simpleform() {
$this->load->helper('form');
$this->load->helper('html');
$this->load->model('welcomedb_model');
if( $this->input->post('submit') ) {
$this->welcomedb_model->add_form();
}
$this->load->view('welcomedb_view');
}
and here is my view code
<?php echo form_open('welcomedb/submit'); ?>
<? echo $name; ?>:
<? echo form_input('name'); ?>
</br>
<? echo $age; ?>:
<? echo form_input('age'); ?>
</br>
<?php echo form_submit('submit', 'Submit'); ?>
<?php echo form_close(); ?>
Thanks for your help
Your form is submitting to welcomedb/submit, but your controller appears to be at welcomedb/simpleform... maybe you need to change that.
Otherwise, there doesn't appear to be anything wrong.
Probably:
$data = array(
'name' => $this->input->post('name'),
'age' => $this->input->post('age'),
);
Remove comma from the last element (age) like this:
$data = array(
'name' => $this->input->post('name'),
'age' => $this->input->post('age')
);
and always dump error.
Best way is to do these code ......
First conifg the autoload and database.
into autoload:$autoload['libraries'] = array('database');
$autoload['helper'] = array('url','form','file');
Into controller
<?php
class CDemo extends CI_Controller
{
function index()
{
$this->load->view('VDemo');
}
function save()
{
$this->load->model('MDemo');
if($this->input->post('submit'))
{
$this->MDemo->process();
}
redirect('CDemo');
}
}
?>
Into Model
<?php
class MDemo extends CI_Model
{
function process()
{
$Id = $this->input->post('Id');
$Name = $this->input->post('Name');
$data = array(
'Id'=>$Id,
'Name'=>$Name
);
$this->db->insert('test',$data);
}
}
?>
Into View
<html>
<head>
<title>DEMO</title>
</head>
<body>
<h1>Form Biodata</h1>
<?php
echo form_open('CDemo/save', array('name' => 'VDemo'));
?>
<table>
<tr>
<td>Id :</td>
<td><input type="text" name="Id"></input></td>
</tr>
<tr>
<td>Name :</td>
<td><input type="text" name="Name"></input></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="submit"></input></td>
</tr>
</table>
<?php
echo form_close();
?>
<textarea rows="" cols="">Hello</textarea>
</body>
</html>