Welcome Guest, Not a member yet? Register   Sign In
from validation + email [solved]
#1

[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 />
&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.
#2

[eluser]wawer[/eluser]
Can anybody help me?
#3

[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-gui...l#tutorial
#4

[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>
#5

[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:
&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.




Theme © iAndrew 2016 - Forum software by © MyBB