Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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

55%
+3 −2
Q&A Uncaught TypeError: Failed to construct 'FormData' [closed]

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...

1 answer  ·  posted 3y ago by deleted user  ·  closed 3y ago by Alexei‭

#7: Question closed by user avatar Alexei‭ · 2021-12-10T16:03:28Z (almost 3 years ago)
#6: Post edited by (deleted user) · 2021-12-10T09:26:04Z (almost 3 years ago)
  • 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 by (deleted user) · 2021-12-10T04:55:04Z (almost 3 years ago)
  • 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 by (deleted user) · 2021-12-10T04:48:13Z (almost 3 years ago)
  • 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 by (deleted user) · 2021-12-10T04:47:03Z (almost 3 years ago)
  • 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 by (deleted user) · 2021-12-10T04:39:47Z (almost 3 years ago)
  • 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 by (deleted user) · 2021-12-10T04:35:27Z (almost 3 years ago)
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
});
```