title: CodeIgniter passing a variable to a Modal then to a View
body: <p>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.</p>
  
  <p>Adding a modal into the mix has made this confusing to me.</p>
  
  <p>View Code</p>
  
  <pre><code>&lt;a href="#" class="btn edit-modal" data-id="&lt;?php echo $c['city_id']; ?&gt;"  data-name="&lt;?php echo  $c['city_name']; ?&gt;"&gt;Edit&lt;/a&gt;
  
  &lt;!-- Modal for Edit --&gt;
  &lt;div class="modal hide" id="editCityDialog"&gt;
  &lt;div class="modal-header"&gt;
      &lt;button class="close" data-dismiss="modal"&gt;x&lt;/button&gt;
      &lt;h3&gt;Edit City&lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="modal-body"&gt;
      &lt;?php $this-&gt;load-&gt;helper('form'); ?&gt;
          &lt;?php echo form_open('/cities/edit_city/'. $city_id); ?&gt;
          &lt;label class="control-label" for="name"&gt;City&lt;/label&gt;
          &lt;input type="text" name="city_name" id="city_name" value=""/&gt;&lt;br /&gt;
          &lt;input type="submit" class="btn-small btn-primary" value="Edit City" /&gt;
          &lt;button class="btn-small" data-dismiss="modal"&gt;Cancel&lt;/button&gt;
      &lt;?php echo form_close(); ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;!-- jQuery for Modal --&gt;
  &lt;script&gt;
    // 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');
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Controller Code</p>
  
  <pre><code>// Edit City
  public function edit_city() {
      $id = $this-&gt;uri-&gt;segment(3);
  
      if ($this-&gt;input-&gt;city('submit')) {
          $city_name = $this-&gt;input-&gt;xss_clean($this-&gt;input-&gt;city('city_name'));
          $this-&gt;cities_model-&gt;edit_city($city_id, $city_name);
      }
  }
  </code></pre>
  
  <p>Model Code</p>
  
  <pre><code>// Edit City
  public function edit_city($city_id, $city_name) {
      $data = array(
          'city_name' =&gt; $city_name
      );
      $this-&gt;db-&gt;where('city_id', $city_id);
      $this-&gt;db-&gt;update('cities', $data);
  }
  </code></pre>