2017-11-27 3 views
0

ich codeigniter.In meine Ansicht Datei verwende ich habe eine Form, und ich verwende Bootstrap-Validator Feld validation.Bootstrap Validator validationg Formularfeld überprüfen correctly.But das Problem ist, dass ich mit codeigniter arbeitete. Die Funktion wird in Controller geschrieben. Nach dem Formular eingereicht sollte es auf Funktion, die in Controller geschrieben wird, umleiten. Hier habe ich ein Problem, wenn ich auf Absenden nach erfolgreicher Validierung klicken, führte es keine Aktion.Es leitet nicht auf Controller wo neu Funktion ist, wie ich Seite nach erfolgreicher Validierung umleiten. Ich benutze Javascript nicht mit Ajax.Seite Umleitung nach dem erfolgreichen Bootstrap-Validator

Hier mein Code of View-Datei ist:

<form class="" data-toggle="validator" role="form" id="sms_form" method="Post" action="<?php echo site_url('SMS/sendIndividualMsg/'.$row->pro_id)?>">      

    <div class="col-md-12"> 
        <div class="form-group"> 
        <label for ="message"><strong>Message</strong></label> 
        <textarea class="form-control" id="comment_body" name="message" placeholder=" Your Message"></textarea>     

        </div> 
        <div> 

        <?php echo form_submit(['name' => 'submit' ,'class' => 'btn btn-default' , 'value' => 'Send Message']); ?> 


        </div> 
        </div> 
       </form> 

Hier mein Code von Bootstrap-Validator ist:

<script> 
    $('#sms_form').bootstrapValidator({ 
     // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later 
     feedbackIcons: { 
      valid: 'glyphicon glyphicon-ok', 
      invalid: 'glyphicon glyphicon-remove', 
      validating: 'glyphicon glyphicon-refresh' 
     }, 
     fields: { 
      message:{ 
      validators: { 
       regexp: { 
         regexp: /^[a-zA-Z0-9_\.\s]+$/, 
         message: 'The message can only consist of alphabetical, number, dot and underscore' 
        }, 
        notEmpty: { 
         message: 'Please supply your message' 
        } 
      } 
      }   
     } 
    }); 
</script> 

Hier ist mein Code von controller.This ist Funktion, wo ich Umleitung wollen:

public function sendIndividualMsg($pro_id) 
{ 
} 
+0

die Version von FormValidation sind u verwendet und welche Version von Bootstrap? – sintakonte

Antwort

1

verwenden ..

<script> 
    $('#sms_form').bootstrapValidator({ 
     // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later 
     feedbackIcons: { 
      valid: 'glyphicon glyphicon-ok', 
      invalid: 'glyphicon glyphicon-remove', 
      validating: 'glyphicon glyphicon-refresh' 
     }, 
     fields: { 
      message:{ 
      validators: { 
       regexp: { 
         regexp: /^[a-zA-Z0-9_\.\s]+$/, 
         message: 'The message can only consist of alphabetical, number, dot and underscore' 
        }, 
        notEmpty: { 
         message: 'Please supply your message' 
        } 
      } 
      }   
     } 
     .on('success.field.fv', function(e, data) { 
     $("form").submit(); 
     }); 
    }); 
</script> 
+0

Swadesh nach dem Schreiben dieses Codes jetzt Validierung funktioniert nicht –

+0

Was ist "success.fied.fv" ist es eine ID oder eine eingebaute Variable? –

+0

Insted von .field.fv Klasse benutzen, um Ihre Klassennamen –

0

War das nicht ein Spaß zu spielen.

lange Geschichte kurz.

Sie benötigen JS haben Nachdem Sie Ihre jquery.js laden Datei (die alle Teil Ihrer Bootstrap js Dateien ist). Dein aktuelles JS funktioniert.

Sie müssen es auch nach dem bootstrapValidator.js, wenn Sie dies nicht tun, müssen Sie Ihre js wickeln in ...

$(document).ready(function() { 
    // JS Code here if this is rendered before bootstrapValidator.min.js 
}) 

Der Trick hier ist die Konsole Nachrichten in Ihrem Browser zu sehen Entwickler-Tools ...

Nur zu sagen, es nicht funktionieren, ohne Nachrichten an der Konsole sucht, wird nicht hilfreich sein.

Wenn Sie keine Ahnung, was ich bin auf etwa ich es später klären werde.

UPDATE: Dies ist der Testcode, den ich verwendet habe, um Ihr Problem zu untersuchen.

Ansicht Test - Ansichten/form_validator_view.php

<!doctype html> 
<html lang="en"> 
<head> 
    <title>Hello, world!</title> 
    <!-- Required meta tags --> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> 

    <!-- Bootstrap CSS --> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous"> 
</head> 
<body> 
<h1>Hello, world!</h1> 

<div class="container"> 
    <form class="" data-toggle="validator" role="form" id="sms_form" method="Post" action="<?php echo site_url('sms/sendIndividualMsg/' . 1) ?>"> 
     <div class="form-group"> 
      <label for="message"><strong>Message</strong></label> 
      <div class="col-md-12"> 
       <textarea class="form-control" id="message" name="message" placeholder=" Your Message"></textarea> 
      </div> 
     </div> 

     <div class="form-group"> 
      <div class="col-xs-9 col-xs-offset-3"> 
       <button type="submit" class="btn btn-primary" name="signup" value="Sign up">Submit</button> 
      </div> 
     </div> 
    </form> 
</div> 

<!-- Optional JavaScript --> 
<!-- jQuery first, then Popper.js, then Bootstrap JS --> 
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script> 
<script src="//oss.maxcdn.com/jquery.bootstrapvalidator/0.5.2/js/bootstrapValidator.min.js"></script> 


<script> 
$(document).ready(function() { 
    // JS Code here if this is rendered before bootstrapValidator.min.js 
}) 
// $(document).ready(function() { 
     $('#sms_form').bootstrapValidator({ 
      // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later 
      feedbackIcons: { 
       valid: 'glyphicon glyphicon-ok', 
       invalid: 'glyphicon glyphicon-remove', 
       validating: 'glyphicon glyphicon-refresh' 
      }, 
      fields: { 
       message: { 
        validators: { 
         regexp: { 
          regexp: /^[a-zA-Z0-9_\.\s]+$/, 
          message: 'The message can only consist of alphabetical, number, dot and underscore' 
         }, 
         notEmpty: { 
          message: 'Please supply your message' 
         } 
        } 
       } 
      } 
     }); 
// }) 
</script> 

</body> 
</html> 

Test Controller - Controller/Sms.php

<?php 

class Sms extends CI_Controller { 
    public function __construct() { 
     parent::__construct(); 
     $this->load->helper('url'); 
     $this->load->helper('form'); 
    } 

    public function index() { 
     $this->load->view('form_validator_view'); 
    } 

    public function sendIndividualMsg($id) { 
     echo "The ID is $id"; 

     var_dump($_POST); 
    } 
} 
Verwandte Themen