Question: Removing Required Difficulty

Removing Required Difficulty

Hello, I read your tutorial but there is difficulty trying to Removing Required causes of validation could you please improve it? For example in customer adding I need customer name and mobi

MB

Mehdi boudhir

Asked
Hello,
I read your tutorial but there is difficulty trying to Removing Required causes of validation could you please improve it?
For example in customer adding I need customer name and mobile number only
"
To remove validation, you will need to edit few files
1. app/controllers/admin/sleectTheControllerYouWantEdeit
2. themes/default/admin/selectTheAppropriateFolderOrFile
3. Database table to accept null value for that field
Please alter the database table to accept the null for your inputs (postal code).
1. Open phpmyadmin and select the database
2. Select the customers table
3. Click Structure
4. Click change on field name (city) line
5. Tick/check the null checkbox
6. Click Save
Now try to add customer without city. You won't get any error as we have remove the
required validation for this input.
You can use these steps to remove the required field for any other fields.
Please be careful while removing the required from some fields as these might be used
in other modules, like removing the required validation for email to accept customer
with no email could cause issues/errors for emailing the invoice to customer in sale/pos.
Let say we want to remove the restriction from postal code from add customer
Open themes/default/views/customers/add.php and look for city input code
<?php echo form_input('city', '', 'class="form-control" id="city" required="required"'); ?>
We need to remove the required (you might need to check pattern) attributes. We will delete the code below
required="required"
You need to check the validation rules in app/config/form_validation.php We are validation
if ($this->form_validation->run('companies/add') == true) {
so search 'companies/add' array and then look for array with field 'city' and remove the required from rules
and now your rules will be as
'rules' => 'other_validation'
For some pages, you need to check the rules in controller as app/controllers/customers.php and look for
function add() and see the validation line on top as
$this->form_validation->set_rules('city', lang("city"), 'required|other_validation');
Remove the line, if you want to keep other validation, please remove required from last part of the
validation. After this our validation line will look as
$this->form_validation->set_rules('city', lang("city"), 'other_validation');
  • MS

    Mian Saleem

    Answered
    Hello,

    You should mention about `what field are you trying to remove?`, `what steps are you done?` and `what step is not clear to you?`

    This guide for developers, if you not sure, feel free to hire any developer to help you modify the item code as you need.

    Thank you
  • MB

    Mehdi boudhir

    Answered
    I need only 2 fields : customer name +customer phone number
    I did these steps:"app/controllers/admin/sleectTheControllerYouWantEdeit
    themes/default/admin/selectTheAppropriateFolderOrFile
    Database table to accept null value for that field Please alter the database table to accept the null for your inputs (postal code).
    Open phpmyadmin and select the database
    Select the customers table
    Click Structure
    Click change on field name (city) line
    Tick/check the null checkbox
    Click Save Now try to add customer without city"
    I got errors with validations.
    I need also to make all these steps with "edit customer" file.
    Best regards .
  • EG

    Enyinnaya Gift

    Answered
    **[Mehdi boudhir](/u/boudo2022)** Please get a developer to assist you before you mess things up.
  • MB

    Mehdi boudhir

    Answered
    I see other systems made with required name and phone number fields only.
    Those are the useful fields.
  • MS

    Mian Saleem

    Answered
    Hello,

    Yes, you will need to remove the validation for both add & edit methods along with their views.

    I am not sure about removing the validation yet but will check in future updates.

    Thank you
  • Login to Reply