I want to calculate qty*price from give input when price and qty changes automatically total should get changed using javascript events in codeigniter and total filed should be disabled my code is as follow
<script>
functionn caltotal()
{
}
</script>
<?php
echo form_open('add_veg/insert_data', 'class="form-horizontal" id="myform" role="form"');
$sales_date = array(
'type' => 'date',
'name' => 'date',
'id' => 'date',
'class' => 'form-control'
);
$vegnames=array();
foreach($veg_names as $r){
$vegnames[$r->value]=$r->label;
}
/*
$vegnames = array(
'cauliflower' => 'Caulifower',
'Brinjal' => 'Brinjal'
);
*/
$wt = array(
'type' => 'text',
'name' => 'weight',
'id' => 'wt',
'class' => 'form-control'
);
$price = array(
'type' => 'text',
'name' => 'price',
'id' => 'price',
'class' => 'form-control'
);
$total=array(
'type'=>'readonly',
'name'=>'total',
'id'=>'total',
'class'=>'form-control disabled'
);
$save=array(
'name' =>'sub',
'value' =>'Save',
'class' =>'btn btn-success btn-sm'
);
echo form_label('Sales date', 'sdate', 'class="control-label col-sm-2"');
echo form_input($sales_date);
echo form_label('Vegitable Name', 'vname', 'class="control-label col-sm-2"');
//echo form_input($veg_name);
echo form_dropdown('v_name', $vegnames,'','class="form-control"');
echo form_label('Weight', 'wt', 'class="control-label col-sm-2"');
echo form_input($wt);
echo form_label('Price', 'price', 'class="control-label col-sm-2"');
echo form_input($price);
echo form_label('Total', 'total', 'class="control-label col-sm-2"');
echo form_input($total);
echo form_submit($save);
echo form_close();
?>
Try this
$('#quantity').keyup(function() {
var quantity = $("#quantity").val();
var iPrice = $("#item_price").val();
var total = quantity * iPrice;
$("#total_price").val(total); // sets the total price input to the quantity * price
});
Related
I have multiple radio buttons and a dropdown list. I want to populate the list based on the selected value. The problem is I can't get the selected value in controller.
View:
<?php echo form_open(base_url() . 'controller/method');
$type1 = array(
'name' => 'category',
'id'=> '1',
'value' => 't1',
'checked' => TRUE,
);
echo form_radio($type1);
echo form_label('Type 1');
$type2 = array(
'name' => 'category',
'id'=> '2',
'value' => 't2',
);
echo form_radio($type2);
echo form_label('Type 2');
$type3 = array(
'name' => 'category',
'id'=> '3',
'value' => 't3',
);
echo form_radio($type3);
echo form_label('Type 3');
echo form_close();
?>
Controller:
$category= $this->input->post('category');
When I try:
if(isset($category)){
echo $category;
}
else{
echo "variable is not there";
}
I always get "variable is not there".
I want to display validation error msg on registration form. Msg should be displayed when Login already exist in database.
MY error: Unable to access an error message corresponding to your field name Login_r.(rule)
Pleas try to help me, its very important. Thank you
config/form_validation.php
$config = array(
'login' => array(
array(
'field' => 'login',
'label' => 'Login',
'rules' => 'required'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'required'
)
),
'register' => array(
array(
'field' => 'name_r',
'label' => 'Name',
'rules' => 'required|alpha'
),
array(
'field' => 'lastname_r',
'label' => 'Lastname',
'rules' => 'required|alpha'
),
array(
'field' => 'login_r',
'label' => 'Login_r',
'rules' => 'required|callback_rule'
),
array(
'field' => 'password_r',
'label' => 'Password_r',
'rules' => 'required|min_length[4]|max_length[12]'
),
array(
'field' => 'confirm_password_r',
'label' => 'Confirm_password',
'rules' => 'required|matches[password_r]'
),
array(
'field' => 'email_r',
'label' => 'Email',
'rules' => 'required|valid_email'
),
array(
'field' => 'adres_r',
'label' => 'Adres',
'rules' => 'required'
)
),
);
Controller:
if ($this->form_validation->run('register') == false)
{
$this->form_validation->set_message('rule', 'Dzialaj !');
$this->load->view('content/register');
}
else
{
$this->load->view('content/index');
$name_r = $this->input->post('name_r');
$lastname_r = $this->input->post('lastname_r');
$login_r = $this->input->post('login_r');
$password_r = $this->input->post('password_r');
$email_r = $this->input->post('email_r');
$adres_r = $this->input->post('adres_r');
$data_db = array(
'name' => $name_r,
'lastname' => $lastname_r,
'login' => $login_r,
'password' => $password_r,
'email' => $email_r,
'adres' => $adres_r
);
$this->Main_model->register($data_db);
}
Model:
public function register($data_db) {
$this->db->where('login',$data_db['login']);
$query = $this->db->get('users');
$row = $query->row();
if($row->login){
$this->form_validation->set_message('rule', 'Error Message');
} else {
$this->db->insert('users', $data_db);
}
View(forms)
<?php
echo validation_errors();
echo form_open();
echo 'Imie: ' . form_input('name_r');
echo br(2);
echo 'Nazwisko: ' . form_input('lastname_r');
echo br(2);
echo 'Login: ' . form_input('login_r');
echo br(2);
echo 'Haslo: ' . form_password('password_r');
echo br(2);
echo 'Potwierdz Haslo: ' . form_password('confirm_password_r');
echo br(2);
echo 'E-mail: ' . form_input('email_r');
echo br(2);
echo 'Adres: ' . form_input('adres_r');
echo br(1);
echo form_submit('zarejestrowany','Stworz konto');
echo form_close();
?>
</div>
</div>
</div>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
</body>
</html>
I'm not sure where you have your validation code you posted, that should be in the controller too. I'd suggest refactoring so you don't do any validation in the model:
Model:
public function get_user($login) {
$this->db->where('login',$login);
$query = $this->db->get('users');
$row = $query->row();
return $row;
}
public function register($data_db) {
$this->db->insert('users', $data_db);
}
Controller:
if ($this->form_validation->run('register') == false)
{
$this->form_validation->set_message('rule', 'Dzialaj !');
$this->load->view('content/register');
}
else
{
$this->load->view('content/index');
$name_r = $this->input->post('name_r');
$lastname_r = $this->input->post('lastname_r');
$login_r = $this->input->post('login_r');
$password_r = $this->input->post('password_r');
$email_r = $this->input->post('email_r');
$adres_r = $this->input->post('adres_r');
$user = $this->Main_model->get_user();
if($user->login) {
$this->form_validation->set_message('rule', 'Error Message');
redirect('content/register')
}
$data_db = array(
'name' => $name_r,
'lastname' => $lastname_r,
'login' => $login_r,
'password' => $password_r,
'email' => $email_r,
'adres' => $adres_r
);
$this->Main_model->register($data_db);
This still isn't great since I have to use a redirect if it $user->login is true, it would be even better to create the callback like I mentioned in the chat, but I don't really understand how your code is structured.
Your controller needs a function called "rule" (because you have a rule called "callback_rule" in your form_validation rules).
function rule($form_value)
{
if(<condition for form value is good>)
{
return TRUE;
}
else
{
$this->form_validation->set_message('login_r','your error message');
return FALSE;
}
}
I am using Cakephp2.0
I have a table for all my images and a table for features.
I have a form that takes the following inputs:
name of feature
text and multiple images with image name.
I need to insert the feature name and text into the feature table, grab id just created, and insert it along with all the image info from the form. I am not sure how to make the controller do that.
controller:
public function add() {
if ($this->request->is('post')) {
$this->Feature->create();
if ($this->Feature->saveAll($this->request->data)) {
$this->Session->setFlash(__('Your Feature has been saved.'));
return $this->redirect(array('controller' => 'dashbords', 'action' => 'index'));
}
$this->Session->setFlash(__('Unable to add your Feature.'));
}
}
form:
<?php
echo $this->Form->create('Feature', array(
'class' => 'form-horizontal',
'role' => 'form',
'type' => 'file',
'inputDefaults' => array(
'format' => array('before', 'label', 'between', 'input', 'error', 'after'),
'div' => array('class' => 'form-group'),
'class' => array('form-control'),
'label' => array('class' => 'col-lg-2 control-label'),
'between' => '<div class="col-lg-6">',
'after' => '</div>',
'error' => array('attributes' => array('wrap' => 'span', 'class' => 'help-inline')),
))); ?>
<?php
echo '<fieldset>';
echo '<legend>Add Features</legend>';
echo '<div class="row"><div class="col-md-4">';
echo $this->Form->input('Feature.name', array('class' => 'feature'));
echo '</div>';
echo '<div class="col-md-8">';
echo '';
echo '</div></div>';
echo '</fieldset>';
//----------------------- Image Block -----------------------------//
// group main image //
echo '<fieldset>';
echo '<div class="row"><div class="col-md-4">';
echo '<legend>Main Image</legend>';
echo $this->Form->input(
'upload', array(
'type' => 'file',
'class' =>'main_image'));
echo $this->Form->input('Image.name', array(
'class' => 'main_image'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '1',
'class' => 'main_image'));
echo '</div>';
// bottom left image //
echo '<div class="col-md-4">';
echo '<legend>Bottom Left</legend>';
// group image 2//
echo $this->Form->input(
'upload', array(
'type' => 'file',
'class' =>'bl'));
echo $this->Form->input('Image.name', array(
'class' => 'bl'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '2',
'class' => 'bl'));
echo '</div>';
// bottom right //
echo '<div class="col-md-4">';
echo '<legend>Bottom Right</legend>';
echo $this->Form->input(
'upload', array(
'type' => 'file',
'class' =>'br'));
echo $this->Form->input('Image.name', array(
'class' => 'br'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '3',
'class' => 'br'));
echo '</div></div>';
echo '</fieldset>';
//----------------------- Gallery Block -----------------------------//
// group 1
echo '<fieldset>';
echo '<legend>Gallery</legend>';
echo '<div class="row"><div class="col-md-4">';
echo $this->Form->input(
'upload', array(
'type' => 'file',
'class' =>'gallery1'));
echo $this->Form->input('Image.name', array(
'class' => 'gallery1'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '4',
'class' => 'gallery1'));
echo '</div>';
echo '<div class="col-md-4">';
// group image 2//
echo $this->Form->input(
'upload', array(
'type' => 'file',
'class' =>'gallery2'));
echo $this->Form->input('Image.name', array('class'=>'gallery2'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '4',
'class', 'gallery2'));
echo '</div>';
echo '<div class="col-md-4">';
// group image 3 //
echo $this->Form->input(
'upload', array(
'type' => 'file',
'class' => 'gallery3'));
echo $this->Form->input('Image.name', array('class'=> 'gallery3'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '4',
'class', 'gallery3'));
echo '</div></div>';
// Feature Text //
echo '</fieldset>';
echo '<div class="row"><div class="col-md-12"><fieldset>';
echo '<legend>Content</legend>';
echo $this->Form->textarea('Feature.content', array('rows' => '10', 'cols' => '75'));
echo '</fieldset></div></div>';
?>
</fieldset>
<div class="row">
<div class="col-md-2 col-md-offset-10">
<?php echo $this->Form->end('Save Content'); ?>
</div>
</div>
Modles:
Featuer:
class Feature extends AppModel{
public $useTable = "features";
public $displayField = "name";
public $hasMany = array(
'Image'=>array('classname' => 'Image', 'foreignkey' => 'image_id'),
);
}
Update:
Per #SverriM.Olsen I have done some more research. I have concluded a few things like how to upload multiple images. Which then lead me to the fact I did dont know how to allow for a name to use as the image alt tag, so I removed that and in my controller add function I looped through the array and grabbed the file name minus the extension. I have read about set and saveAssociated. Where I am at now it how to join the newly created array of names and add then to the image table with the images from the form. here is an updated controller:
public function add() {
//get array of images loop throug
$file = $this->request->data['Image']['image'];
// get file name and extract name - extention
$name = array();
foreach($file as $key=>$value){
foreach($value as $k=>$v){
if($k == 'name'){
$file = $v;
$info = pathinfo($file);
$file_name = basename($file,'.'.$info['extension']);
$this->set(
'Image', array(
'name'=> $name[] = $file_name));
}
}
}
if ($this->request->is('post')) {
$this->Feature->create();
if ($this->Feature->saveAssociated($this->request->data)) {
$this->Session->setFlash(__('Your Feature has been saved.'));
return $this->redirect(array('controller' => 'dashbords', 'action' => 'index'));
}
$this->Session->setFlash(__('Unable to add your Feature.'));
debug($this->Feature->validationErrors);
}
}
and an updated form (add.ctp)
<?php
echo $this->Form->create('Feature', array(
'class' => 'form-horizontal',
'role' => 'form',
'type' => 'file',
'inputDefaults' => array(
'format' => array('before', 'label', 'between', 'input', 'error', 'after'),
'div' => array('class' => 'form-group'),
'class' => array('form-control'),
'label' => array('class' => 'col-lg-2 control-label'),
'between' => '<div class="col-lg-6">',
'after' => '</div>',
'error' => array('attributes' => array('wrap' => 'span', 'class' => 'help-inline')),
))); ?>
<?php
echo '<fieldset>';
echo '<legend>Add Features</legend>';
echo '<div class="row"><div class="col-md-4">';
echo $this->Form->input('name');
echo $this->Form->textarea('content', array('rows' => '5', 'cols' => '55'));
echo '<br/><br/>';
echo '<div class="col-md-8">';
echo '';
echo '</div></div>';
echo '</fieldset>';
//----------------------- Image Block -----------------------------//
// group main image //
echo '<fieldset>';
echo '<div class="row"><div class="col-md-4">';
echo '<legend>Main Image</legend>';
echo '<p>Uploade multiple image for each lug set at once.</p>';
echo $this->Form->input(
'Image.image.', array(
'type' => 'file',
'multiple' => 'multiple',
'class' =>'main_image'));
echo $this->Form->input('Image.name', array(
'type' => 'hidden',
'class' => 'main_image'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '1',
'class' => 'main_image'));
echo '</div>';
// bottom left image //
echo '<div class="col-md-4">';
echo '<legend>Bottom Left</legend>';
// group image 2//
echo $this->Form->input(
'Image.image.', array(
'type' => 'file.',
'multiple' => 'multiple',
'class' =>'bl'));
echo $this->Form->input('Image.name', array(
'class' => 'bl'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '2',
'class' => 'bl'));
echo '</div>';
// bottom right //
echo '<div class="col-md-4">';
echo '<legend>Bottom Right</legend>';
echo $this->Form->input(
'Image.image.', array(
'type' => 'file',
'class' =>'br'));
echo $this->Form->input('Image.name', array(
'class' => 'br'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '3',
'class' => 'br'));
echo '</div></div>';
echo '</fieldset>';
//----------------------- Gallery Block -----------------------------//
// group 1
echo '<fieldset>';
echo '<legend>Gallery</legend>';
echo '<div class="row"><div class="col-md-4">';
echo $this->Form->input(
'Image.image.', array(
'type' => 'file',
'class' =>'gallery1'));
echo $this->Form->input('Image.name', array(
'class' => 'gallery1'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '4',
'class' => 'gallery1'));
echo '</div>';
echo '<div class="col-md-4">';
// group image 2//
echo $this->Form->input(
'Image.image.', array(
'type' => 'file.',
'class' =>'gallery2'));
echo $this->Form->input('Image.name', array('class'=>'gallery2'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '4',
'class', 'gallery2'));
echo '</div>';
echo '<div class="col-md-4">';
// group image 3 //
echo $this->Form->input(
'Image.image.', array(
'type' => 'file.',
'class' => 'gallery3'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '4',
'class', 'gallery3'));
echo '</div></div>';
?>
</fieldset>
<div class="row">
<div class="col-md-2 col-md-offset-10">
<?php echo $this->Form->end('Save Content'); ?>
</div>
</div>
Any help or pointer to places that will help is great. I will try some more googling.
Thank you in advance.
I have dropdown with database values.But,dropdown also shows database value's index and i want to remove index.I have searched in google and other forums,but not getting expected solution.
function products_edit($product_id) {
$this->load->helper('form');
$this->load->helper('html');
$this->load->library('form_validation');
$this->load->model('products_model');
$data=$this->products_model->general();
$category['categories']=$this->products_model->get_category();
$product = $this->products_model->get_product($product_id);
$this->data['title'] = 'Edit Product';
//validate form input
$this->form_validation->set_rules('name', 'Product name', 'required|xss_clean');
$this->form_validation->set_rules('description', 'Product Description', 'required|xss_clean');
$this->form_validation->set_rules('category', 'Category', 'required|xss_clean');
//$this->form_validation->set_rules('extras', 'Extras', 'required|xss_clean');
$this->form_validation->set_rules('price', 'Price', 'required|xss_clean');
$this->form_validation->set_rules('is_featured', 'Is Featured', 'required|xss_clean');
$this->form_validation->set_rules('prorder', 'prorder', 'required|xss_clean');
if (isset($_POST) && !empty($_POST)) {
$data = array(
'product_name'=> $this->input->post('name'),
'product_desc'=> $this->input->post('description'),
'product_category' => $this->input->post('category'),
'extras' => $this->input->post('extras'),
'price' => $this->input->post('price'),
'is_featured' => $this->input->post('is_featured'),
'prorder' => $this->input->post('prorder'),
);
if ($this->form_validation->run() === true) {
$this->products_model->updateproducts($product_id, $data);
$this->session->set_flashdata('message', "<p>Product updated successfully.</p>");
redirect('products_controller/products_edit/'.$product_id);
}
}
$this->data['message'] = (validation_errors() ? validation_errors() : $this->session->flashdata('message'));
$this->data['product'] = $product;
//display the edit product form
$this->data['name'] = array(
'name' => 'name',
'id' => 'name',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('name', $product['product_name']),
);
$this->data['description'] = array(
'name' => 'description',
'id' => 'description',
'type' => 'text',
'cols' => 60,
'rows' => 5,
'value' => $this->form_validation->set_value('description', $product['product_desc']),
);
$cat=array();
$test = array();
for($i=0;$i<=3;$i++) {
$test[$i] = array($category['categories'][$i] => $category['categories'][$i]);
}
$this->data['category'] = $test;
$this->data['extras'] = array(
'name' => 'extras',
'id' => 'extras',
'type' => 'text',
'style' => 'width:250px;',
'value' => $this->form_validation->set_value('extras', $product['extras']),
);
$this->data['price'] = array(
'name' => 'price',
'id' => 'picture',
'type' => 'text',
'style' => 'width:250px;',
'value' => $this->form_validation->set_value('price', $product['price']),
);
$this->data['is_featured'] = array(
'name' => 'is_featured',
'id' => 'is_featured',
'type' => 'text',
'style' => 'width:250px;',
'value' => $this->form_validation->set_value('is_featured', $product['is_featured']),
);
$this->data['prorder'] = array(
'name' => 'prorder',
'id' => 'prorder',
'type' => 'text',
'style' => 'width:250px;',
'value' => $this->form_validation->set_value('prorder', $product['prorder']),
);
$this->load->view('products_edit', $this->data);
}
The error occurs in this line.
for($i=0;$i<=3;$i++) {
$test[$i] = array($category['categories'][$i] => $category['categories'][$i]);
}
The error is due to $i in the test array. If I remove it, causing an error. I don't have solution for this error.
The screen shot http://i.share.pho.to/f4a24cc3_o.png
Is there a particular reason why you're using a for loop to build your categories dropdown list?
The $test array needs to look something like this:
$test = array(
1 => 'Pizza',
2 => 'Sandwich',
3 => 'Dessert',
4 => 'Salad'
);
Where the key is the associated id to the category and the value is the category name. At the minute you are loading both the key and value of the array with the whole category (based on it's index).
If you are wanting to pull out all the categories into a dropdown box, I would suggest something similar to the below, as this would allow you to add additional categories in future and them appear in the dropdown box:
foreach($category['categories'] as $category) {
$test[$category['id']] = $category['name'];
}
$this->data['category'] = $test;
This would require the categories (which I assume are being pulled out of a database table?) to have an id and name field.
Hope that helps...
I have a controller and a view. I am trying to submit some details through a form, but when I submit it, no errors are displayed.
I am using only one controller to for 2 different types of users. The two users are -
User
Gym/Health Club Owner
And according to the $suertype, I have the same view being called but a different content being loaded.
This is my controller:
public function CreateProfile_Step2()
{
$data['page_title'] = 'Create Profile (Step 2)';
$loginid = $this->session->userdata('loginid');
$this->load->model('profilemodel', 'profile');
$userid = $this->profile->get_userid($loginid);
$this->session->set_userdata('userid', $userid);
$usertype = $this->profile->get_usertype($userid);
$data['usertype'] = $usertype;
if ($usertype == 'User') {
$this->load->model('activitymodel', 'activity');
$arr_activities = $this->activity->get_activities();
$data['options'] = $arr_activities;
}
else if ($usertype == 'Gym/Health Club Owner') {
$this->load->model('facilitymodel', 'facility');
$arr_facility = $this->facility->get_facilities();
$data['options'] = $arr_facility;
}
$config = array(
'User' => array(
array(
'name' => 'sex',
'label' => 'Sex',
'rules' => 'required'
)),
'Gym/Health Club Owner' => array(
array(
'name' => 'website',
'label' => 'Website',
'rules' => 'prep_url'
),
array(
'name' => 'hours_of_operation',
'label' => 'Hours of Operation',
'rules' => 'required|numeric'
),
array(
'name' => 'membership_charges',
'label' => 'Membership Charges',
'rules' => 'required|numeric'
))
);
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules($config);
if ($usertype == 'User') {
if ($this->form_validation->run('User') == FALSE) {
$this->load->view('create-profile-step-2', $data);
}
else {
$selected_options = $this->input->post('activities');
$this->activity->add_user_activities($userid, $selected_options);
$sex = $this->input->post('sex');
$this->profile->add_user_details($userid, $sex);
echo 'Profile Creation Completed!';
}
}
else {
if ($this->form_validation->run('Gym/Health Club Owner') == FALSE) {
$this->load->view('create-profile-step-2', $data);
}
else {
$selected_options = $this->input->post('facilities');
$this->facility->add_gym_facility($userid, $selected_options);
$website = $this->input->post('website');
$hours_of_operation = $this->input->post('hours_of_operation');
$membership_charges = $this->input->post('membership_charges');
$this->facility->add_gym_details($userid, $website, $hours_of_operation, $membership_charges);
echo 'Profile Creation Completed!';
}
}
}
This is my view:
<?php include 'user/inc/header.php'; ?>
<div id="content" class="row twelvecol">
<h1>Create Profile (Step 2 of 2)</h1>
<h2>For <?php echo $usertype; ?></h2>
<?php
echo form_open('register/CreateProfile_Step2');
if ($usertype == 'User') {
echo form_label('Sex', 'sex');
$options_sex = array(
'Male' => 'Male',
'Female' => 'Female'
);
echo form_dropdown('sex', $options_sex, 'male');
$ctr = 1;
echo form_label('Activities Interested In', 'activities');
foreach($options->result() as $option)
{
echo form_label($option->activity, 'activity-'.$ctr);
$arr_option = array(
'name' => 'activities[]',
'id' => 'activity-'.$ctr++,
'value' => $option->activity
);
echo form_checkbox($arr_option);
}
}
elseif ($usertype == 'Gym/Health Club Owner')
{
echo form_label('Website', 'website');
$arr_website = array(
'name' => 'website',
'id' => 'website',
'value' => set_value('website')
);
echo form_input($arr_website);
echo form_label('Hours of Operation', 'hours_of_operation');
$arr_hours = array(
'name' => 'hours_of_operation',
'id' => 'hours_of_operation',
'value' => set_value('hours_of_operation')
);
echo form_input($arr_hours);
echo form_label('Membership Charges', 'membership_charges');
$arr_charges = array(
'name' => 'membership_charges',
'id' => 'membership_charges',
'value' => set_value('membership_charges')
);
echo form_input($arr_charges);
$ctr = 1;
echo form_label('Facilities Available', 'facilities');
foreach($options->result() as $option)
{
echo form_label($option->facility, 'facility-'.$ctr);
$arr_option = array(
'name' => 'facilities[]',
'id' => 'facility-'.$ctr++,
'value' => $option->facility
);
echo form_checkbox($arr_option);
}
}
echo "<br/><br/>";
echo form_submit('submit', 'Create Profile');
echo form_close();
echo validation_errors();
?>
Return to previous step
</div>
<?php include 'user/inc/footer.php'; ?>
It's more likely some problem with the $config, because I have tried changing my code and used 2 separate controllers and views for the 2 cases.
Well, since no one answered my question. I was going through the code and found the errors myself. I had used the key 'name' in my configuration instead of 'field'.
INCORRECT CODE
$config = array(
'User' => array(
array(
'name' => 'sex',
'label' => 'Sex',
'rules' => 'required'
)),
'Gym/Health Club Owner' => array(
array(
'name' => 'website',
'label' => 'Website',
'rules' => 'prep_url'
),
array(
'name' => 'hours_of_operation',
'label' => 'Hours of Operation',
'rules' => 'required|numeric'
),
array(
'name' => 'membership_charges',
'label' => 'Membership Charges',
'rules' => 'required|numeric'
))
);
CORRECT CODE
$config = array(
'User' => array(
array(
'field' => 'sex',
'label' => 'Sex',
'rules' => 'required'
)),
'Gym/Health Club Owner' => array(
array(
'field' => 'website',
'label' => 'Website',
'rules' => 'prep_url'
),
array(
'field' => 'hours_of_operation',
'label' => 'Hours of Operation',
'rules' => 'required|numeric'
),
array(
'field' => 'membership_charges',
'label' => 'Membership Charges',
'rules' => 'required|numeric'
))
);