Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
hi all, trying to setup an external test to ensure our contact form is always working, using the task scheduler on my synology NAS but struggling to get the syntax right, can someone let me know what I'm doing wrong?
URL: https://calmbuddhi.com.au/pages/contact-us
I am able to do a simple test without the form submission and the script returns the correct 200/404 response so the connectivity is OK.
When I add the form data to the script, the response is "Form submission failed. Response code: 404". The URL is correct, but I have a feeling I'm not setting the form action or something around this. The form details : action="/contact#ContactForm" id="ContactForm"
#!/bin/bash
# URL of the contact form (Replace with the actual URL of your Shopify contact form action URL)
FORM_URL="https://calmbuddhi.com.au/pages/contact-us"
# Form data (Replace 'form_type' and 'utf8' with actual hidden input field names and values if required)
FORM_DATA="form_type=contact&utf8=✓&contact[name]=Testuser&contact[email]=test@calmbuddhi.com.au&contact[body]=This is a test message."
# Send the POST request and capture the response
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "$FORM_DATA" "$FORM_URL")
# Check if the response code is 200 (OK)
if [ "$RESPONSE" -eq 200 ]; then
echo "Form submission successful."
else
echo "Form submission failed. Response code: $RESPONSE"
fi
thanks for any help.
Solved! Go to the solution
This is an accepted solution.
Hi @hotify,
Thanks for reaching out to the community. We are MooseDesk, a comprehensive Live Chat, FAQ & Helpdesk App designed to elevate your customer support experience.
Hello! I understand that you're trying to set up an external test to ensure your contact form is always working. I have some suggestions to help you better understand the issue and why your bash script isn't working as expected:
1 - First, try testing the form directly on the website:
fetch('https://calmbuddhi.com.au/contact#ContactForm', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
'form_type': 'contact',
'utf8': '✓',
'contact[Name]': 'Test Name',
'contact[email]': 'test@example.com',
'contact[Message]': 'This is a test message'
})
})
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
You'll see a successful submit request in the Network tab.
3 - Now, try running the same script on a different website (not https://calmbuddhi.com.au). You'll see a CORS error with status code 304 in the Network tab.
4 - This is why you can't use a bash script to test this form externally. Your website has CORS security measures in place that prevent requests from other domains.
To address this issue, you have several options:
In conclusion, the inability to use a bash script to test the form externally is due to CORS security measures, not an error in your script. I recommend considering safer alternative methods to test the availability of your contact form.
If this is helpful for you, please let me know by giving MooseDesk a 'LIKE'. If your question is answered please mark this as 'SOLUTION’.
Thank you for reading. Wish you a nice day ahead!
Was your question answered? Giving MooseDesk's reply a Like or marking it as an Accepted Solution!
Install now. Be our early bird and get all features free forever.
This is an accepted solution.
Hi @hotify,
Thanks for reaching out to the community. We are MooseDesk, a comprehensive Live Chat, FAQ & Helpdesk App designed to elevate your customer support experience.
Hello! I understand that you're trying to set up an external test to ensure your contact form is always working. I have some suggestions to help you better understand the issue and why your bash script isn't working as expected:
1 - First, try testing the form directly on the website:
fetch('https://calmbuddhi.com.au/contact#ContactForm', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
'form_type': 'contact',
'utf8': '✓',
'contact[Name]': 'Test Name',
'contact[email]': 'test@example.com',
'contact[Message]': 'This is a test message'
})
})
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
You'll see a successful submit request in the Network tab.
3 - Now, try running the same script on a different website (not https://calmbuddhi.com.au). You'll see a CORS error with status code 304 in the Network tab.
4 - This is why you can't use a bash script to test this form externally. Your website has CORS security measures in place that prevent requests from other domains.
To address this issue, you have several options:
In conclusion, the inability to use a bash script to test the form externally is due to CORS security measures, not an error in your script. I recommend considering safer alternative methods to test the availability of your contact form.
If this is helpful for you, please let me know by giving MooseDesk a 'LIKE'. If your question is answered please mark this as 'SOLUTION’.
Thank you for reading. Wish you a nice day ahead!
Was your question answered? Giving MooseDesk's reply a Like or marking it as an Accepted Solution!
Install now. Be our early bird and get all features free forever.
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024