Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It only works on PC, Windows, and Android. #451

Open
nextron-microprobe opened this issue Nov 16, 2023 · 5 comments
Open

It only works on PC, Windows, and Android. #451

nextron-microprobe opened this issue Nov 16, 2023 · 5 comments

Comments

@nextron-microprobe
Copy link

nextron-microprobe commented Nov 16, 2023

Ajax is executed when you press the Send button only on PC, Windows, and Android, but does not proceed on iPhone. I tried changing "ajax" to "fetch" to fetch, but it still doesn't work. I didn't always check while updating several times, but I suddenly found that it wasn't working. No code was touched. Although the HTML has been modified, it cannot be explained that it runs in an environment other than iOS.

I've already done things like open the JavaScript toggle or clear cookies in Safari's settings.

Chrome also did the same thing, but only on the iPhone, no matter how many times I pressed the "send button", it didn't work. The email doesn't arrive, and the "thankyou_message" doesn't appear either.

@cristianofromagio
Copy link
Contributor

Do you have any console errors while running on Safari? Chrome on iOS (if I'm not mistaken) also runs WebKit under the hood (like Safari).

Do you have a reproducible code example or have it hosted online somewhere?

@nextron-microprobe
Copy link
Author

nextron-microprobe commented Nov 16, 2023 via email

@cristianofromagio
Copy link
Contributor

I went ahead and tried to reach the Contact page (archived version for reference) from the website in your signature, and indeed, said Contact form failed to submit on Safari.

Solving your issue specifically

If you just want to make this form work on Safari, change the id value on these image elements inside your form to something other than numbers:

<!-- find each one in the code, they are not grouped like this -->

<img style="position:absolute; opacity: 0;" src="./image/update/piezoModule.webp" align="center" id="1002" class="preview" alt="">
<img style="position:absolute; opacity: 0;" src="./image/update/probeModule.webp" align="center" id="1001" class="preview" alt="" title="">
<img style="position:absolute; opacity: 0;" src="./image/update/ModuleDuo.webp" align="center" id="1003" class="preview" alt="">

Notice their ids: id="1002", id="1001" and id="1003". Change them to something else that is not just an integer number, for example id="img1002", id="img1001" and id="img1003". Just that will solve this form specific problem. To understand why, read the explanation below.

Breaking down the issue

This is the error that appears on the console when we try to submit the form in Safari (here I'm using Webkit MiniBrowser on Windows, but should apply to Safari as well):

image

image

This is the related line in our script. Notice the problem is it can't find the name property because (allegedly) elements[k] is undefined.

In this piece of code, elements refers to form.elements a property that returns a HTMLFormControlsCollection. We can access an entry on this collection by an index, by its name attribute or by its id attribute.

You can access a particular form control in the returned collection by using either an index or the element's name or id attributes. ref.

When we try accessing it using elements[k].name, k is one of the HTMLFormControlsCollection keys we get by passing it through the Object.keys() function.

This is what we get on Firefox (left), Chromium (middle) and Safari (right) when we run this script in the page:

// `form` being the contact form

Object.keys(form.elements).map((k) => {
  console.log(k, form.elements[k]);
});

console.log(Object.keys(form.elements));

image

Notice that, apart from the difference in size of Object.keys(form.elements) in each one of them, in Safari the 1002, 1001 and 1003 key returns an undefined element because it tries to find the item in the HTMLFormControlsCollection by its id but because it is an integer it confuses it with an index. That is why changing the img element id to a string solves the problem in this case.

What can we do to fix this?

Although our specific issue is with an integer id acting as an index, the real issue is that image elements shouldn't even be returned in the HTMLFormControlsCollection.

@nextron-microprobe
Copy link
Author

nextron-microprobe commented Nov 21, 2023 via email

@nextron-microprobe
Copy link
Author

nextron-microprobe commented Nov 23, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants