from validation + email [solved] - El Forum - 09-14-2009
[eluser]wawer[/eluser]
Sorry for my English. I have problem with form validation. Before I made some changes(use CI form helper) everything works fine. I try to back to previous versions but sill the same problem. When I press send button page reloaded but no error show. This is controller:
Code: function kontact() {
$this->load->library('form_validation', 'email');
$this->load->helper('email');
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('email', 'Email', 'valid_email');
$this->form_validation->set_rules('text', 'Text', 'required');
$data['page_title'] = 'Kontakt';
$data['page'] = 'kontact';
if ($this->form_validation->run() == FALSE){
$this->load->view('index',$data);
}
else{
$this->email->from($this->input->post('email'));
$this->email->to('my@email');
$this->email->reply_to($this->input->post('email'));
$this->email->subject($this->input->post('title'));
$this->email->message($this->input->post('text'));
if (valid_email($this->email->from($this->input->post('email')))){
$this->email->send();
$data['page'] = 'succes';
$data['info'] = 'Wysłano prawidłowo.';
$this->load->view('index',$data);
}
else{
echo 'email is not valid';
}
}
}
end the view:
Code: <?=form_open('main/kontact', array('id' => 'kontact'));?>
<strong for="kontact-1">Tytuł emaila</strong><br />
<?=form_input(array('name'=>'title','size'=> '20','validation'=>'required')); ?><br />
<strong for="kontact-2">Twój email</strong><br />
<?=form_input(array('name'=>'email','size'=> '20','validation'=>'email')); ?><br />
<strong for="kontact-3">Wiadomość</strong><br />
<?=form_textarea(array('name'=>'text','rows'=>'10','cols'=>'50','validation'=>'required')); ?><br />
<p><?=form_submit('submit', 'Wyślij!'); ?></p>
<?=form_close(); ?>
[removed]
$(function(){
$("#kontact").validation();
});
[removed]
There is also java form validation(jQuery) I switch it off but no result.
from validation + email [solved] - El Forum - 09-15-2009
[eluser]wawer[/eluser]
Can anybody help me?
from validation + email [solved] - El Forum - 09-15-2009
[eluser]pistolPete[/eluser]
[quote author="wawer" date="1252934376"]... When I press send button page reloaded but no error show. ...[/quote]
You need to display the errors in your view using e.g. this function:
Code: <?php echo validation_errors(); ?>
Have a look at the Form Validation Tutorial: http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#tutorial
from validation + email [solved] - El Forum - 09-15-2009
[eluser]wawer[/eluser]
I check up my view and there is error displaying. I read several times that tutorial before I post there.
My view:
Code: <div class='title'><?=$page_title; ?></div>
<div id='border'>
<div id='kontact_main'>
<?=form_open('main/kontact', array('id' => 'kontact'));?>
<?=validation_errors(); ?>
<strong for="kontact-1">Tytuł emaila</strong><br />
<?=form_input(array('name'=>'title','size'=> '20','validation'=>'required')); ?><br />
<strong for="kontact-2">Twój email</strong><br />
<?=form_input(array('name'=>'email','size'=> '20','validation'=>'email')); ?><br />
<strong for="kontact-3">Wiadomość</strong><br />
<?=form_textarea(array('name'=>'text','rows'=>'10','cols'=>'50','validation'=>'required')); ?><br />
<p><input type="submit" value="Wyślij!" /></p>
<?=form_close(); ?>
[removed]
$(function(){
$("#kontact").validation();
});
[removed]
</div>
</div>
from validation + email [solved] - El Forum - 09-17-2009
[eluser]wawer[/eluser]
I solve the problem. I make second controller function called send and now works fine. Now controller:
Code: function kontact(){// loadning view with contact form
$data['page_title'] = 'Kontakt';
$data['page'] = 'kontact';
$this->load->view('index',$data);
}
function send() {// sending mail
$this->load->library(array('form_validation', 'email'));
$this->load->helper('email');
$this->form_validation->set_rules('title', 'Title', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required');
$this->form_validation->set_rules('content', 'Content', 'required');
$data['page_title'] = 'Kontakt';
$data['page'] = 'kontact';
if ($this->form_validation->run() == FALSE){
$this->load->view('index',$data);
}
else{
$this->email->from($this->input->post('email'));
$this->email->to('my@maill');
$this->email->reply_to($this->input->post('email'));
$this->email->subject($this->input->post('title'));
$this->email->message($this->input->post('content'));
$this->email->send();
$data['page'] = 'succes';
$data['info'] = 'Wysłano prawidłowo.';
$this->load->view('index',$data);
}
}
The view:
Code: <?=form_open('main/send', array('id' => 'kontact')); ?>
<?=validation_errors(); ?>
<strong for="kontact-1">Tytuł emaila</strong><br />
<?=form_input(array('name'=>'title','size'=> '20','validation'=>'required')); ?><br />
<strong for="kontact-2">Twój email</strong><br />
<?=form_input(array('name'=>'email','size'=> '20','validation'=>'email')); ?><br />
<strong for="kontact-3">Wiadomość</strong><br />
<?=form_textarea(array('name'=>'content','rows'=>'10','cols'=>'50','validation'=>'required')); ?><br />
<p><input type="submit" value="Wyślij!" /></p>
<?=form_close(); ?>
Thanks for help.
|