Welcome Guest, Not a member yet? Register   Sign In
Add Form Help
#1

[eluser]jzmwebdevelopement[/eluser]
Hello,

I have edited the below code to keep it upto date with changes I have made. The issue that I am having is that I seem to insert fine (well not data just 0) when I changed
Code:
if($this->form_validation->run() === TRUE
to false.

What I am trying to do is when the validation is true insert the $ into the db

How would I make it display a completed message after the query has run?

Controller

Code:
class Addsale extends CI_Controller {

    function __construct(){
    parent::__construct();
    }
    function index() {
        if(!$this->session->userdata('logged_in')) {
            redirect('admin/home');
        }
        // set data
        $data['title'] = "Add Sale";
        $data['sales_pages'] = $this->sales_model->getSalesPages();
        $data['cms_pages'] = $this->navigation_model->getCMSPages();
    
        $this->load->library('form_validation');
        $this->form_validation->set_rules('name', 'Name', 'trim|required');
        $this->form_validation->set_rules('location', 'Location', 'trim|required');
        $this->form_validation->set_rules('bedrooms', 'Bedrooms', 'trim|is_natural|required');
        $this->form_validation->set_rules('bathrooms', 'Bathrooms', 'trim|required');
        $this->form_validation->set_rules('condition', 'Condition', 'trim|required');
        $this->form_validation->set_rules('description', 'Description', 'trim|required');
        $this->form_validation->set_rules('price', 'Price', 'trim|required');
        
        if($this->form_validation->run() === TRUE) {
            
            $name = $this->input->post('name', TRUE);
            $location = $this->input->post('location', TRUE);
            $bedrooms = $this->input->post('bedrooms', TRUE);
            $bathrooms = $this->input->post('bathrooms', TRUE);
            $condition = $this->input->post('condition', TRUE);
            $description = $this->input->post('description', TRUE);
            $price = $this->input->post('price', TRUE);
        
            $this->sales_model->addSale($name, $location, $bedrooms, $bathrooms, $condition, $description, $price);
          
            redirect('admin/dashboard' , $data);
            
            $this->form_validation->set_message('required','Page Saved');
        }else{
            $data['content'] = $this->load->view('admin/addsale', NULL, TRUE);
            $this->load->view('template', $data);
            }

    }
    
        
}

View

Code:
<?php
//Setting form attributes
$formAddSale = array('id' => 'addSale', 'name' => 'addSale');
$formTitle = array('id' => 'title', 'name' => 'title');
$formLocation = array('id' => 'location', 'name' => 'location');
$formBedrooms = array('id' => 'bedrooms','name' => 'bedrooms');
$formBathrooms = array('id' => 'bathrooms','name' => 'bathrooms');
$formCondition = array('id' => 'condition','name' => 'condition');
$formDescription = array('id' => 'description','name' => 'description');
$formPrice = array('id' => 'price','name' => 'price');
?>

<section id = "validation">&lt;?php echo validation_errors();?&gt;</section>

&lt;?php
echo form_open('admin/addsale/', $formAddSale);
echo form_fieldset();
echo form_label('Name:', 'name');
echo form_input($name);
echo form_label ('Location', 'location');
echo form_input($location);
echo form_label ('Bedrooms', 'bedrooms');
echo form_input($bedrooms);
echo form_label ('Bathrooms', 'bathrooms');
echo form_input($bathrooms);
echo form_label ('Condition', 'condition');
echo form_input($condition);
echo form_label ('Price', 'price');
echo form_input($price);
echo form_label ('Description', 'description');
echo form_textarea($description);
echo form_submit('submit','Submit');
echo form_fieldset_close();
echo form_close();
?&gt;

Model
Code:
function addSale($name, $location, $bedrooms, $bathrooms, $condition, $description, $price) {
         $data = array('name' => $name, 'location' => $location, 'bedrooms' => $bedrooms, 'bathrooms' => $bathrooms, 'condition' => $condition, 'description' => $description, 'price' => $price);
    
    $this->db->insert('sales', $data);
    }


[/code]
#2

[eluser]byde[/eluser]
well, where is the model???

you have:
Code:
$data['sales_pages'] = $data->sales_model->getSalesPages(); // Line 21

i think you mean
Code:
$data['sales_pages'] = $this->sales_model->getSalesPages(); // Line 21

but for that you need
Code:
$this->load->model("sales_model");

cause
Quote:Line 21, Call to a member function getSalesPages() on a non-object
means that "$data" is not an object, is an array
#3

[eluser]jzmwebdevelopement[/eluser]
I feel blonde haha been a long day

My addPage model is

Code:
function addSale($data) {
         $this->db->insert($data);
    }




Theme © iAndrew 2016 - Forum software by © MyBB