Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP Codeigniter Validation Help Need.

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #154698

    Hi.

    I use codeigniter for my frame work but I would like to know if there is away to get the validation error on views page to show below the specified input.

    Currently I have to put at the

    <?php echo validation_errors(); ?>
    

    at top of the form and it will show all error in that section

    Here is my contact controller contactus.php

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Contactus extends MX_Controller {
    
        public function index() {
    
            $this->load->library('form_validation');
    
            $this->form_validation->set_rules('name', 'Name', 'required');
            $this->form_validation->set_rules('email', 'Email', 'required');
            $this->form_validation->set_rules('website', 'Website', 'required');
            $this->form_validation->set_rules('subject', 'Subject', 'required');
            $this->form_validation->set_rules('message', 'Message', 'required');
    
    
            if($this->form_validation->run() == FALSE)
            {
                $this->load->view('header');
                $this->load->view('contactus');
                $this->load->view('footer');
            }
            else
            {
                $this->load->view('header');
                $this->load->view('confirmation');
                $this->load->view('footer');
            }
    
        }
    }
    
    #154706

    Problem now solved now just had to make form look like this

    <div class="form-group">
    <input type="text" class="form-control" placeholder="Your Name" name="name" >
    <?php echo form_error('name'); ?>
    </div>
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.