[eluser]Unknown[/eluser]
Here's the problem. I have loaded in the head section Jquery 1.2.6.min and also a dynamic dropdown js file.I didn't want to mix controllers with client side so that s the reason I have put them into the view.So, I have attached the view file.
My head section is looking like this:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration Form</title>
<link href="<? echo base_url('css/form.css')?>" rel="stylesheet" />
<scrip+ src="<? echo base_url('js/jquery-1.2.6.min.js');?>"> </scrip+>
<scrip+ src="<? echo base_url('js/drop_down_old.js');?>"> </scrip+>
</head>
My .htaccess;
Code:
<IfModule mod_rewrite.so>
Options +FollowSymLinks
RewriteEngine On
# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/
RewriteBase /codeign
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|jquery\.js|robots\.txt)
# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
My controller:
Code:
<?php
class form extends CI_Controller {
function __construct() {
parent::__construct();
$this->view_data['base_url'] = base_url();
$this->load->model ('user_model') ;
}
function index()
{
$this->register();
}
function register()
{
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('array_helper');
$this->load->library('Form_validation');
$this->load->database();
$this->form_validation->set_rules ('username', 'Username', 'trim|required|alpha_numeric|min_lenght[6]|max_lenght[15]|strolower|is_unique[clform.username]|xss_clean');
$this->form_validation->set_rules ('password', 'Password', 'trim|required|alpha_numeric|min_lenght[6]|max_lenght[20]|matches[passconf]|xss_clean');
$this->form_validation->set_rules ('passconf', 'Password Confirmation', 'trim|required|alpha_numeric|min_lenght[6]|max_lenght[20]|xss_clean');
$this->form_validation->set_rules ('email', 'Email Adress', 'trim|required|valid_email|min_lenght[6]|max_lenght[30]|xss_clean');
$this->form_validation->set_rules ('title', 'Title', 'trim|required|check_default|xss_clean');
$this->form_validation->set_rules ('lname', 'Last Name', 'trim|required|alpha|min_lenght[2]|max_lenght[30]|xss_clean');
$this->form_validation->set_rules ('fname', 'First Name', 'trim|alpha|min_lenght[2]|max_lenght[30]|xss_clean');
$this->form_validation->set_rules ('phone', 'Phone', 'trim|is_natural|min_lenght[6]|max_lenght[20]|regex_match[/^\\+[0-9]{1,3}\\.[0-9]{4,14}(?:x.+)?$/]|xss_clean');
$this->form_validation->set_rules ('mphone', 'Mobile Phone', 'trim|is_natural|min_lenght[6]|max_lenght[20]|regex_match[/^\\+[0-9]{1,3}\\.[0-9]{4,14}(?:x.+)?$/]|xss_clean');
$this->form_validation->set_rules ('state', 'Province', 'trim|required|check_default|xss_clean');
$this->form_validation->set_rules ('county', 'Municipality', 'trim|required|check_default|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('view_register', $this->view_data);
}
else
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$passconf = $this->input->post('passconf');
$email = $this->input->post('email');
$title = $this->input->post('title');
$lname = $this->input->post('lname');
$fname = $this->input->post('fname');
$phone = $this->input->post('phone');
$mphone = $this->input->post('mphone');
$state = $this->input->post('state');
$county = $this->input->post('county');
$this->user_model->register_user($username, $password, $passconf, $email, $title, $lname, $fname, $phone, $mphone, $state, $county);
}
}
}
I also have a model and a library extension which I will not post because I don t think they are relevant to the situation.
The js dynamic dropdown file:
Code:
function drop_down_list(state)
{
if(state == 'AK' || state == 'DC') // Alaska and District Columbia have no counties
{
$('#county_drop_down').hide();
$('#no_county_drop_down').show();
}
else
{
$('#loading_county_drop_down').show(); // Show the Loading...
$('#county_drop_down').hide(); // Hide the drop down
$('#no_county_drop_down').hide(); // Hide the "no counties" message (if it's the case)
$.getScript("js/states/"+ state.toLowerCase() +".js", function(){
populate(document.form.county);
$('#loading_county_drop_down').hide(); // Hide the Loading...
$('#county_drop_down').show(); // Show the drop down
});
}
}
A state js file is looking like this:
Code:
function populate(form)
{
form.options.length = 0;
form.options[0] = new Option("Select a county of Alabama","000");
form.options[1] = new Option("Autauga County","Autauga County");
form.options[2] = new Option("Baldwin County","Baldwin County"); .....etc.
All the js files, including the states folder are put into a js folder under the codeigniter directory.
The problem is that I cannot trigger the dropdown function inside the view file with codeigniter, giving me Uncaught RefferenceError drop_down list is not defined, thus not being able to populate the second dropdown.
This is haunting me for a few weeks. Will very much appreciate your help.