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 8697065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:25:36+00:00 2026-06-13T01:25:36+00:00

Been struggling with this for about 4 hours, I’m attempting to have a modal

  • 0

Been struggling with this for about 4 hours, I’m attempting to have a modal drop down (Twitter bootstrap modal) that contains a form to create a Company. This is built in CodeIgniter.

I’m having issues with input type=”submit” and input type=”button”.

I only have 1 required field, which is Company Name. If I use input type=”button”, the validation will fire correctly inside of the modal, however the form will only INSERT just the company name, along with company_id, user_id, active, and cdate.

Now if I use input type=”submit”, all the data inserts fine. However, the validation breaks and I get a “Page cannot be found” after clicking “Create Company”, the data is still inserting though.

Any ideas? Thanks! New to AJAX…

My AJAX function:

   $(document).ready(function(){

  $('#create_btn').live('click', function(){
      //we'll want to move to page specific files later

    var name = $('#name').val();

    $.ajax({
        url: CI_ROOT + "members/proposals/add_client",
        type: 'post',
        data: {'name': name },
        complete: function(r){
          var response_obj = jQuery.parseJSON(r.responseText);

          if (response_obj.status == 'SUCCESS')
          {
              window.location = CI_ROOT + response_obj.data.redirect;
          }
          else
          {       
            $('#error_message2').html(response_obj.data.err_msg);
          }
        },
    });     


  });

});

My controller function which handles the insert:

    function add_client()
{

    $this->form_validation->set_rules('name', 'Company Name', 'trim|required|xss_clean');

    load_model('client_model', 'clients');
    load_model('industry_model');

    $user_id = get_user_id();
    $company_id = get_company_id();

    if (!$user_id || !$company_id) redirect('home');

    if ($_POST)
    {

        if ($this->form_validation->run() == TRUE)
        { 

        $fields = $this->input->post(null , TRUE);


        $fields['user_id'] = $user_id;
        $fields['company_id'] = $company_id;
        $fields['active'] = 1;
        $fields['cdate'] = time();


        $insert = $this->clients->insert($fields);

            if ($insert)
            {
                $this->message->set('alert alert-success', '<h4>Company has been added</h4>');
                header('location:'.$_SERVER['HTTP_REFERER']);
            }
            else
            {
                $this->message->set('alert alert-error', '<h4>There was an issue adding this Company, please try again</h4>');
            }                   


        }


        else
        {  
            $err_msg =  validation_errors('<div class="alert alert-error">', '</div>'); 
            $retval = array('err_msg'=>$err_msg);
            $this->ajax_output($retval, false);
        }

    }

    $this->data['industries'] = array(0=>'Select Industry...') + $this->industry_model->dropdown('industry');   

    $this->insertMethodJS();
    $this->template->write_view('content',$this->base_path.'/'.build_view_path(__METHOD__), $this->data);           
    $this->template->render();
}

And finally, my view:

    <div class="modal hide fade" id="milestone" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width: 600px !important;">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Add a Company</h3>
  </div>

  <div class="modal-body">

    <?php echo form_open_multipart(base_url().'members/proposals/add_client', array('class' => '', 'id' => 'client_form'));?>   

    <div id="error_message2"></div> 

    <div class="row-fluid">
        <div class="span5">

            <input type="hidden" name="cdate" id="cdate" value="" />

            <div class="control-group">
            <label class="control-label">Company Name: <span style="color: red;">*</span></label>
                <div class="controls">
                    <input type="text" id="name" name="name" value=""/>
                </div>
            </div>  

            <div class="control-group">
            <label class="control-label">Company Abbreviation:<span style="color: red;">*</span></label>
                <div class="controls">
                    <input type="text" id="abbreviation" name="abbreviation" value=""/>
                </div>
            </div>      


            <div class="control-group">
            <label class="control-label">Company Image: </label>
                <div class="controls">
                        <input type="file" name="client_image" size="20" /> 
                </div>
            </div>

            </div>  

            <div class="span5">

            <div class="control-group">
            <label class="control-label">Website:</label>
                <div class="controls">
                    <input type="text" id="website" name="website" value=""/> 
                </div>
            </div>  

       </div>

    </div>  



<div class="row-fluid">
    <div class="span5" style="margin-top: 25px;">

    <div class="control-group">
            <div class="controls">
                <p><strong>Client</strong></p>
            </div>
    </div>  


    <div class="control-group">
        <label class="control-label">Address 1:</label>
            <div class="controls">
                <input type="text" id="address1" name="address1" value=""/>
            </div>
    </div>  

    <div class="control-group">
        <label class="control-label">Address 2:</label>
            <div class="controls">
                <input type="text" id="address2" name="address2" value=""/>
            </div>
    </div>      

    <div class="control-group">
        <label class="control-label">City:</label>
            <div class="controls">
                <input type="text" name="city" id="city"  value=""/>
            </div>
    </div>  


    <div class="control-group">
        <label class="control-label">State:</label>
            <div class="controls">
                <?= form_dropdown('state', usa_state_list(), set_value('state'), 'id=state');  ?>     
            </div>
    </div>  

    <div class="control-group">
        <label class="control-label">Zip:</label>
            <div class="controls">
                <input type="text" id="zip" name="zip" value=""/>
            </div>
    </div>  

    <div class="control-group">
        <label class="control-label">Country:</label>
            <div class="controls">
                <?= form_dropdown('country', country_list(), set_value('country'), 'id=country');  ?>    
            </div>
    </div>

  </div>
</div>
</div>

  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button type="submit" class="btn btn-primary" id="create_btn">Create Company</button>
  </div>
 </form> 
</div>

So again, to summarize. With input type=”button”, my validation works great within the modal and only the Company Name is inserting into the database along with company_id, user_id, active, and cdate.

Now, with input type=”submit”, all data inserts great, however validation fails and I get a redirect to a page cannot be found.

Again, thanks!

  • 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-06-13T01:25:38+00:00Added an answer on June 13, 2026 at 1:25 am

    The issue is with your ajax function call.

    You need to prevent the form from firing (and thus submitting via post to the url in action):

    Change:

    $('#create_btn').live('click', function(){
    

    To:

    $('#create_btn').live('click', function(e){
        e.preventDefault();
    

    This should fix the issue. If it doesn’t, let me know and I’ll do more digging. I would also recommend switching live to on so that you future-proof yourself. on handles the same stuff as live, bind, etc. in a single function with more efficiency.

    Edit: To explain what’s going on (and why you must use e.preventDefault();), it is because <input type="submit"> will actually submit the form to the url specified in the <form> tag’s action attribute. Thus, what’s happening with your code is that your javascript is running as soon as you click the button, and then the native browser submit event is occurring immediately afterwards.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with this issue for about 10 hours straight. I really
I have been struggling for several hours about this problem, although it seems ridiculous
I have been struggling with this error for more than two hours: error: aggregate
I've been struggling with this problem for 5 hours and I have a feeling
I've posted about this before but have been struggling to come up with a
Link to code I have been struggling with this code for about two weeks
I have been struggling with this NHibernate issue for hours. I extensively researched on
I've been struggling with this issue for a few hours. I have a table
I know there's a lot of questions about this but I've been struggling with
Been struggling with this simple selector problem a couple of hours now and must

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.