AMP Form submission redirect or response

前端 未结 3 1219
情话喂你
情话喂你 2020-12-15 01:39

Good morning, I have a form on a test AMP page (is AMP validate) and the form works: I receive the email with result (I use a php to handle it). I don\'t know (I did some tr

3条回答
  •  孤街浪徒
    2020-12-15 02:04

    You can redirect user after successful submission, however it can only be done if you are submitting values to a secure URL (like https://www.example.com).

    HTML With AMP-Form

    
    
      
        
        
        Hello, AMPs
        
        
        
        
        
      
      
        

    Hello World!

    SUBMISSION REQUEST HANDLER CODE IN PHP

    MUST BE 'https://';*/
        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: ".$domain_url);
    
    
        /*/ For Sending Error Use this code /*/
        if(!mail("email@example.com" , "Test submission" , "email: $name 
    name: $name" , "From: $name\n ")){ header("HTTP/1.0 412 Precondition Failed", true, 412); echo json_encode(array('errmsg'=>'There is some error while sending email!')); die(); } else { /*/--Assuming all validations are good here--*/ if( empty($redirect_url)) { header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin"); } else { header("AMP-Redirect-To: ".$redirect_url); header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); } echo json_encode(array('successmsg'=>$_POST['name'].'My success message. [It will be displayed shortly(!) if with redirect]')); die(); } }?>

提交回复
热议问题