Welcome Guest, Not a member yet? Register   Sign In
loading different module views into page virew. possible or quite wrong?
#1

[eluser]shershen08[/eluser]
if it's right desigion for my situation?
i've got booking form on a page, wich user can fill in and press submit
this form is made as a module and it has 3 views: form (empty form itself), success (when form is filled properly) and error (when some field are missing)
it has it's own controller which validates the data and loads needed view
BUT
i've got one page template - say it's a view called "page_view"
and in it i load my module as - modules::run('booking'), this case loads
basic view of a module called form, but HOW CAN I CALL another views of a module form like success and error on the same page view?
what construction i should use to make my module changing inside the same page view?
i'am a newbie so probably this idea is urgly and wrong, than how should i do this?
#2

[eluser]Jan_1[/eluser]
hope I have understood you and this might be a help:

make a view_file with 3 cases (empty_form, success and error)
pass a variable from controller_file to view_file which says what kind of view is needed.

make form-validation in the controller_file
if form-validation is ok, call function in model_file which writes input_data to database

PS: if you like to: call form_fields from a function in model_file and pass it to view_file by controller_file
#3

[eluser]shershen08[/eluser]
[quote author="Jan from Hamburg" date="1280494053"]
make a view_file with 3 cases (empty_form, success and error)
pass a variable from controller_file to view_file which says what kind of view is needed.

[/quote]
thanks for fast answer, but that's the obvious thing, which i wanted to avoid exactly
i wanna have 1 view of the page and 3 views of a module
is that possible?
#4

[eluser]shershen08[/eluser]
[quote author="shershen08" date="1280496051"][quote author="Jan from Hamburg" date="1280494053"]
make a view_file with 3 cases (empty_form, success and error)
pass a variable from controller_file to view_file which says what kind of view is needed.

[/quote]
thanks for fast answer, but that's the obvious thing, which i wanted to avoid exactly
i wanna have 1 view of the page and 3 views of a module
is that possible?[/quote]
oh, sorry let me think once again, probably i didn't get the idea
#5

[eluser]shershen08[/eluser]
ok, now got it!
i tried to do this way, but could not find information how to get paraveters inside view.
in controller i call view like this - $this->load->view('booking', $params);
than can you give me an example how i can get this $params
inside view ?
#6

[eluser]Jan_1[/eluser]
as fast/short as possible... Hope I made no mistakes ;o)
Have a look in the manual, too, please


form_controller.php
Code:
function my_form()
{ $this->load->helper('url','form');
  $this->load->model('form_model');
  $this->load->library('form_validation');
  $this->form_validation->set_rules('username', 'Username','required');
  $this->form_validation->set_rules('email', 'Your Email', 'trim|required|valid_email);
  
  if ($this->form_validation->run() == FALSE)
       {  
        $data['text'] = "Hello, please fill out this form!";
        $data['form'] = "form";
       }
  else {
        $data['text'] = "Congratulations etc etc";
        $this->form_model->write_to_database();
        $data['form'] = "success";
       }
  $this->load->view('form_view', $data);
}

form_model.php:
Code:
function write_to_database()
{
$insert['username'] = $this->input->post('username');
$insert['email']    = $this->input->post('email');
$this->db->insert('db_table', $insert);
}

form_view.php:
Code:
<?php
  if($form=='form')
    {
      echo $text;
      echo form_open('form_controller/my_form');
      echo form_error('username');
      echo form_input('username', 'your name');
      echo form_error('email');
      echo form_input('email', 'your email');
      echo form_submit('mysubmit', 'Submit Post!');
    }
  elseif($form=='success') { echo $text;}
  else {echo "How did you get here?!";}  //;o)
?>

you can also push your inputfields from controller
Code:
$data['fields']= "<input type='text' name='passconf' value='' size='50'/>etc etc all fields...";
or take it from a model
Code:
$data['input_username']=$this->form_model->inputfield_username();
#7

[eluser]shershen08[/eluser]
it started working at last! thanks a lot!




Theme © iAndrew 2016 - Forum software by © MyBB