AMP forms incompatible with IE 11
What's the issue?
Form submission is failing on IE11 with the following error: Response must contain the AMP-Access-Control-Allow-Source-Origin header Form submission failed: Error: Response must contain the AMP-Access-Control-Allow-Source-Origin header
The forms used to work before with same code without any errors. All forms are not working now and getting the same error.
All of sudden I am getting following errors.
- Response must contain the AMP-Access-Control-Allow-Source-Origin header
- Form submission failed: Error: Response must contain the AMP-Access-Control-Allow-Source-Origin header
AMP-Access-Control-Allow-Source-Origin header code already present in my code
// Validate origin
$site_url = get_site_url();
$site_url_https = set_url_scheme($request_origin, 'https');
$site_url_https_no_path = stripUrlPath(set_url_scheme($site_url, 'https'));
$request_origin = $_SERVER['HTTP_ORIGIN'];
$request_origin_https = set_url_scheme($request_origin, 'https');
if( $site_url_https_no_path !== $request_origin_https){
return;
}
// Set redirection headers
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Origin: ['. $request_origin . ', https://websitetest-localhost.cdn.ampproject.org, https://websitetest.localhost.amp.cloudflare.com, https://cdn.ampproject.org]');
**header('AMP-Access-Control-Allow-Source-Origin: ' . $request_origin);**
header('Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin');
What browsers are affected?
IE11
Which AMP version is affected?
v0 (Version 1904301721170)
cc @cvializ 😄
Hi @PilarDCV thanks for reporting what you're experiencing. I checked some other documents that use amp-form in IE11 and it looks like it's working as far as I can tell. Let me know if you find that the amp-form demos aren't working in the IE11 browser.
Can you share a link to a document where this is occurring? If not, can you share a screenshot of the dev tools network panel, showing the headers that are part of the failing request? Has anything changed recently on the backend that could cause the request to be processed differently?
Hi @cvializ thanks for replying. No changes were made recently in the backend. The forms used to work before with same code without any errors. All forms are not working now and getting the same error. I share screenshot of the console.

Thanks for that screenshot, but the Network tab (Red tab in your screenshot) would be more helpful, with the request headers shown in the side panel.

When clicking on the "submit" button, the form isn't sent and it doesn't redirect me to the error url.
This is the screenshot of the tab network.

Thank you, that helps. It looks like the response is missing the AMP-Access-Control-Allow-Source-Origin header, so I believe the backend response code might have changed. The form is sent, but AMP is not accepting the response to render the result because the response is missing the required headers. The form does not redirect to an error URL because AMP forms use AJAX and no redirect is required.
But the form works correctly in the other browsers. Ex: Chrome

On the server side there is nothing that changes according to the browser with which they access
Can you share some markup from the form to help me reproduce?
Unfortunately I can't share the link : ( The information I can add is that the website is a wordpress with a theme developed in AMP (It doesn't use AMP plugin) and that the forms worked perfectly until very recently and from one moment to another they stopped working only in IE11.
I'm sorry to hear that but without more information like anonymized HTML used to make the form I can't effectively reproduce the problem.
Hi, Is there any way to test an earlier version of the v0.js file?
You can use the RTV URLs with the release numbers from https://github.com/ampproject/amphtml/releases and use the RTV URL (https://cdn.ampproject.org/rtv/01<RELEASE_NUMBER>/v0.js) as the script URL in your test document.
e.g.
https://cdn.ampproject.org/rtv/011905021827420/v0.jshttps://cdn.ampproject.org/rtv/011905021827420/v0/amp-form-0.1.js
This will make your document invalid AMP though and can only be used for testing
Hi @cvializ, This is my form code:
<form action-xhr="<?php echo get_rest_url( null, '/custom-page/sendform/'); ?>" custom-validation-reporting="show-all-on-submit" method="post" target="_top">
<div class="formF">
<input type="text" name="name" id="name" value="" autocomplete="first-name" placeholder="First Name *" required pattern="^[a-zA-ZÀ-ÿ '´-]+$"/>
<div class="error-message-val">
<span visible-when-invalid="valueMissing" validation-for="name">Complete this field</span>
<span visible-when-invalid="patternMismatch" validation-for="name">Please enter your first name</span>
</div>
</div>
<div class="formF">
<input type="text" name="lastname" id="lastname" value="" autocomplete="last-name" placeholder="Last Name *" required pattern="^[a-zA-ZÀ-ÿ '´-]+$"/>
<div class="error-message-val">
<span visible-when-invalid="valueMissing" validation-for="lastname">Complete this field</span>
<span visible-when-invalid="patternMismatch" validation-for="lastname">Please enter your last name</span>
</div>
</div>
<div class="formF">
<input type="email" name="email" id="email" value="" autocomplete="contact-email" placeholder="Email Address *" required />
<div class="error-message-val">
<span visible-when-invalid="valueMissing" validation-for="email">Complete this field</span>
<span visible-when-invalid="typeMismatch" validation-for="email">Please enter a valid email</span>
</div>
</div>
<div class="formF">
<input type="text" name="phone" id="phone" value="" autocomplete="phone-number" placeholder="Phone Number *" required pattern="^[0-9\+() ]{1,}[0-9\-() ]+$"/>
<div class="error-message-val">
<span visible-when-invalid="valueMissing" validation-for="phone">Complete this field</span>
<span visible-when-invalid="patternMismatch" validation-for="phone">Please enter a valid phone number</span>
</div>
</div>
<div class="formF">
<input type="text" name="jobtitle" id="jobtitle" value="" autocomplete="job-title" required placeholder="Job Title *"/>
<div class="error-message-val">
<span visible-when-invalid="valueMissing" validation-for="jobtitle">Complete this field</span>
<span visible-when-invalid="patternMismatch" validation-for="jobtitle">Please enter your job title</span>
</div>
</div>
<div class="formF">
<input type="text" name="company" id="company" value="" autocomplete="company-name" placeholder="Company *" required />
<div class="error-message-val">
<span visible-when-invalid="valueMissing" validation-for="company">Complete this field</span>
</div>
</div>
<div class="formF">
<select class="" name="company-country" id="company-country" required on="change:AMP.setState({visibility: event.value=='US'?'sF':'hide'})">
<option value="" selected disabled>Company HQ Country *</option>
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
</select>
<div class="error-message-val">
<span visible-when-invalid="valueMissing" validation-for="company-country">Complete this field</span>
</div>
</div>
<div class="formF hide" [class]="visibility||'show'">
<select name="company-states" id="company-states">
<option value="" selected disabled>State</option>
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
</select>
</div>
<div class="formF">
<select class="" name="interest" id="interest" required>
<option value="" selected disabled>I'm interested in *</option>
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
</select>
<div class="error-message-val">
<span visible-when-invalid="valueMissing" validation-for="interest">Complete this field</span>
</div>
</div>
<div class="formF">
<label>Details</label>
<textarea name="details" rows="8" cols="80" placeholder="Details"></textarea>
</div>
<div class="formF btnsSubmit">
<button type="submit">Submit</button>
</div>
<div class="formF btnsCancel">
<a class="without-border-btn" href="<?php the_permalink(); ?>">Cancel</a>
</div>
</form>
How can you see, I'm using "action-xhr". I have seen other issues where they report problems between IE11 and the use of "action-xhr". Is it possible that it is related to my problem?
Regards!
Thanks for sharing some of your markup, that helped. I created a reproduction case and I am still not able to reproduce. Are you able to observe your issue at this URL? https://amphtml-repro-22201.glitch.me/
There have been some issues in the past, but they had different root causes. https://github.com/ampproject/amphtml/issues/11149 was caused by the author giving the headers a value that IE did not parse https://github.com/ampproject/amphtml/issues/18183 involved a bug with templates in IE11 and has been fixed

Thanks for the test link! I don't understand what is happening ... This demo (-> https://amphtml-repro-22201.glitch.me/) works fine in IE11

But my code does not :(
Some other references about my project: - It's a website in wordpress. - The form is in a page and in the file "functions.php" I have the code that executes the form. The code is this:
<?php
function processContactForm(){
if( !empty($_POST['name']) ){
// Validate origin
$site_url = get_site_url();
$site_url_https = set_url_scheme($request_origin, 'https');
$site_url_https_no_path = stripUrlPath(set_url_scheme($site_url, 'https'));
$request_origin = $_SERVER['HTTP_ORIGIN'];
$request_origin_https = set_url_scheme($request_origin, 'https');
if( $site_url_https_no_path !== $request_origin_https){
return;
}
// Set redirection headers
header('AMP-Access-Control-Allow-Source-Origin: ' . $request_origin);
header('Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin');
$contactWpId = !empty($_POST['contact_wp_id']) ? $_POST['contact_wp_id'] : '';
// Get fields
$form_fields = array(
'name' => !empty($_POST['name']) ? $_POST['name'] : '',
'lastname' => !empty($_POST['lastname']) ? $_POST['lastname'] : '',
'email' => !empty($_POST['email']) ? $_POST['email'] : '',
'phone' => !empty($_POST['phone']) ? $_POST['phone'] : '',
'jobTitle' => !empty($_POST['jobtitle']) ? $_POST['jobtitle'] : '',
'company' => !empty($_POST['company']) ? $_POST['company'] : '',
'companyCountry' => !empty($_POST['company-country']) ? $_POST['company-country'] : '',
'companyState' => !empty($_POST['company-states']) ? $_POST['company-states'] : '',
'interest' => !empty($_POST['interest']) ? $_POST['interest'] : '',
'details' => !empty($_POST['details']) ? preg_replace( "/\r|\n/", "", $_POST['details']) : '',
'onlineInquiry' => '',
'receiveMoreInformation' => $_POST['receive-more-information'] == 'on' ? 1 : 0
);
if( empty($contactWpId) || get_post_type($contactWpId) !== 'contact' ){
exit();
}
$tempFile = '/tmp/' . uniqid('reg-' . mt_rand(), true) . '.csv';
touch($tempFile);
chmod($tempFile, 0600);
$fp = fopen($tempFile, 'w');
if ($fp) {
fputcsv($fp, $form_fields);
fclose($fp);
}
$cfile = new CURLFile($tempFile, 'text/csv', 'newLead.csv');
// PRODUCTION
$url = 'https://myomian.con/ImporterService/xsxsxsssxxssxsxsxsxsxsxsx/';
$postParams['upload'] = $cfile;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
$result = curl_exec($ch);
curl_close($ch);
$redirect_url = get_permalink($contactWpId);
$errors = false;
if (!empty($result)) {
$redirect_url .= '?success=1';
} else {
$redirect_url .= '?contactError=1';
$errors = true;
}
// Redirect to Thank You
header('AMP-Redirect-To: ' . $redirect_url);
if($errors)
echo json_encode(array('status' => 'OK'));
else
echo json_encode(array('status' => 'ERROR'));
exit();
}
?>
- The amp dependencies that I use are:
<?php
<script async src = "https://cdn.ampproject.org/v0.js">
<script async custom-element = "amp-carousel" src = "https://cdn.ampproject.org/v0/amp-carousel-0.1.js"> </ script>
<script async custom-element = "amp-sidebar" src = "https://cdn.ampproject.org/v0/amp-sidebar-0.1.js"> </ script>
<script async custom-element = "amp-form" src = "https://cdn.ampproject.org/v0/amp-form-0.1.js"> </ script>
<script async custom-element = "amp-selector" src = "https://cdn.ampproject.org/v0/amp-selector-0.1.js"> </ script>
<script async custom-element = "amp-lightbox" src = "https://cdn.ampproject.org/v0/amp-lightbox-0.1.js"> </ script>
<script async custom-element = "amp-iframe" src = "https://cdn.ampproject.org/v0/amp-iframe-0.1.js"> </ script>
<script async custom-element = "amp-youtube" src = "https://cdn.ampproject.org/v0/amp-youtube-0.1.js"> </ script>
<script async custom-element = "amp-accordion" src = "https://cdn.ampproject.org/v0/amp-accordion-0.1.js"> </ script>
<script async custom-element = "amp-social-share" src = "https://cdn.ampproject.org/v0/amp-social-share-0.1.js"> </ script>
<script async custom-element = "amp-bind" src = "https://cdn.ampproject.org/v0/amp-bind-0.1.js"> </ script>
<script async custom-element = "amp-user-notification" src = "https://cdn.ampproject.org/v0/amp-user-notification-0.1.js"> </ script>
?>
Regards!
From a quick read it looks like the php code might be setting the header Access-Control-Expose-Headers twice, or missing the AMP-Redirect-To header, but I can't say for sure. I don't see those headers at all in the response screenshot you posted. https://github.com/ampproject/amphtml/issues/22201#issuecomment-490993360
@amedina do you have any WordPress wisdom to apply here? Does WP overwrite any headers?
As I understand, those headers aren't seen in the screenshots of IE11 because the form doesn't execute the "submit".
I am confused, because if the form didn't execute the submit, there would not be a response, and the open tab says "Response" so there must have been a response.
Here is the sequence of events that I understand:
- User clicks submit
- amp-form creates request object
- amp-form sends ajax request
- server sends response
- amp-form reads response to make sure required headers are present
- required headers are not present, so the amp-form does throws and error and does not redirect.
The error message you received says Response must contain the AMP-Access-Control-Allow-Source-Origin header, so we know submit must have executed and the response was received, but an error is thrown because the AMP-Access-Control-Allow-Source-Origin header is missing.
If the problem with the headers is solved, the form will not throw an error and will show successfully after submit.
Thanks for working through this : )
Of course, the problem is that I have already done a lot of tests to correct the headers and nothing works for IE11 : (
Closing since repro https://amphtml-repro-22201.glitch.me/ works in IE11 and therefore a userland issue.
Please reopen with more information if needed.