[eluser]taewoo[/eluser]
Hey all.
I have a form with 3 inputs
- name
- city
- state
I form one of those blog URLs based on the three (i.e.. http;//blah.com/John-Smith/Los-Angeles/CA), and I save the query string (i.e.. "John-Smith/Los-Angeles/CA")as a row in a DB table. Of course, I need this to be unique...
How do I validate this? The tricky issue here is that there is no "URL" field in the form to validate on, not to mention is auto-generated.
So far this is what I have:
Code:
$rules['club_id'] = "trim|required|xss_clean";
$rules['name'] = "trim|required|xss_clean";
$rules['description'] = "trim|required|xss_clean";
$rules['city'] = "trim|required|xss_clean";
$rules['state'] = "trim|required|xss_clean|exact_length[2]";
$this->validation->set_rules($rules);
$fields['club_id'] = '<><><><> DB ERROR <><><><>';
$fields['name'] = '<b>Name</b>';
$fields['description'] = '<b>Description</b>';
$fields['city'] = '<b>City</b>';
$fields['state'] = '<b>State</b>';
$this->validation->set_fields($fields);
$club_id = $this->input->post("club_id");
$city = $this->input->post("city", true);
$state = $this->input->post("state", true);
$name = $this->input->post("name", true);
$url = $state ."/".url_title( $city )."/".url_title($name);
$club_names = $this->club_model->getByClubUrl( $url );
if(count($club_names) > 0)
{
$this->validation->set_message('url', 'Name is taken');
}
if ($this->validation->run() == FALSE)
{
return ( !$club_id || $club_id == "X") ? $this->add() : $this->edit($club_id);
}
Yeap, this doesn't work.