I have an options panel in my WordPress theme with several text fields e.g. project title, project description, etc.
case 'text':
$val = $value['std'];
$std = get_option($value['id']);
if ( $std != "") { $val = $std; }
$output .= '<input class="" maxlength="12" name=""'. $value['id'] .'" id="'. $value['id'] .'" type="'. $value['type'] .'" value="'. $val .'" />';
break;
As the above code shows… I currently have my max length for the text fields as 12, but I would like to have a max length to be different for each of the text fields. How can I do this?
Define an array containing the fields and their corresponding maxlength values.
(I’ve used field names, but you could also use an Id number)
E.g: field_name => max_length_for_that_field
Identify which text field (input) you are currently building and use that identifier to reference your maxFieldLengths array.
Note: From your code sample it’s not 100% clear how you identify the field you are currently building. You could, for example, use something like: