如何确保字符串包含更多自动输入的默认值?

I have an input form to create a customField name, when the page loads the textbox is automatically filled with "cst_".

I preset this value in my class:

class customField{

    // DEFINE PROPERTIES
    public $id = 0;
    public $groupId;
    public $name = 'cst_';
    public $displayName;
    public $type;
    public $defaultValue;
    public $required;
    public $orderCount;
    ...

When I go to save the fields on my page, I check to make sure that the user has imputed more values than just leaving the "cst_"

I do this by simply:

// CHECK FOR ONLY "cst_"
if(strlen($customField->name > 4)){

    // SAVE
    $customField->save();

}else{ noticeSet(1,'PLEASE ADD NAME');noticeSet(1,strlen($customField->name));}

in my textbox I added cst_water hardness however I get the error

PLEASE ADD NAME

18

I don't understand how it is failing at that if statement

I've added a noticeSet before the if statement and it shows 18.

Is there any better way to see if a user has added more than just "cst_"?

You have a parentheses out of place so you end up with ($customField->name > 4) which results in false. So the expression ends up if(strlen(false)) which is obviously no good. Fix it with:

if(strlen($customField->name) > 4){

If cst_ must be present, then maybe:

if(strpos($customField->name, 'cst_') === 0 && strlen($customField->name) > 4){

Or shorter but probably slower:

if(preg_match('/cst_.+/', $customField->name)) {

Does your $customField->name contain the name? Is that checked? If so, i can see a problem in your code. You use:

if(strlen($customField->name > 4)){ ...

It should be:

if(strlen($customField->name) > 4){ ...

Anyway, this just will check that the name length is greater than 4. It won't check if it is "cst_".

Instead, you should be doing something like:

if (isset($customField->name) && $customField->name != "cst_") {
  //Your code
}

The statement should read

if(strlen($customField->name) > 4){ 

(note the moved bracket)

Ideally, though, you want

if ($customField->name != "cst_") {