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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:13:03+00:00 2026-06-14T23:13:03+00:00

I have a list of cities in my database. There is an edit button

  • 0

I have a list of cities in my database. There is an edit button that brings up a modal with a form where they can change the name of the city and submit. I’m having a hard time getting the city_id to pass from the edit button through the modal and to the controller. I get a “message undefined variable for the city_id on the line that tries to put the city_id in the form open code.

Adding a modal into the mix has made this confusing to me.

View Code

<a href="#" class="btn edit-modal" data-id="<?php echo $c['city_id']; ?>"  data-name="<?php echo  $c['city_name']; ?>">Edit</a>

<!-- Modal for Edit -->
<div class="modal hide" id="editCityDialog">
<div class="modal-header">
    <button class="close" data-dismiss="modal">x</button>
    <h3>Edit City</h3>
</div>
<div class="modal-body">
    <?php $this->load->helper('form'); ?>
        <?php echo form_open('/cities/edit_city/'. $city_id); ?>
        <label class="control-label" for="name">City</label>
        <input type="text" name="city_name" id="city_name" value=""/><br />
        <input type="submit" class="btn-small btn-primary" value="Edit City" />
        <button class="btn-small" data-dismiss="modal">Cancel</button>
    <?php echo form_close(); ?>
</div>

<!-- jQuery for Modal -->
<script>
  // scripts for modal windows
$(document).on("click", ".edit-modal", function () {
    var city_name = $(this).data('name');
    var city_id = $(this).data('id');
    $(".modal-body #city_name").val( city_name );
    $('#editCityDialog').modal('show');
});
</script>

Controller Code

// Edit City
public function edit_city() {
    $id = $this->uri->segment(3);

    if ($this->input->city('submit')) {
        $city_name = $this->input->xss_clean($this->input->city('city_name'));
        $this->cities_model->edit_city($city_id, $city_name);
    }
}

Model Code

// Edit City
public function edit_city($city_id, $city_name) {
    $data = array(
        'city_name' => $city_name
    );
    $this->db->where('city_id', $city_id);
    $this->db->update('cities', $data);
}
  • 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-14T23:13:05+00:00Added an answer on June 14, 2026 at 11:13 pm

    You can use the city_id you already have and set the action with that:

    $(document).on("click", ".edit-modal", function () {
        var city_name = $(this).data('name');
        var city_id = $(this).data('id');
        $(".modal-body #city_name").val( city_name );
        //set the forms action to include the city_id
        $(".modal-body form").attr('action','/cities/edit_city/'+city_id);
        $('#editCityDialog').modal('show');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of cities, and i want a user can choose one
I have a list of cities names that is variable and I want to
I have a select list, where you can choose multiple cities - When choosing
I have CreateDiscountViewByUser discountViewByUser it contains a list of cities that are chosen by
I have a list of cities name. I just want to do, if user
I have a List Of cities name. I am not sure, I will be
I have a text input that has autocomplete connected to a list of cities
My database has following structure: Every Region ( CountryStates ) can have many cities
I have list of input area in the form with id like contact1_title, contact2_title,
i have list of rows that user select and i want to delete them,

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.