shell script for testing contact form - from external site

Solved

shell script for testing contact form - from external site

hotify
Shopify Partner
28 3 13

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.

 

Accepted Solution (1)

MooseDesk
Shopify Partner
325 47 100

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:

  1. If you have server access, you could configure it to allow CORS from your domain. However, this may pose security risks.
  2. Create a separate API endpoint on your server to check the status of the contact form. This endpoint could perform internal checks and return results without encountering CORS issues.
  3. Use a third-party website testing service capable of simulating user interactions.
  4. If you still want to use a bash script, you could consider using a proxy server to bypass CORS, but this is not recommended for security reasons.

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!


MooseDesk - #All-in-one Customer Support and Helpdesk Solution for Shopify Merchants

Install now. Be our early bird and get all features free forever.

View solution in original post

Reply 1 (1)

MooseDesk
Shopify Partner
325 47 100

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:

  1. If you have server access, you could configure it to allow CORS from your domain. However, this may pose security risks.
  2. Create a separate API endpoint on your server to check the status of the contact form. This endpoint could perform internal checks and return results without encountering CORS issues.
  3. Use a third-party website testing service capable of simulating user interactions.
  4. If you still want to use a bash script, you could consider using a proxy server to bypass CORS, but this is not recommended for security reasons.

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!


MooseDesk - #All-in-one Customer Support and Helpdesk Solution for Shopify Merchants

Install now. Be our early bird and get all features free forever.