Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The '<em>can not enter</em>' message is passed back after the rules have been passed. It is inside of the <strong>if</strong> statement when the form validation is true.</p> <p>If you want this message to be displayed either load the message into the view, or set it as flash data.</p> <p>Why not make the puede_entrar() model call into a custom callback form validation rule, then it can be added to the rules that are set.</p> <p>Look <a href="http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#callbacks" rel="nofollow">here</a> for information on custom callbacks.</p> <p>This is how I would code your controller;</p> <pre><code>&lt;?php class Foo extends CI_Controller { public function anuncios() { // xxs_clean set globally in config $this-&gt;form_validation-&gt;set_rules('drcorreo','Nombre de usuario', 'trim|required|min_length[5]|callback_puede_entrar'); // should use sha1 at least for hashing, see http://www.freerainbowtables.com/tables/ $this-&gt;form_validation-&gt;set_rules('contrasena','Contrase&amp;ntilde;a', 'trim|required|min_length[8]|md5'); if($this-&gt;form_validation-&gt;run()) { $this-&gt;load-&gt;model('modelo_bd'); $data['vanc']=$this-&gt;modelo_bd-&gt;datos(); $this-&gt;load-&gt;view('vancios',$data); } else { // redisplay form with validation errors $this-&gt;load-&gt;view('indice'); } } public function puede_entrar($val) { $this-&gt;load-&gt;model('modelo_usuarios'); if($this-&gt;modelo_usuarios-&gt;puede_entrar()) { return TRUE; } else { $this-&gt;form_validation-&gt;set_message('puede_entrar', 'Las reglas no son validas.'); return FALSE; } } } </code></pre> <p>The view (assuming you have autoloaded or have loaded <code>$this-&gt;load-&gt;helper(array('form', 'url')); $this-&gt;load-&gt;library('form_validation');</code> elsewhere);</p> <pre><code>&lt;div id="acformulario"&gt; &lt;form action="http://localhost/Pruebas/index.php/cindice/anuncios" method="post"&gt; &lt;?php echo form_error('drcorreo'); ?&gt; &lt;label for="correo" id="dcorreo"&gt;Direcci&amp;oacute;n de correo&lt;/label&gt; &lt;input type="text" name="drcorreo" id="dcc"/&gt;&lt;br /&gt;&lt;br /&gt; &lt;label for="contrasenya" id="cont"&gt;Contrase&amp;ntilde;a&lt;/label&gt; &lt;?php echo form_error('contrasena'); ?&gt; &lt;input type="password" name="contrasena" id="cmcont"/&gt;&lt;br /&gt;&lt;br /&gt; &lt;!--&lt;label for="enviar"&gt;&lt;/label&gt;--&gt; &lt;input type="submit" name="envia" id="bentrar" value="Entrar" /&gt; &lt;/form&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload