Search code examples
phpjoomla

How to set header HTTP code in PHP without page terminate?


Can you please suggest me, how can I set 412 http code in header while coming invalid request from user form with out page termination or break.

Below code I am using in validation function

      if(bad request){
                header('HTTP/1.1 412 Precondition Failed', true, 412);
        }

Note : only header should set the http code and page will return to user form and with error emssage

Validation function

        function validateContactData($postData){
            $db       = &JFactory::getDBO();
            $errorMsg = array();
           $builder_name    = $this->emptyReplace($postData['builder_name']);

          if($builder_name == '' ){
              header('HTTP/1.1 412 Precondition Failed', true, 412);
            $errorMsg['builderNmError'] = "Please Select builder Program. "; 
           }
          return $errorMsg;

     }

Solution

  • I have found the solution which I used below function for set the header response without stuck the page .

                         http_response_code(412);