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
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();
}
}?>