Amp html Can';t在AMP中提交表单时显示验证错误

Amp html Can';t在AMP中提交表单时显示验证错误,amp-html,Amp Html,我正在用amp表单进行后端数据输入验证,我想在前端显示错误。然而,当我提交表单时,即使表单包含错误(没有输入名称),前端也会说“成功”,而不是输出错误 PHP代码: action xhr=“scripts/contact_process.php” 验证xhr=“/scripts/contact_process.php” method=“post” target=“\u blank” class=“详细的联系方式” 自定义验证报告=“随用随用” > 安排约会 电子邮件 名称 电话 消息 我想为我

我正在用amp表单进行后端数据输入验证,我想在前端显示错误。然而,当我提交表单时,即使表单包含错误(没有输入名称),前端也会说“成功”,而不是输出错误

PHP代码:

action xhr=“scripts/contact_process.php”
验证xhr=“/scripts/contact_process.php”
method=“post”
target=“\u blank”
class=“详细的联系方式”
自定义验证报告=“随用随用”
>
安排约会
电子邮件
名称
电话
消息
我想为我的龙斯基皮安排一个约会,明天上午10点
{{{#验证错误}
{{message}}

{{/verifyErrors}} {{^verifyErrors}} 出了点问题。请稍后再试

{{/verifyErrors}} {{{#验证错误} {{message}}

{{/verifyErrors}} {{^verifyErrors}} 出了点问题。请稍后再试

{{/verifyErrors}} 成功! ```
我收到了一条成功消息,因为AMP跟踪HTTP头,每当我提交表单时,如果提交成功(即使由于错误我无法发送电子邮件),contact_process.php将返回一个HTTP头2xx,AMP会认为这是成功的

提交成功将在成功提交表单时输出,无论表单是否按照您的要求执行

每当后端返回4xxx的HTTP头时,将输出提交错误。在我的例子中,我必须添加以下代码行:

头文件(“HTTP/1.1400错误请求”)

echo json\u encode($error\u array)
下面,它成功了

无论何时要输出错误,请确保手动发送错误HTTP头4xx

   action-xhr="scripts/contact_process.php" 
   verify-xhr="/scripts/contact_process.php"
   method="post" 
   target="_blank" 
   class="detailed_contact_form "
   custom-validation-reporting="as-you-go"
   >
      <fieldset class="user-valid valid">
         <legend>
            <span> Schedule an appointment</span>
         </legend>
         <div class="form-body">
            <div class="form-group">   
             <div class="form-group"> 
                  <div class="form-group"> 
               <label for="email">Email  </label> 
               <input type="text" required name="email" id="email"  value="exampleexample.com"class="form-input string-entry">
            </div>
               <label for="name">Name  </label> 
               <input type="text" required  name="name" id="name" value="Cindy"  class="form-input string-entry">
            </div>
            <div class="form-group">  
               <label for="phone">Phone </label>  
               <input type="tel" required name="phone" id="phone" value="123-345-6789" class="form-input string-entry">
            </div>
               <div class="form-group">  
               <label for="phone">Message </label>  
               <textarea name="message" required class="textarea" >I want to schedule an appointment for my dragon Skippy, for tomorrow 10AM</textarea>
            </div>
            <div class="form-group button-holder">
               <input type="submit" class="button" value="Send appointment!">
            </div>
         </div>
            <div verify-error>
        <template type="amp-mustache">
            {{#verifyErrors}}
                <p>{{message}}</p>
            {{/verifyErrors}}
            {{^verifyErrors}}
                <p>Something went wrong. Try again later?</p>
            {{/verifyErrors}}
        </template>
    </div>
    <div submit-error>
        <template type="amp-mustache">
            {{#verifyErrors}}
                <p>{{message}}</p>
            {{/verifyErrors}}
            {{^verifyErrors}}
                <p>Something went wrong. Try again later?</p>
            {{/verifyErrors}}
        </template>
    </div>

    <div submit-success>
    <template type="amp-mustache">
      Success! 
    </template>
  </div>

      </fieldset>

   </form> ```