Help form some basics - El Forum - 03-27-2012
[eluser]Unknown[/eluser]
Hellow, I'm new user of codeigniter and just started with php and that stuffs. I have some basic questions about forms and connect to database with model, etc. I'll show on examples:
View:
Code: <?php echo validation_errors('<p class="error">'); ?>
<?php echo form_open("user/registration"); ?>
<p>
<label for="user_name">Username:</label>
<input type="text" id="user_name" name="user_name" value="<?php echo set_value('user_name'); ?>" />
</p>
<p>
<label for="email_address">Email:</label>
<input type="text" id="email_address" name="email_address" value="<?php echo set_value('email_address'); ?>" />
</p>
<p>
<label for="password">Password:</label>
<input type="password" id="password" name="password" value="<?php echo set_value('password'); ?>" />
</p>
<p>
<label for="con_password">Confirm password:</label>
<input type="password" id="con_password" name="con_password" value="<?php echo set_value('con_password'); ?>" />
</p>
<p>
<label for="user_rname">Real name:</label>
<input type="text" id="user_rname" name="user_rname" value="<?php echo set_value('user_rname'); ?>" />
</p>
<p>
<label for="user_rsname">Surname:</label>
<input type="text" id="user_rsname" name="user_rsname" value="<?php echo set_value('user_rsname'); ?>" />
</p>
<p>
<?php
echo form_label('Location:', 'location');
$options = array(
'small' => 'Small Shirt',
'med' => 'Medium Shirt',
'large' => 'Large Shirt',
);
echo form_dropdown('location', $options, 'large'); ?>
</p>
<p>
<?php
echo form_label('Sex:', 'sex');
echo form_radio('sex', 'm');
echo form_radio('sex', 'ΕΎ');
echo form_radio('sex', 'neopredeljen', TRUE);
?>
</p>
<p>
<input type="submit" class="greenButton" value="Submit" />
</p>
<?php echo form_close(); ?>
My add user in model:
Code: public function add_user()
{
$data=array(
'username'=>$this->input->post('user_name'),
'email'=>$this->input->post('email_address'),
'password'=>md5($this->input->post('password')),
'realname'=>$this->input->post('user_rname'),
'surname'=>$this->input->post('user_rsname'),
// how can I add location(dropdown) and sex(radio button) to my database
);
$this->db->insert('user',$data);
}
My questions:
1. How can I add location and sex to my database?
2. How can I have whole radio button selection in one line? (now we have 3 radio buttons in 3 lines)
3. How can I add textarea into my form?
I know these are some basic and for most of you a piece of cake. I'd be very gratefully for all answers :$
Help form some basics - El Forum - 03-28-2012
[eluser]Ivar89[/eluser]
Form Helper User Guide
Help form some basics - El Forum - 03-28-2012
[eluser]CodeIgniteMe[/eluser]
After you have read the User Guide, you can also check your $_POST array or the array returned by $this->input->post() to see where and what to access for the data you need.
|