Welcome Guest, Not a member yet? Register   Sign In
Form validation not working
#1

(This post was last modified: 09-10-2017, 12:46 AM by jaynarayan.)

PHP Code:
//controller
<?php namespace App\Controllers;

use 
CodeIgniter\Controller;

 
   class Form extends Controller
    
{
 
           public function index()
 
           {
 
               helper(['form''url']);

 
           if (! $this->validate([]))
 
                   {
 
                           echo view('Signup', [
 
                               'validation' => $this->validation
                            
]);
 
                   }
 
                   else
                    
{
 
                           echo view('Success');
 
                   }
 
           }
 
   
PHP Code:
//success.php
<html>
<
head>
 
   <title>My Form</title>
</
head>
<
body>

<
h3>Your form was successfully submitted!</h3>

<
p><?= anchor('form''Try it again!'?></p>

</body>
</html> 
PHP Code:
//form
<html>
<
head>
 
   <title>My Form</title>
</
head>
<
body>

<?= 
$validation->listErrors() ?>

<?= form_open('form'?>

<h5>Username</h5>
<input type="text" name="username" value="" size="50" />

<h5>Password</h5>
<input type="text" name="password" value="" size="50" />

<h5>Password Confirm</h5>
<input type="text" name="passconf" value="" size="50" />

<h5>Email Address</h5>
<input type="text" name="email" value="" size="50" />

<div><input type="submit" value="Submit" /></div>

</form>

</body>
</html> 

I am following the tutorial from the docs , but the form is not displaying. it shows validation is successful every time. try it again link is also not working
          Heart  love codeigniter Heart
          Learning  best  practices
     Rate my post if you found it helpfull
Reply
#2

Try this:
Change <input type="submit" value="Submit" /> to <input type="submit" name="submitted" value="Submit" />
and
if (! $this->validate([])) to if ($this->request->getPost("submitted") == null || ! $this->validate([]))
Simpler is always better
Reply
#3

(This post was last modified: 09-28-2017, 12:29 AM by jaynarayan.)

The  Issue was Fixed in this commit
          Heart  love codeigniter Heart
          Learning  best  practices
     Rate my post if you found it helpfull
Reply




Theme © iAndrew 2016 - Forum software by © MyBB