[eluser]Unknown[/eluser]
Hi thanx 4 the reply,
i cant get wat u r trying to say,
my problem is ....
consider the situation
1. open form
2. insert a text box named "txtname"
3. insert a combo box named "country"
- India
- Australia
- UK
- Srilanka
4. insert a radio option for "gender"
- Male
- Female
5. insert a check box for "items"
- Mobile
- Laptop
6. insert a submit button
7. close form
After creating the above said form,
when i press submit button
it has to validate the POST data
if some datas are invalid
then it should show error, [ I M GETTING ERROR ]
after displaying the error, the old data which was entered in the text box is
displaying using the
set_value() function
but i m not getting the re populated value for
combo box, radio option and the check box.
just send me a code where the things are working properly....
Thanx 4 the reply...
---------------------------------
view File
myform.php
Code:
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php //echo validation_errors('<div style="color: #FF0000; background:#F3CBCE;">','</div>'); ?>
<?php echo form_open('../form'); ?>
<h5>Username</h5>
<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" /><?php echo form_error('username','<div style="color: #FF0000; background:#F3CBCE;">','</div>'); ?>
<h5>Password</h5>
<input type="text" name="password" value="<?php echo set_value('password'); ?>" size="50" /><?php echo form_error('password','<div style="color: #FF0000; background:#F3CBCE;">','</div>'); ?>
<h5>Password Confirm</h5>
<input type="text" name="passconf" value="<?php echo set_value('passconf'); ?>" size="50" /><?php echo form_error('passconf','<div style="color: #FF0000; background:#F3CBCE;">','</div>'); ?>
<h5>Email Address</h5>
<input type="text" name="email" value="<?php echo set_value('email'); ?>" size="50" /><?php echo form_error('email','<div style="color: #FF0000; background:#F3CBCE;">','</div>'); ?>
<select name="myselect">
<option value="one" <?php echo set_select('myselect', 'one', TRUE); ?> >One</option>
<option value="two" <?php echo set_select('myselect', 'two'); ?> >Two</option>
<option value="three" <?php echo set_select('myselect', 'three'); ?> >Three</option>
</select>
<input type="checkbox" name="mycheck[]" value="1" <?php echo set_checkbox('mycheck[]', '1'); ?> />Red
<input type="checkbox" name="mycheck[]" value="2" <?php echo set_checkbox('mycheck[]', '2'); ?> />Green
<input type="radio" name="myradio" value="1" <?php echo set_radio('myradio', '1', TRUE); ?> />Radio1
<input type="radio" name="myradio" value="2" <?php echo set_radio('myradio', '2'); ?> />Radio2
<div><input type="submit" value="Submit" /></div>
</form>
</body>
</html>
------------------------------------
Controller File
form.php
Code:
<?php
class Form extends Controller {
function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|max_length[12]|xss_clean|callback_username_check');
$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
function username_check($str)
{
if ($str == 'test')
{
$this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
return FALSE;
}
else
{
return TRUE;
}
}
}
?>