Hello All.
I have joined this forum a few minutes after I downloaded and installed CI 3.0.6. And this is the first time I am using anything like CI. Though I have been working on Core PHP and Wordpress, I have never used any MVC before and I am quite a few hours into it only.
So here is my problem -
I have been asked to implement a website for my newly joined job and lets start with the home page first -
The home page has 3 Forms -
a. Login form - via the Main Menu
b. Subscribe form and
c. Signup form
(b and c on the lower end of the page).
Gladly, the help on Internet did help me integrate Bootstrap into Code Igniter and also the documentation helped me get started. But now, I am stuck up with these forms.
Code Snippets-
The Home Controller Class
PHP Code:
class Home extends CI_Controller{
function __construct() {
parent::__construct();
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->helper('url');
}
public function index()
{
if(!file_exists('application/views/pages/home.php')){
echo "Sorry, The Home Page Does Not Exist";
}
else{
//Load the home page view here
$this->load->view('pages/home');
}
}
public function subscribe(){
$this->form_validation->set_rules('sname', 'Name', 'trim|required|min_length[5]');
$this->form_validation->set_rules('semail', 'Email', 'trim|required|valid_email');
if ($this->form_validation->run() === FALSE)
{
$this->load->view('pages/home');
}
else{
echo "All Good... Try Storing data and emailing";
}
}
public function signup(){
}
public function dologin(){
}
}
The Home View -
This has the Nav Bar (with a dropdown Login Form) and then there are two forms - Subscribe and Signup
Now, the problem that crops up is -
When I submit the Subscribe form with an intentional error (that violates the rules), the error messages are displayed on all 3 forms.
I did read on Internet that it is not advisable to have 3 forms in one view and also, if there is no way out, then, I should use Hidden fileds to identify which form has been submitted.
But somehow, as I am quite very new here, I would love to read what the Experienced Community on this forum thinks. What are the best practices in such situations.
Thanks in advance for your patience to read through this and helping me become proficient in using CI.
Warm regards,
Kevin.