CodeIgniter Forums
from validation + email [solved] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: from validation + email [solved] (/thread-22563.html)



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('[email protected]');
            $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 />
&lt;?=form_input(array('name'=>'title','size'=> '20','validation'=>'required')); ?&gt;<br />

<strong for="kontact-2">Twój email</strong><br />
&lt;?=form_input(array('name'=>'email','size'=> '20','validation'=>'email')); ?&gt;<br />

<strong for="kontact-3">Wiadomość</strong><br />
&lt;?=form_textarea(array('name'=>'text','rows'=>'10','cols'=>'50','validation'=>'required')); ?&gt;<br />

<p>&lt;?=form_submit('submit', 'Wyślij!'); ?&gt;</p>
&lt;?=form_close(); ?&gt;
[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:
&lt;?php echo validation_errors(); ?&gt;

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'>&lt;?=$page_title; ?&gt;</div>
<div id='border'>
<div id='kontact_main'>
&lt;?=form_open('main/kontact', array('id' => 'kontact'));?&gt;
&lt;?=validation_errors(); ?&gt;
<strong for="kontact-1">Tytuł emaila</strong><br />
&lt;?=form_input(array('name'=>'title','size'=> '20','validation'=>'required')); ?&gt;<br />
<strong for="kontact-2">Twój email</strong><br />
&lt;?=form_input(array('name'=>'email','size'=> '20','validation'=>'email')); ?&gt;<br />
<strong for="kontact-3">Wiadomość</strong><br />
&lt;?=form_textarea(array('name'=>'text','rows'=>'10','cols'=>'50','validation'=>'required')); ?&gt;<br />
<p>&lt;input type="submit" value="Wyślij!"  /&gt;&lt;/p>
&lt;?=form_close(); ?&gt;
[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('[email protected]');
            $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:
&lt;?=form_open('main/send', array('id' => 'kontact')); ?&gt;
&lt;?=validation_errors(); ?&gt;
<strong for="kontact-1">Tytuł emaila</strong><br />
&lt;?=form_input(array('name'=>'title','size'=> '20','validation'=>'required')); ?&gt;<br />
<strong for="kontact-2">Twój email</strong><br />
&lt;?=form_input(array('name'=>'email','size'=> '20','validation'=>'email')); ?&gt;<br />
<strong for="kontact-3">Wiadomość</strong><br />
&lt;?=form_textarea(array('name'=>'content','rows'=>'10','cols'=>'50','validation'=>'required')); ?&gt;<br />
<p>&lt;input type="submit" value="Wyślij!"  /&gt;&lt;/p>
&lt;?=form_close(); ?&gt;

Thanks for help.