Comments (5)
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):
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));
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.
- Report the error "upstream" to Safari: the issue "form.elements should not contain image elements." is a known bug reported in the Safari bug-tracker. We can improve by contributing to it and reporting it further with examples and reproductible scenarios.
- Improve our script to safe-guard these edge cases: at first glance, this issue should not be possible ("all form elements' keys should return a valid form element"), but as we just saw, this can break and halt the execution of our script. This could also solve other issues that might be related to this specific problem (#351, #425).
from learn-to-send-email-via-google-script-html-no-server.
from learn-to-send-email-via-google-script-html-no-server.
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?
from learn-to-send-email-via-google-script-html-no-server.
from learn-to-send-email-via-google-script-html-no-server.
from learn-to-send-email-via-google-script-html-no-server.
Related Issues (20)
- Concatenating Name and String to make a custom subject for each email. HOT 12
- Help with customizing the email sent HOT 1
- Redirecting? HOT 4
- Can You please provide video.
- Adding new entries to the top of google sheet HOT 3
- send email via google script html
- ajax post works on pc but doesnt on mobile phones? HOT 1
- Checkbox input fields issue HOT 1
- Hide hidden input fields in email HOT 3
- update & fix readme links
- update links
- update researching recommendations on user privacy link HOT 1
- Thank You message doesn't disply HOT 1
- Receive Pictures and Documents HOT 4
- Mail is no longer delivered HOT 7
- {"result":"error","error":{"message":"\"TO_ADDRESS\" is not defined.","name":"ReferenceError","fileName":"script","lineNumber":56,"stack":"\tat script:56 (doPost)\n"}} HOT 2
- reload upon submission HOT 2
- QUESTION - Does This Work With React? HOT 4
- File input
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from learn-to-send-email-via-google-script-html-no-server.