Welcome Guest, Not a member yet? Register   Sign In
$this->load->view('home_view', $data); and href=#
#1

[eluser]tintamarre[/eluser]
Hello,

I am trying to load a view file which I do correctly in my controler using :

$this->load->view('home_view', $data);


but then I would like the browser to go to the anchor #contact on the form home_view.php meaning to index.php/home/#contact

I have read all the documentation on the view file and so on, but I can't figure it out!

The only thing I can get is :
An Error Was Encountered
Unable to load the requested file: /home/#contact.php


This make sense because I want index.php/home/#contact

I have tried several options, but I have not had any sucess yet and I can't find any subject on this on the forum.

Thanks for your help!

Tintamarre.
#2

[eluser]tintamarre[/eluser]
Hello,

I am open to read some part of the documentation to find out the issue - but where to look ? I have read all the documentation on codeigniter.com.

I hope the only thing to do is not to change the view() function...

Thanks,

Tintamarre.
#3

[eluser]xerobytez[/eluser]
You would have to do a redirect to that URL. So something like this should work.

Code:
redirect(site_url('home/#contact'));
#4

[eluser]tintamarre[/eluser]
Hello,

This is working, but we can't pass $_POST data and the $data array as a paramenter. So I can't retrieve my data.

Is there a solution to push some data with redirect ?

Thanks,

T.
#5

[eluser]tintamarre[/eluser]
Hello,

just to give more information on this :

Here is my function that send the email. In case of errors, I would like the screen to go to /home/#contact as the contact form is far below in my web page. I would like to avoid the user to scroll down to the form.

So instead of

Code:
$this->load->view('header_view',$data);
$this->load->view('home_view', $data);

If would need to sth like this (but this one below is not working :-()

Code:
$this->load->view('header_view',$data);
$this->load->view('home_view#contact', $data);

if I do this :

Code:
redirect('home#contact','refresh');

The page goes correctly to the form, I do not have the error message of my form.

I am in need of this for two web sites... I have included the whole code below.

Any help would be greatly appreaciated!

Thanks,

T.

This is in the controler :

Code:
Function mail(){
    
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('nom', 'nom', 'trim|required|alpha_numeric|xss_clean');
        $this->form_validation->set_rules('prenom', 'prenom', 'trim|required|alpha_numeric|xss_clean');
        $this->form_validation->set_rules('email', 'email', 'trim|required|valid_email');
        $this->form_validation->set_rules('texte', 'texte', 'trim|required|xss_clean');
        
        $this->form_validation->set_message('required', 'Le champ %s est obligatoire');
        $this->form_validation->set_message('alpha_numeric', 'Le champ %s doit ĂȘtre alphanumerique');
        $this->form_validation->set_message('valid_email', "L'%s doit ĂȘtre un email valide");
        
        $this->form_validation->set_error_delimiters('<li>', '</li>');

        if ($this->form_validation->run() == TRUE){
            
            //$this->email->clear();
            $this->email->from($email,$nom." ".$prenom );
            $this->email->to('[email protected]');
            $this->email->reply_to($email,$nom." ".$prenom);
            $this->email->cc($email);
            $this->email->subject('atravers.fr - contact');
            $this->email->message($texte);
            $this->email->send();
            
            $data['formsucess'] = 'Merci pour votre message';
        
            // redirect to home page    
            $this->load->view('header_view',$data);
            $this->load->view('home_view', $data);
        }
        else
        {
            
            $this->load->view('header_view');
            $this->load->view('home_view');
            
        }
        
    }

this is in the view file :


Code:
<div id="contact">
<div id="formulaire">
&lt;!--- FORMULAIRE --&gt;
                     <p><ul>&lt;?php echo validation_errors(); ?&gt;</ul></p>
                    &lt;?php echo form_open('home/mail'); ?&gt;
                        <p>Nom</p>
                        &lt;input name='nom' type='text' size='40' value="&lt;?php echo set_value('nom'); ?&gt;"/&gt;
                        <p>Prenom</p>
                        &lt;input name='prenom' type='text' size='40' value="&lt;?php echo set_value('prenom'); ?&gt;"/&gt;&lt;br/>
                        <p>Email</p>
                        &lt;input name='email' type='text' size='40' value="&lt;?php echo set_value('email'); ?&gt;"/&gt;&lt;br/>
                        <p>Message</p>
                        &lt;textarea class="textareasize" name='texte' cols="" rows=""&gt;&lt;?php echo set_value('texte'); ?&gt;&lt;/textarea&gt;&lt;br/><br/>
                        &lt;input name='soumettre' type='submit' value='Envoyer'/&gt;&lt;br/>
                    &lt;/form&gt;
</div>
</div>
#6

[eluser]tintamarre[/eluser]
Hello,

According to other sources, this should be done using javascript as view() does not support anchors.

http://flesler.blogspot.com/2007/10/jqueryscrollto.html

Thanks,




Theme © iAndrew 2016 - Forum software by © MyBB