Welcome Guest, Not a member yet? Register   Sign In
Validate email if its typed in?
#1

Hi,

I have a form, where the email is not required, but when someone types it in I would like to validate it. So i tried the following approach, but than I get the error, that its not a valid email, if I do not type an email in the form.

Does someone have an Idea?

Thanks

Code:
<?php
namespace App\Models;

use CodeIgniter\Model;

class ContactModel extends Model
{

    protected $table = 'contact';
    protected $primaryKey = "idcontact";
    protected $allowedFields = ['name', 'email', 'phone', 'mobile', 'web', 'addresses_idaddresses',];
    protected $useTimestamps = true;
    protected $createField = 'created_at';
    protected $updatedField = 'updated_at';
    protected $delteField = 'deleted_at';
    protected $returnType = 'array';

    protected $validationRules = [
      'name' => 'required',
      'email' => 'valid_email',

    ];



}
Reply
#2

I think you'll need to include the permit_empty rule.

See https://codeigniter.com/user_guide/libra...able-rules
Reply




Theme © iAndrew 2016 - Forum software by © MyBB