Welcome Guest, Not a member yet? Register   Sign In
How to add hash tag and div id to end of url when loading a view
#1

[eluser]Unknown[/eluser]
Hi there,

I'm currently working on a one page website which has a fixed navigation which scrolls to different sections of the page depending on the anchor clicked.

If there are validation errors in the contact section when the contact form has been submitted I want the page to load and go to the section of the page which has the validation errors like so http://mysite.com/site/submit#contact.

The contact form works fine at the moment except for adding the # tag followed by the contact ID to the end of the URL. This is the current code I'm using at the moment:

class Site extends CI_Controller {
function index() {
$this->load->view('site_view');
}

function sendmail() {

//field name, error message, validation
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');

if ($this->form_validation->run() == FALSE) {
$this->load->view('site_view'); /*THIS IS WHERE I WANT TO ADD THE #CONTACT TO THE END OF THE URL*/
}

else {
//validation has passed. now send email
$name = $this->input->post('name');
$email = $this->input->post('email');

$this->email->from($email, $name);
$this->email->to('[email protected]', 'Mr Mail');
$this->email->subject('My subject');
$this->email->message('My message');

if ($this->email->send()) {
//echo "Your e-mail was sent!";
$this->load->view('site_view');
}
else {
$this->load->view('site_view');
show_error($this->email->print_debugger());
}
}
}
}

Does anyone have any ideas as I'm not sure how to overcome this issue?

Thanks,

Dan




Theme © iAndrew 2016 - Forum software by © MyBB