AMP form submitting with post

后端 未结 2 1037
别跟我提以往
别跟我提以往 2021-01-02 23:38

I\'ve a website for years with a few forms to login etc. Recently I made it all Google\'s AMP proof, but the forms stopped working. I\'m searching for days now, but I can\'t

2条回答
  •  一生所求
    2021-01-03 00:42

    To put it simply: you can't just echo the input.

    From the docs:

    Use the action-xhr attribute to submit the form via XMLHttpRequest (XHR). You can use amp-mustache templates to show custom success or error messages, using data sent by the server endpoint as JSON. For example, if the server sends {"foo": "bar"}, you can use use {{foo}} in the template to render bar.

    So since you are using the action-xhr, you should be returning a JSON, and update the form template accordingly.

    Check out this.

    Full example, from your code:

     $name
        ];
    header("Content-type: application/json");
    header("Access-Control-Allow-Credentials: true");
    header("Access-Control-Allow-Origin: *.ampproject.org");
    header("AMP-Access-Control-Allow-Source-Origin: https://www.domain.com");
    header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
    
    echo json_encode($output);
    die();
    
    }
    ?>
    
    
    
        
        
        
        
        
        
        
        AMP form
    
    
    
    
    Name:

提交回复
热议问题