Closed (fixed)
Project:
Location
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
10 Feb 2012 at 03:06 UTC
Updated:
4 May 2012 at 21:20 UTC
I created a form to do some custom validation on the Postal_Code field that Location provides. The code is as follows
<?php
function location_extra_node_validate($node, $form, &$form_state) {
//dsm($form);
//print "<pre>";
//print_r($form['field_item_location']['und'][0]['postal_code']);
//print_r($form_state['values']['field_item_location']['und'][0]['postal_code']);
//print "</pre>";
// create a variable that is a little easier to work with
$zip = $form_state['values']['field_item_location']['und'][0]['postal_code'];
// let's check to see if the value is a 5 digit US zipcode
if($match = preg_match("#[0-9]{5}#", $zip)) {
// check to see if the zipcode is actually in the database
$result = db_query('SELECT zip FROM zipcodes WHERE zip = :zip', array(':zip' => $zip));
//count to see if result is 0, indicating an invalid zipcode
$number_of_rows = $result->rowCount();
//if $number_of_rows is 0, throw form_set_error()
if($number_of_rows == 0) {
form_set_error('postal_code', 'Your zip code was not found. Please make sure you entered a valid 5 digit zip US code.');
}
} else {
form_set_error('postal_code', 'This is not a valid zip code. Please enter a 5 digit US zip code.');
}
}
?>
The function works, but when the error is thrown by form_set_error, the postal_code form field is not highlighted. I am sure it's because I have the wrong argument 'postal_code.' Can someone tell me what the correct title is so that highlighting works correctly on an error?
Thanks
Comments
Comment #1
samhassell commentedI'm struggling with the same issue in 6.x using location cck... it should be something like
i think..
Comment #2
ankur commented@Gastonia,
samhassel, is right. In your case, it should be
Feel free to re-open this ticket if that doesn't fix it for you.