php - How to make sure a string contains more then automatically inputed defaults? -
i have input form create customfield name, when page loads textbox automatically filled "cst_".
i preset value in class:
class customfield{ // define properties public $id = 0; public $groupid; public $name = 'cst_'; public $displayname; public $type; public $defaultvalue; public $required; public $ordercount; ... when go save fields on page, check make sure user has imputed more values leaving "cst_"
i simply:
// check "cst_" if(strlen($customfield->name > 4)){ // save $customfield->save(); }else{ noticeset(1,'please add name');noticeset(1,strlen($customfield->name));} in textbox added cst_water hardness error
please add name
18
i don't understand how failing @ if statement
i've added noticeset before if statement , shows 18.
is there better way see if user has added more "cst_"?
you have parentheses out of place end ($customfield->name > 4) results in false. expression ends if(strlen(false)) no good. fix with:
if(strlen($customfield->name) > 4){ if cst_ must present, maybe:
if(strpos($customfield->name, 'cst_') === 0 && strlen($customfield->name) > 4){ or shorter slower:
if(preg_match('/cst_.+/', $customfield->name)) {
Comments
Post a Comment