Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
I am trying to submit a form with Ajax from a well-configured shared hosting environment. Emails don't arrive to my email client although I have already sent emails without Ajax from this environm...
#6: Post edited
- I am trying to submit a form with Ajax from a well-configured shared hosting environment.
- Emails don't arrive to my email client although I have already sent emails without Ajax from this environment without a problem so the problem shouldn't be in the email server.
- I assume that emails aren't sent in relation to the following error in browser console:
- > Uncaught TypeError: Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.
- at behavior.js:2
What may cause that problem?- ---
- ## behavior.js
- ```js
- let formToWorkOn = document.querySelector('#prcf_form');
- let formData = new FormData(formToWorkOn);
- fetch('./behavior.php', {
- method: 'POST',
body: formData- });
- ```
- I am trying to submit a form with Ajax from a well-configured shared hosting environment.
- Emails don't arrive to my email client although I have already sent emails without Ajax from this environment without a problem so the problem shouldn't be in the email server.
- I assume that emails aren't sent in relation to the following error in browser console:
- > Uncaught TypeError: Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.
- at behavior.js:2
- **What may cause that problem?**
- ---
- ## index.php
- ```html
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" href="./style.css"></link>
- </head>
- <body>
- <form id="#prcf_form">
- <div class="form">
- <span><label for="prcf_input_name" id="prcf_label_name" class="prcf_label">Name</label></span><span class="prcf_required">*</span>
- <input type="text" name="name" id="prcf_input_name" class="prcf_item" required>
- </input> <!-- required property-->
- </div>
- <div class="prcf_footers">
- <input type="submit" value="Send" id="prcf_submit" class="prcf_finalization_buttons"></input>
- </div>
- </form>
- </body>
- <script src="./behavior.js"></script>
- </html>
- ```
- ## behavior.php
- ```js
- <?php
- $name = $_POST['name']; # Required;
- $to = 'EMAIL_ADDRESS_NAME@DOMAIN';
- $subject = 'New message from: ' . $name;
- include 'message.php';
- $headers[] = 'MIME-Version: 1.0';
- $headers[] = 'Content-type: text/html; charset=utf-8';
- mail($to, $subject, $message, implode("\r\n", $headers));
- ?>
- ```
- ## message.php
- ```php
- <?php
- $message = <<<LABEL
- <html>
- <head>
- </head>
- <body>
- <div><span class="form_output_col_1">Name: </span><span class="form_output_col_2">$name</span></div>
- </body>
- </html>
- LABEL;
- ?>
- ```
- ## behavior.js
- ```js
- let formToWorkOn = document.querySelector('#prcf_form');
- let formData = new FormData(formToWorkOn);
- fetch('./behavior.php', {
- method: 'POST',
- body: formToWorkOn
- });
- ```
#5: Post edited
- I am trying to submit a form with Ajax from a well-configured shared hosting environment.
- Emails don't arrive to my email client although I have already sent emails without Ajax from this environment without a problem so the problem shouldn't be in the email server.
- I assume that emails aren't sent in relation to the following error in browser console:
- > Uncaught TypeError: Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.
- at behavior.js:2
- What may cause that problem?
- ---
- ## behavior.js
- ```js
- let formToWorkOn = document.querySelector('#prcf_form');
- let formData = new FormData(formToWorkOn);
- fetch('./behavior.php', {
- method: 'POST',
body: formToWorkOn- });
- ```
- I am trying to submit a form with Ajax from a well-configured shared hosting environment.
- Emails don't arrive to my email client although I have already sent emails without Ajax from this environment without a problem so the problem shouldn't be in the email server.
- I assume that emails aren't sent in relation to the following error in browser console:
- > Uncaught TypeError: Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.
- at behavior.js:2
- What may cause that problem?
- ---
- ## behavior.js
- ```js
- let formToWorkOn = document.querySelector('#prcf_form');
- let formData = new FormData(formToWorkOn);
- fetch('./behavior.php', {
- method: 'POST',
- body: formData
- });
- ```
#4: Post edited
- I am trying to submit a form with Ajax from a well-configured shared hosting environment.
- Emails don't arrive to my email client although I have already sent emails without Ajax from this environment without a problem so the problem shouldn't be in the email server.
- I assume that emails aren't sent in relation to the following error in browser console:
- > Uncaught TypeError: Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.
- at behavior.js:2
**What may cause that problem?**- ---
- ## behavior.js
- ```js
- let formToWorkOn = document.querySelector('#prcf_form');
- let formData = new FormData(formToWorkOn);
- fetch('./behavior.php', {
- method: 'POST',
- body: formToWorkOn
- });
- ```
- I am trying to submit a form with Ajax from a well-configured shared hosting environment.
- Emails don't arrive to my email client although I have already sent emails without Ajax from this environment without a problem so the problem shouldn't be in the email server.
- I assume that emails aren't sent in relation to the following error in browser console:
- > Uncaught TypeError: Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.
- at behavior.js:2
- What may cause that problem?
- ---
- ## behavior.js
- ```js
- let formToWorkOn = document.querySelector('#prcf_form');
- let formData = new FormData(formToWorkOn);
- fetch('./behavior.php', {
- method: 'POST',
- body: formToWorkOn
- });
- ```
#3: Post edited
- I am trying to submit a form with Ajax from a well-configured shared hosting environment.
- Emails don't arrive to my email client although I have already sent emails without Ajax from this environment without a problem so the problem shouldn't be in the email server.
- I assume that emails aren't sent in relation to the following error in browser console:
- > Uncaught TypeError: Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.
- at behavior.js:2
- **What may cause that problem?**
- ---
## index.php```html<!DOCTYPE html><html><head><link rel="stylesheet" href="./style.css"></link></head><body><form id="#prcf_form"><div class="form"><span><label for="prcf_input_name" id="prcf_label_name" class="prcf_label">Name</label></span><span class="prcf_required">*</span><input type="text" name="name" id="prcf_input_name" class="prcf_item" required></input> <!-- required property--></div><div class="prcf_footers"><input type="submit" value="Send" id="prcf_submit" class="prcf_finalization_buttons"></input></div></form></body><script src="./behavior.js"></script></html>```## behavior.php```js<?php$name = $_POST['name']; # Required;$to = 'EMAIL_ADDRESS_NAME@DOMAIN';$subject = 'New message from: ' . $name;include 'message.php';$headers[] = 'MIME-Version: 1.0';$headers[] = 'Content-type: text/html; charset=utf-8';mail($to, $subject, $message, implode("\r\n", $headers));?>```## message.php```php<?php$message = <<<LABEL<html><head></head><body><div><span class="form_output_col_1">Name: </span><span class="form_output_col_2">$name</span></div></body></html>LABEL;?>```- ## behavior.js
- ```js
- let formToWorkOn = document.querySelector('#prcf_form');
- let formData = new FormData(formToWorkOn);
- fetch('./behavior.php', {
- method: 'POST',
- body: formToWorkOn
- });
- ```
- I am trying to submit a form with Ajax from a well-configured shared hosting environment.
- Emails don't arrive to my email client although I have already sent emails without Ajax from this environment without a problem so the problem shouldn't be in the email server.
- I assume that emails aren't sent in relation to the following error in browser console:
- > Uncaught TypeError: Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.
- at behavior.js:2
- **What may cause that problem?**
- ---
- ## behavior.js
- ```js
- let formToWorkOn = document.querySelector('#prcf_form');
- let formData = new FormData(formToWorkOn);
- fetch('./behavior.php', {
- method: 'POST',
- body: formToWorkOn
- });
- ```
#2: Post edited
- I am trying to submit a form with Ajax from a well-configured shared hosting environment.
- Emails don't arrive to my email client although I have already sent emails without Ajax from this environment without a problem so the problem shouldn't be in the email server.
- I assume that emails aren't sent in relation to the following error in browser console:
- > Uncaught TypeError: Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.
- at behavior.js:2
- **What may cause that problem?**
- ---
- ## index.php
- ```html
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" href="./style.css"></link>
- </head>
- <body>
- <form id="#prcf_form">
- <div class="form">
- <span><label for="prcf_input_name" id="prcf_label_name" class="prcf_label">Name</label></span><span class="prcf_required">*</span>
- <input type="text" name="name" id="prcf_input_name" class="prcf_item" required>
- </input> <!-- required property-->
- </div>
- <div class="prcf_footers">
- <input type="submit" value="Send" id="prcf_submit" class="prcf_finalization_buttons"></input>
- </div>
- </form>
- </body>
- <script src="./behavior.js"></script>
- </html>
- ```
- ## behavior.php
- ```js
- <?php
- $name = $_POST['name']; # Required;
- $to = 'EMAIL_ADDRESS_NAME@DOMAIN';
- $subject = 'New message from: ' . $name;
- include 'message.php';
- $headers[] = 'MIME-Version: 1.0';
- $headers[] = 'Content-type: text/html; charset=utf-8';
- mail($to, $subject, $message, implode("\r\n", $headers));
- ?>
- ```
- ## message.php
- ```php
- <?php
- $message = <<<LABEL
- <html>
- <head>
- </head>
- <body>
- <div><span class="form_output_col_1">Name: </span><span class="form_output_col_2">$name</span></div>
- </body>
- </html>
- LABEL;
- ?>
- ```
- ## behavior.js
- ```js
- let formToWorkOn = document.querySelector('#prcf_form');
- let formData = new FormData(formToWorkOn);
- fetch('./behavior.php', {
- method: 'POST',
- body: formToWorkOn
- });
- ```
- I am trying to submit a form with Ajax from a well-configured shared hosting environment.
- Emails don't arrive to my email client although I have already sent emails without Ajax from this environment without a problem so the problem shouldn't be in the email server.
- I assume that emails aren't sent in relation to the following error in browser console:
- > Uncaught TypeError: Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.
- at behavior.js:2
- **What may cause that problem?**
- ---
- ## index.php
- ```html
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" href="./style.css"></link>
- </head>
- <body>
- <form id="#prcf_form">
- <div class="form">
- <span><label for="prcf_input_name" id="prcf_label_name" class="prcf_label">Name</label></span><span class="prcf_required">*</span>
- <input type="text" name="name" id="prcf_input_name" class="prcf_item" required>
- </input> <!-- required property-->
- </div>
- <div class="prcf_footers">
- <input type="submit" value="Send" id="prcf_submit" class="prcf_finalization_buttons"></input>
- </div>
- </form>
- </body>
- <script src="./behavior.js"></script>
- </html>
- ```
- ## behavior.php
- ```js
- <?php
- $name = $_POST['name']; # Required;
- $to = 'EMAIL_ADDRESS_NAME@DOMAIN';
- $subject = 'New message from: ' . $name;
- include 'message.php';
- $headers[] = 'MIME-Version: 1.0';
- $headers[] = 'Content-type: text/html; charset=utf-8';
- mail($to, $subject, $message, implode("\r\n", $headers));
- ?>
- ```
- ## message.php
- ```php
- <?php
- $message = <<<LABEL
- <html>
- <head>
- </head>
- <body>
- <div><span class="form_output_col_1">Name: </span><span class="form_output_col_2">$name</span></div>
- </body>
- </html>
- LABEL;
- ?>
- ```
- ## behavior.js
- ```js
- let formToWorkOn = document.querySelector('#prcf_form');
- let formData = new FormData(formToWorkOn);
- fetch('./behavior.php', {
- method: 'POST',
- body: formToWorkOn
- });
- ```
#1: Initial revision
Uncaught TypeError: Failed to construct 'FormData'
I am trying to submit a form with Ajax from a well-configured shared hosting environment. Emails don't arrive to my email client although I have already sent emails without Ajax from this environment without a problem so the problem shouldn't be in the email server. I assume that emails aren't sent in relation to the following error in browser console: > Uncaught TypeError: Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'. at behavior.js:2 **What may cause that problem?** --- ## index.php ```html <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="./style.css"></link> </head> <body> <form id="#prcf_form"> <div class="form"> <span><label for="prcf_input_name" id="prcf_label_name" class="prcf_label">Name</label></span><span class="prcf_required">*</span> <input type="text" name="name" id="prcf_input_name" class="prcf_item" required> </input> <!-- required property--> </div> <div class="prcf_footers"> <input type="submit" value="Send" id="prcf_submit" class="prcf_finalization_buttons"></input> </div> </form> </body> <script src="./behavior.js"></script> </html> ``` ## behavior.php ```js <?php $name = $_POST['name']; # Required; $to = 'EMAIL_ADDRESS_NAME@DOMAIN'; $subject = 'New message from: ' . $name; include 'message.php'; $headers[] = 'MIME-Version: 1.0'; $headers[] = 'Content-type: text/html; charset=utf-8'; mail($to, $subject, $message, implode("\r\n", $headers)); ?> ``` ## message.php ```php <?php $message = <<<LABEL <html> <head> </head> <body> <div><span class="form_output_col_1">Name: </span><span class="form_output_col_2">$name</span></div> </body> </html> LABEL; ?> ``` ## behavior.js ```js let formToWorkOn = document.querySelector('#prcf_form'); let formData = new FormData(formToWorkOn); fetch('./behavior.php', { method: 'POST', body: formToWorkOn }); ```