How to test if a HTML body contains empty tags

后端 未结 2 1580
轮回少年
轮回少年 2021-01-28 02:25

I am using a text editor on certain form fields, TinyMCE. it works ok.

However the TinyMCE editor returns a HTML body tag for each field in the form. T

相关标签:
2条回答
  • 2021-01-28 03:05

    its not a very ellegant solution but it works. i simply remove the tags from the document using the strip_tag(), then test if the variable is empty. If its not empty i submit the post variable.

    if (isset($_POST['description']))
                    {
                        $preValidated = dsf_db_prepare_input($_POST['description']);
                        $testValue  = trim(strip_tags($preValidated));
    
                        if(!strlen($testValue) >= 1)
                        {
                            $description ='';
                         }
                         else
                         {
                            $description ="$preValidated";
                         }     
                    }
    
    0 讨论(0)
  • 2021-01-28 03:18

    you can do it on the client side using jquery

    if($('<html><body></body></html>').find('body').children().length < 1) {
      console.log('empty')
    } else {
      console.log('not empty');
    }
    

    you can validate and send appropriate response to the server

    0 讨论(0)
提交回复
热议问题