CodeIgniter Forums

Full Version: Many form_option elements within one pair of "<li></li>."
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]EthanSP[/eluser]
How do I accomplish this: 2 option buttons each w/ a label on the right that is within <li>?

This is my code in HTML:

<ul>
<li><label>&lt;input type="radio" name="Race" value="asian" style="width: 12px;" /&gt; Asian</label>
<label>&lt;input type="radio" name="Race" value="nonasian" style="width: 12px;" /&gt; Non-Asian</label></li>
</ul>

I'm stucked here:

&lt;? $list = array(
form_input($fid),
form_input($fln),
form_input($ffn),
form_input($fmn),
form_radio($fgf),
form_label('female'),
form_radio($fgm),
form_label('male'),

);
$attributes = array('class'=>'jdatacol');
echo ul($list, $attributes); ?&gt;

I tried searching the forum but to no avail. Sad

El Forum

[eluser]Michael Wales[/eluser]
I think the form and html helpers get in the way more ofen than not.

What's wrong with just doing it in plain-old HTML? You won't be calling functions, thus reducing server load and decreasing processing time/load times for your users, plus it's infinitely more "readable" than that horrible array...

El Forum

[eluser]EthanSP[/eluser]
[quote author="Michael Wales" date="1211555204"]I think the form and html helpers get in the way more ofen than not.

What's wrong with just doing it in plain-old HTML? You won't be calling functions, thus reducing server load and decreasing processing time/load times for your users, plus it's infinitely more "readable" than that horrible array...[/quote]

Yes, I agree. I thought of that as well. But CI conventions dictate (please correct me if I'm mistaken) the complete separation of data (in models) from presentation (in views). I just thought of a workaround:

form_radio($fgf)
.form_label('Female')
.form_radio($fgm)
.form_label('Male')

But again you are right; the issue here will be LOAD TIME vs. STICKING TO CONVENTIONS. Would non-compliance to such convention bring about a crucial issue in the future processing of the system that I'm working on?

El Forum

[eluser]Michael Wales[/eluser]
Your understanding of conventions is correct but what you are labelling as data vs. view is wrong.

A form is a view - it is a means of collecting data not the data itself (which is the model). Even a completed form is a view - because it is using that particular means to present the data to us.

A quick example:
Code:
class Person {
  var $first_name;
  var $last_name;
  var $height;
  var $weight;
}

This class is a basic definition of a piece of data - descriptive characteristics of a person, it is the model.

Now - let's move on to the controller. How do we get this data? Well, we could use a form, parse XML files, accept mobile text messages, etc.

Now - the view. XML and text messages don't require a view... so we don't need to worry about that. But, how are we going to accept POST input? Through an HTML form of course! So, in our view - we build an HTML form.

What if we went through and deleted all of the HTML tags from this form view and replaced them with <p> tags? Would that change what the data within the model is? Nope - it's purely presentational.

El Forum

[eluser]EthanSP[/eluser]
So, how do I use the data that I inputted in my form. Because when I submit the form, a 404 file not found appears.

Here's my model code:
function forms_menu() {
$data = $this->get_paths();
$data['menu_items'] = $this->get_titles();
$this->load->library('BangungotMenu');
$bmenu = new BangungotMenu;
$data['bmenu'] = $bmenu->show_menu($data['menu_items']);
return $data;
}

function get_fields() {
$data['title'] = 'Demographics';
$data['fid'] = array('name'=>'id');
$data['ffn'] = array('name'=>'fname');
$data['fmn'] = array('name'=>'mname');
$data['fln'] = array('name'=>'lname');
$data['fgf'] = array('name'=>'gender','value'=>'male','style'=>'width: 12px;');
$data['fgm'] = array('name'=>'gender','value'=>'female','style'=>'width: 12px;');
$data['fbd'] = array('name'=>'bday');
$data['fag'] = array('name'=>'age');
$data['fcs'] = array('name'=>'cstat');
$data['fra'] = array('name'=>'race','value'=>'asian','style'=>'width: 12px;');
$data['frn'] = array('name'=>'race','value'=>'non-asian','style'=>'width: 12px;');
$data['fct'] = array('name'=>'city');
$data['fpv'] = array('name'=>'province');
return $data;
}

function add_entry() {
$this->load->database();
$this->db->insert('demographics', $data);
}

Here's my view/form code:
<div class="jwin1">
&lt;?= $title;
echo form_open('demographics'); ?&gt;
</div>
<div class="jwin2">
<div class="jmenu">
<ul class="jdatacol" > &lt;!-- style="width:120px;" --&gt;
<li>Patient ID No. </li>
<li>Last Name</li>
<li>First Name</li>
<li>Middle Name</li>
<li>Gender</li>
<li>Birthday</li>
<li>Age</li>
<li>Civil Status</li>
<li>Ethnicity</li>
<li>Municipality/City</li>
<li>Provincial Address </li>
</ul>
</div>
<div class="jmenu">
&lt;? $attributes = array('class'=>'jdatacol');
$list = array(
form_input($fid),
form_input($fln),
form_input($ffn),
form_input($fmn),
form_radio($fgf)
.form_label('female')
.form_radio($fgm)
.form_label('male'),
form_input($fbd),
form_input($fag),
form_input($fcs),
form_radio($fra)
.form_label('Asian')
.form_radio($frn)
.form_label('Non-Asian'),
form_input($fct),
form_input($fpv));
echo ul($list, $attributes); ?&gt;
</div>
<div class="jwin3">
&lt;? //&lt;input name="save" type="button" value="Save changes" class="jbutton" /&gt;</div>
echo form_submit('mysubmit','Submit!');
echo form_close(); ?&gt;
</div>

Here's my controller code:
function demographics() {
$this->load->helper('form');
$this->load->helper('html');
$this->load->model('bangungot_model');
if($this->input->post('mysubmit')) {
$this->bangungot_model->add_entry();
}
$data = array_merge($this->bangungot_model->get_paths(),
$this->bangungot_model->get_fields());
$this->load->view('demographics', $data);
}

I will be glad for your help.


Ethan