Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6059721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:44:36+00:00 2026-05-23T08:44:36+00:00

I am trying to validate a form and save it in my database. I

  • 0

I am trying to validate a form and save it in my database. I am using codeigniter’s validation library and it fails.

this is the ajax function inside the view

function save_form(){   
    $.ajax({
        url: '/projects/cafe/index.php/welcome/save_form',
        type: 'post',
        data: {'fname' : $('#fname').val(),
                'lname' : $('#lname').val(),
                'story_name' : $('#story_name').val(),
                'email' : $('#email').val(),
                'address_street' : $('#address_street').val(),
                'city' : $('#city').val(),
                'state' : $('#state').val(),
                'zip' : $('#zip').val(),
                'phone1' : $('#phone1').val(),
                'phone2' : $('#phone2').val(),
                'phone3' : $('#phone3').val(),
                'age_18' : $('#age_18').val(),
                'ci_csrf_token' : $('input[name=ci_csrf_token]').val()},
        success: function(data, textStatus, jqXHR){
            //Redirect user to next page here...
            if(data == '1'){
                location.href = 'http://www.voltage.com/projects/cafe/index.php/welcome/create4';
            }else{
                alert('form save failed');
            }
        },
        error: function(jqXHR, textStatus, errorThrown){
            console.log('error: '+jqXHR);
            console.log(textStatus);
            console.log(errorThrown);
        }
    });
} 

this is the function in my controller

class Welcome extends MY_Controller {
public function save_form(){
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');

        $this->form_validation->set_rules('fname', 'First Name', 'required|min_length[6]|max_length[12]');
        $this->form_validation->set_rules('lname', 'Last Name', 'required');
        $this->form_validation->set_rules('story_name', 'Story Name', 'required');
        $this->form_validation->set_rules('email', 'email', 'required');
        $this->form_validation->set_rules('address_street', 'Street Address', 'required');
        $this->form_validation->set_rules('city', 'City', 'required');
        $this->form_validation->set_rules('state', 'State', 'required');
        $this->form_validation->set_rules('zip', 'Zip', 'required');
        $this->form_validation->set_rules('phone1', 'Area Code', 'required');
        $this->form_validation->set_rules('phone2', 'Phone Number', 'required');
        $this->form_validation->set_rules('phone3', 'Phone Number', 'required');
        $this->form_validation->set_rules('age_18', 'Age Verification', 'required');

        if($this->form_validation->run() == FALSE)
            die();

        $this->load->model('user');

        $results = $this->user->save_form($this->session->userdata('fbid'),
                                            $this->input->post());

        echo $results;
    }

What I’m confused about is how if($this->form_validation->run() == FALSE) passes if I don’t have any values for phone1, phone2, or phone3, which are required.

        $this->form_validation->set_rules('phone1', 'Area Code', 'required');
        $this->form_validation->set_rules('phone2', 'Phone Number', 'required');
        $this->form_validation->set_rules('phone3', 'Phone Number', 'required');

this is what being sent to the server fname=First&lname=Last&story_name=Your+Story&email=yourname%40domain.com&address_street=Street&city=City&state=State&zip=Zip&phone1=&phone2=&phone3=&age_18=

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:44:36+00:00Added an answer on May 23, 2026 at 8:44 am

    I’ve been staring at this and can’t see why it wouldn’t work. Are you also getting unexpected behavior when other fields are omitted or is it strictly limited to these 3 fields? The only thing “odd” I see, and maybe this is keeping the form_validation library from loading correctly, is the

    <?=fname?>
    

    you are passing in this line:

    $this->form_validation->set_rules('<?=$fname?>', 'First Name', 'required|min_length[6]|max_length[12]');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to validate a form using an AJAX call to check available inventory.
I was trying to validate an XML signature. The validation according to this tutorial
I'm trying to convert a form from synchronous to asynchronous using the Ajax.BeginForm helper
I'm trying to validate a form using Data Annotation. It seems great for string
I am trying to validate a form, using jQuery validate and show errors messages
I'm trying to validate a form using jquery validate plugin and I'm having a
I'm trying to validate a model containing other objects with validation rules using the
I am currently trying to validate a form server side, the way it works
Hey there, I'm trying to validate a form with Zend_Validate and Zend_Form. My element:
I'm trying to validate that a submitted URL doesn't already exist in the database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.