jodancer Posted January 14, 2013 Share Posted January 14, 2013 I have a text field which I am trying to hide the name, suffix and prefex when the field value is empty. Been trying for I just cannot make it work. (pretty useless I know!) Could anyone take a look and point me in the right direction? many thanks Quote Link to comment https://forums.phpfreaks.com/topic/273158-trying-to-hide-field-title-and-suffix-when-empty/ Share on other sites More sharing options...
stijn0713 Posted January 14, 2013 Share Posted January 14, 2013 I don't understand what you are trying to do: do you mean you have something like : <td> aNameForTextfield </td> <td> <input type="text" name='aTF' value=''/> and you want to hide aNameForTextfield as long as their is no entered value? Quote Link to comment https://forums.phpfreaks.com/topic/273158-trying-to-hide-field-title-and-suffix-when-empty/#findComment-1405680 Share on other sites More sharing options...
jodancer Posted January 14, 2013 Author Share Posted January 14, 2013 Hi, Thanks for the reply. I have a number of fields and these have a title a possible suffix or prefix Example Number of Bedrooms: 4 Double In this case the Number of Bedrooms is the Title of the field 4 is the input value Double is the prefix If the field is not filled in (in this case 4) then I would like Number of bedrooms and Double hidden Quote Link to comment https://forums.phpfreaks.com/topic/273158-trying-to-hide-field-title-and-suffix-when-empty/#findComment-1405715 Share on other sites More sharing options...
Jessica Posted January 14, 2013 Share Posted January 14, 2013 Without code we can't do much to help you Quote Link to comment https://forums.phpfreaks.com/topic/273158-trying-to-hide-field-title-and-suffix-when-empty/#findComment-1405716 Share on other sites More sharing options...
jodancer Posted January 15, 2013 Author Share Posted January 15, 2013 Sorry, I did attach a file but it sems to have disappeared! <?php defined( 'cliff' ) or die( 'Restricted access' );?> <?php class GExtrafieldTextText extends GElement{ public function renderInput($name, $value, &$node, $control_name) { $parameters = & JRegistry::getInstance ($node); $parameters->loadJSON($node); $required = $parameters->get( 'required', 0 ) ; //$size = ($parameters->get('field_size') ? 'size="'.$parameters->get('field_size').'"' : ''); $default_value = $parameters->get( 'default_value', '' ) ; $prefix = $parameters->get( 'prefix_text', '' ) ; $suffix = $parameters->get( 'suffix_text', '' ) ; $required = $required ? ' validate[required]' : ''; $class = 'class="lbinputbox'.$required.$parameters->get('field_class').'"'; // Required to avoid a cycle of encoding & $value = htmlspecialchars(htmlspecialchars_decode($value, ENT_QUOTES), ENT_QUOTES, 'UTF-8'); if($value=="") { $value = $default_value; } $input = ""; $input .= "<span class=\"input\">"; $input .= $prefix; $input .= "</span>"; $input .= '<input type="text" name="'.$control_name.'['.$name.']" id="'.$control_name.$name.'" value="'.$value.'" '.$class.' />'; $input .= "<span class=\"input\">"; $input .= $suffix; $input .= "</span>"; return $input; } function renderValue($data) { $registry = & JRegistry::getInstance ($data->params); $registry->loadJSON($data->params ); $prefix = $registry->get( 'prefix_text_view', '' ) ; $suffix = $registry->get( 'suffix_text_view', '' ) ; // Required to avoid a cycle of encoding & $value = htmlspecialchars(htmlspecialchars_decode($data->actual_value, ENT_QUOTES), ENT_QUOTES, 'UTF-8'); $output = ""; if($prefix!="") { $output .= "<span class=\"input\">"; $output .= $prefix; $output .= "</span>"; } $output .= $value; if($suffix!="") { $output .= "<span class=\"input\">"; $output .= $suffix; $output .= "</span>"; } return $output; } function renderSearchInput($name, $value, &$node, $control_name) { $parameters = & JRegistry::getInstance ($node); $parameters->loadJSON($node); //$size = ($parameters->get('field_size') ? 'size="'.$parameters->get('field_size').'"' : ''); $default_value = $parameters->get( 'default_value', '' ) ; $prefix = $parameters->get( 'prefix_text', '' ) ; $suffix = $parameters->get( 'suffix_text', '' ) ; $class = 'class="lbinputbox'.$parameters->get('field_class').'"'; // Required to avoid a cycle of encoding & $value = htmlspecialchars(htmlspecialchars_decode($value, ENT_QUOTES), ENT_QUOTES, 'UTF-8'); if($value=="") { $value = $default_value; } $input = ""; $input .= "<span class=\"input\">"; $input .= $prefix; $input .= "</span>"; $input .= '<input type="text" name="'.$control_name.'['.$name.']" id="'.$control_name.$name.'" value="'.$value.'" '.$class.' />'; $input .= "<span class=\"input\">"; $input .= $suffix; $input .= "</span>"; return $input; } function beforeStoreInput($extrafield,&$data, $files) { $err_msg = ""; if(!is_null($data)) { if(key_exists($extrafield->fieldcode, $data)) { $registry = & JRegistry::getInstance ($extrafield->id); $registry->loadJSON($extrafield->params ); $required = $registry->get( 'required', 0 ) ; if($required && empty($data[$extrafield->fieldcode])) { $err_msg = JText::_('TEXT_EXTRAFIELD_REQUIRED'); } else { if($data[$extrafield->fieldcode]!="") { $filter = GFilter::factory('string'); $data[$extrafield->fieldcode] = $filter->sanitize($data[$extrafield->fieldcode]); } } } } return $err_msg; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/273158-trying-to-hide-field-title-and-suffix-when-empty/#findComment-1405730 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.