Загрузите определенный div на id codeigniter - PullRequest
0 голосов
/ 29 октября 2018

myiamge

У меня есть 2 формы в виде вкладки на странице регистрации, когда отправляется одна форма, и если есть какая-либо ошибка, я хочу перенаправить ее на эту конкретную вкладку, которая содержит ошибку, но не произошла.

Вот мой взгляд

<?php include 'header.php'; ?>
<section class="services">
    <div class="container">
    <div class="signup-wrapper well" style="margin-bottom: 80px; margin-top: 80px;">
        <div class="container">
            <div class="services__main">
                <h2 class="title title--main"><span class="title__bold">Sign Up</span><span class="line line--title"><span class="line__first"></span><span class="line__second"></span></span></h2>
            </div>
            <div class="aside-tabs__links">
                <a href="#" class="no-decoration js-tab-link aside-tabs__active-link" data-for="#desc">Genrel User</a>
                <a href="#" class="no-decoration js-tab-link" data-for="#rev">Dealership</a>
            </div>
            <div class="aside-tabs__blocks about-tab js-tab-block no-b-border" id="desc" >
                <div class="col-md-5">
                    <form action="<?= base_url();?>Home/add_user" method="post" >
                        <!-- class="quick-form"  -->
                        <div class="form-group">
                            <input type="text" class="form-control" name="fname" placeholder="Full Name" />
                        </div>
                        <?php echo form_error('fname'); ?>
                        <div class="form-group">
                            <input type="email" class="form-control" name="email" placeholder="Email" />
                        </div>
                        <?php echo form_error('email'); ?>
                        <div class="form-group">
                            <input type="password" class="form-control" name="password" placeholder="Password" />
                        </div>
                        <?php echo form_error('password'); ?>
                        <div class="form-group">
                            <input type="text" class="form-control" name="phone" placeholder="Phone #" />
                        </div>
                        <?php echo form_error('phone'); ?>
                        <div class="form-group">
                            <select class="select-2 form-control" name="city">
                                <option>Select City</option>
                                    <?php foreach ($results as $result) { ?>
                                        <option><?= $result->city; ?></option>
                                <?php   } ?>
                            </select>
                        </div>
                        <?php echo form_error('city'); ?>
                        <div class="form-group">
                            <input  type="submit" class="btn button button--red button--main pull-right" style="margin-bottom: 10px;" value="Sign Up">
                        </div>
                    </form>                         
                </div>
            </div>
            <div class="aside-tabs__blocks about-tab js-tab-block no-b-border" id="rev" style="display: none;">
                <div class="col-xs-5">
                    <form action="<?= base_url();?>Home/add_dealer" method="post" enctype="multipart/form-data">
                        <h4>Comapny Information</h4>
                        <hr>
                       <div class="form-group">
                            <input type="text" class="form-control" name="cname" placeholder="Company Name" />
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" name="owner" placeholder="Owner Name" />
                        </div>
                        <div class="form-group">
                            <select class="select-2 form-control" name="city">
                                <option>Select City</option>
                                    <?php foreach ($results as $result) { ?>
                                        <option><?= $result->city; ?></option>
                                <?php   } ?>
                            </select>
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" name="address" placeholder="Office Location" />
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" name="phone" placeholder="Office Phone" />
                        </div>
                        <div class="form-group">
                            <select name="business-type" class="form-control">
                                <option class="form-group">Products Deal</option>
                                <option class="form-group">Bikes</option>
                                <option class="form-group">Accessories</option>
                                <option class="form-group">Both</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" name="link" placeholder="social-link(optional)" />
                        </div>
                        <div class="form-group">
                            <button type="button" class="button button--custom--grey button--main btn" id="logo">Upload Logo</button>

                            <input type="file" class="form-control hidden" id="logo1" name="logo1" /><span id="mylogo">* Format must be jpg,jpeg or png</span>
                        </div>
                        <?php echo form_error('logo'); ?>
                        <div class="form-group">
                            <textarea class="form-control" name="descrp" placeholder="Description(optional)"></textarea>
                        </div>
                        <h4>Primary Information</h4>
                        <hr>
                        <div class="form-group">
                            <input type="text" class="form-control" name="email" placeholder="Email" />
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" name="password" placeholder="Password" />
                        </div>

                        <div class="form-group">
                            <input type="submit" name="submit" class="btn button button--red button--main pull-right" value="Sign Up">
                        </div>
                    </form>
                </div>
            </div>
        </div>
        </div>
            </div>
           </section>

     <?php include 'footer.php'; ?>

вот мой контроллер

    function add_dealer()
     {
    //echo "<pre>"; print_r($_FILES);
    $config['upload_path'] = 'C:\xampp\htdocs\devilbirds\images\uploads';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']     = '0';
        $config['max_width'] = '0';
        $config['max_height'] = '0';
        $config['encrypt_name'] = 'TRUE';
        $config['overwrite'] = 'FALSE';
        $config['wm_text'] = 'Deveil Birds';
        $config['wm_type'] = 'text';
        $config['wm_font_path'] = 'C:\xampp\htdocs\devilbirds/fonts/fontawesome-webfont.ttf';
        $config['wm_font_size'] = '16';
        $config['wm_font_color'] = 'aabbcc';
        $config['wm_vrt_alignment'] = 'bottom';
        $config['wm_hor_alignment'] = 'center';
        $config['wm_padding'] = '20';

         $this->load->library('upload', $config);
         $this->image_lib->watermark();
        $abc = $this->upload->do_upload('logo1');
          $upload_data = $this->upload->data();
         // var_dump($abc);exit();
          $file_name = $upload_data['file_name'];
    $this->form_validation->set_rules('cname','CName','trim|required');
    $this->form_validation->set_rules('logo1','Logo1','trim');
    $this->form_validation->set_rules('address','Address','trim');
    $this->form_validation->set_rules('phone','Phone','trim|is_unique[bd_dealer.phone]');
    $this->form_validation->set_rules('owner','Owner','trim');
    $this->form_validation->set_rules('descrp','Descrp','trim');
    $this->form_validation->set_rules('business-type','Business-type','trim');
    $this->form_validation->set_rules('link','Link','trim');
    $this->form_validation->set_rules('email','Email','trim|is_unique[bd_dealer.email]');
    $this->form_validation->set_rules('password','Password','trim|min_length[5]|max_length[20]');
    $this->form_validation->set_rules('city','City','trim');
    if ($this->form_validation->run() == FALSE) 
    {
        $data['error'] = $this->session->set_flashdata('errors');
        $this->load->view('pages/signup',$data);// this is the link which loads my view i dont get how to go load that specific div from this url  
    }
    else
    {
            $userData = array(
                'company' => $this->input->post('cname'),
                'logo' => $file_name,
                'location' => $this->input->post('address'),
                'phone' => $this->input->post('phone'),
                'name' => $this->input->post('owner'),
                'description' => $this->input->post('descrp'),
                'business_type' => $this->input->post('business-type'),
                'social_link' => $this->input->post('link'),
                'email' => $this->input->post('email'),
                'password' => $this->input->post('password'),
                'city' => $this->input->post('city'));
             $data = array(
                'email' => $this->input->post('email'),
                'password' => $this->input->post('password'),
                'user_type' => '2');
            //var_dump($userData);exit();
            $this->Home_m->add_dealer($userData);
            $this->Home_m->users($data);
            redirect('Home/login'); 
    }
}

У меня есть две функции для двух разных форм на вкладках. Давайте предположим, что если я опубликую форму дилера, и у этой формы возникнут какие-либо проблемы, она будет перенаправлена ​​на страницу регистрации и покажет предварительную активную вкладку, которая является обычной регистрацией пользователя. Я хочу перенаправить на div, который содержит форму или регистрацию дилера. любая помощь будет оценена, спасибо заранее

1 Ответ

0 голосов
/ 29 октября 2018

В вашем контроллере при появлении ошибки сделайте это.

для одной ошибки формы

 $data['error'] = $this->session->set_flashdata('errors');
$data['div1'] = "div1";
    $this->load->view('pages/signup',$data);// this is the link which loads my view i dont get how to go load that specific div from this url ,i have pass div1 as parameter

Для ошибки формы два

$data['error'] = $this->session->set_flashdata('errors');
$data['div2'] = "div2";
$this->load->view('pages/signup',$data);// this is the link which loads my view i dont get how to go load that specific div from this url ,i have pass div1 as parameter

На вашей странице просмотра

<script>
           $(document).ready(function(){
               var div1 =  "<?php $div1; ?>";
               var div2 = "<?php $div2; ?>";
               if(div1=='' && div2==''){
                   $("#desc").show();
                   $("#rev").hide();
               }else if(div1=='div1' && div2==''){
                   $("#desc").show();
                   $("#rev").hide();
               }else if(div1=='' && div2=='div2'){
                   $("#desc").hide();
                   $("#rev").show();
               }
           })
           </script>

div1

<div class="aside-tabs__blocks about-tab js-tab-block no-b-border" id="desc">

Div2

<div class="aside-tabs__blocks about-tab js-tab-block no-b-border" id="rev">

Надеюсь, это поможет вам.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...