My PHP/JS contact form is not doing anything when I click send

I have created a simple portfolio website through Github pages, but I cannot get the contact form to work. You can see the contact form here.

When I click on send, nothing ever happens, and I cannot figure out why the code is not connected, as everything seems like it was in the template at the beginning.

Here is the JS code:

    $("#contactform").submit(function () {
        var a = $(this).attr("action");
        $("#message").slideUp(750, function () {
            $("#message").hide();
            $("#submit").attr("disabled", "disabled");
            $.post(a, {
                name: $("#name").val(),
                email: $("#email").val(),
                comments: $("#comments").val()
            }, function (a) {
                document.getElementById("message").innerHTML = a;
                $("#message").slideDown("slow");
                $("#submit").removeAttr("disabled");
                if (null != a.match("success")) $("#contactform").slideDown("slow");
            });
        });
        return false;
    });
    $("#contactform input, #contactform textarea").keyup(function () {
        $("#message").slideUp(1500);
    });
    $(".mob_filter-btn").on("click", function () {
        $(".inline-filters-wrap .gallery-filters").fadeToggle(400);

    });

Here is the HTML:

<div id="contact-form" class="fl-wrap">
   <div id="message"></div>
   <form  class="custom-form" action="php/contact.php" name="contactform" id="contactform">
   </form>
</div>
</div>
</section>
<fieldset>
   <input type="text" name="name" id="name" placeholder="Your name *" value="">
   <input type="text"  name="email" id="email" placeholder="Your email *" value="">
   <textarea name="comments"  id="comments" cols="40" rows="3" placeholder="Your message:"></textarea>
   <button class="btn float-btn flat-btn color-bg" id="submit">Send </button>
</fieldset>

And here is the PHP:

<?php

if(!$_POST) exit;

// Email address verification, do not edit.
function isEmail($email) {
    return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]]).)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]).){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}

if (!defined("PHP_EOL")) define("PHP_EOL", "rn");

$name     = $_POST['name'];
$email    = $_POST['email'];
$comments = $_POST['comments'];


if(trim($name) == '') {
    echo '<div class="error_message">Enter your name.</div>';
    exit();
} else if(trim($email) == '') {
    echo '<div class="error_message">Enter a valid email address.</div>';
    exit();
} else if(!isEmail($email)) {
    echo '<div class="error_message">You have entered an invalid e-mail address. Please try again.</div>';
    exit();
} else if(trim($comments) == '') {
    echo '<div class="error_message">Enter your message.</div>';
    exit();
} 

if(get_magic_quotes_gpc()) {
    $comments = stripslashes($comments);
}


// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "[email protected]";

//$address = "[email protected]";
$address = "[email protected]";


// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."

// Example, $e_subject = '$name . ' has contacted you via Your Website.';

$e_subject = 'You've been contacted by ' . $name . '.';


// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.

$e_body = "You have been contacted by: $name" . PHP_EOL . PHP_EOL;
$e_reply = "E-mail: $emailrnPhone: $phone";
$e_content = "Message:rn$comments" . PHP_EOL . PHP_EOL;


$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );

$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;

if(mail($address, $e_subject, $msg, $headers)) {

    // Email has sent successfully, echo a success page.

    echo "<fieldset>";
    echo "<div id='success_page'>";
    echo "<h3>Email sent successfully.</h3>";
    echo "<p>Thank you <strong>$name</strong>. Your message has been submitted to us.</p>";
    echo "</div>";
    echo "</fieldset>";

} else {

    echo 'ERROR!';

}

Can anyone please guide me in the right direction as I don’t even know where to look? I have tried searching the web but couldn’t find explanations on how the code works. I figured (at least broadly) what each piece of the code does, but cannot understand where the problem lies. Thanks for any help.

How to get the duration of a video in an iframe?

I’m a beginner in programming and I’m trying to get the length (in seconds) of a YouTube video that is in an iframe for a purpose, can anyone help me?

This is my iframe:

<iframe id="youtube-video" height="500" src="https://www.youtube.com/embed/uSkPqgnBmUk?autoplay=1" allow="autoplay"></iframe>

I need it to be the easiest way in JS!!

Thanks in advance.

I tried to find it here on the website but without success.

Using TAB in JavaScript [closed]

I like using TAB more than SPACE when I’m writing code and I use it everywhere I can to position myself better and faster.
But in JavaScript I can’t seem to use it to escape certain brackets and then I’m forced to use arrow keys. I’m using VS Code as my editor.
Can I use certain combination of keys or another editor that will allow me to do this in JavaScript?
I have tried googling this issue but it keeps taking me to threads that aren’t connected to using TAB at all.

React onLoad not calling function im passing in?

React onLoad not calling function im passing in?

import { useRef } from 'react';

import './ProductCard.css';
 
export default function ProductCard(props) {

    const stars = useRef();

    function setStars() {
        for (let i = 0; i < props.product.priority; i++) { 
            stars.current.children[i].classList.add('checked');
        }
    }

    return(
        <div>
            <div className="card">
            <h1>{props.product.productName}</h1>
            <p className="price">${props.product.price}</p>
            <p ref={stars} className="importance" onLoad={setStars}>
                <span className="fa fa-star"></span>
                <span className="fa fa-star"></span>
                <span className="fa fa-star"></span>
                <span className="fa fa-star"></span>
                <span className="fa fa-star"></span>
            </p>
            <p><button onClick={() => window.open(props.product.productUrl)}>Visit site</button></p>
            </div>
        </div>
    )
}

i tried adding brackets to call it but then i get an error:

enter image description here

multer-gridfs error ” TypeError: Cannot read properties of undefined (reading ‘_id’) “

I’m working on creating a WhatsApp clone and implementing a file sharing feature. Everything was going smoothly until I encountered this error that’s causing my backend to crash. The strange thing is, I can see the file in MongoDB, but the error persists. I’m hoping someone can help me troubleshoot this issue.

Here’s a summary of what’s happening:

I have a file sharing feature in my WhatsApp clone app.
When a user tries to share a file, it’s saved to MongoDB.
I can confirm that the file exists in the MongoDB database.
However, the backend crashes with an error that I can’t seem to resolve.
I’m not sure where to begin troubleshooting this issue. Can anyone provide insights on what might be causing this problem? Is there a common mistake I might be making when dealing with file sharing in a MongoDB database?

i cant post all my code here my question will be too long [here is my github link][1]

api.js

export const uploadFile = async (data) => {
    try {
        return await axios.post(`${url}/file/upload`, data);
    } catch (error) {
        console.log('Error while calling uploadfile API ', error);
    }
}

controller

const url = 'http://localhost:8000';
export const uploadFile = async(request, response)=>{
    if(!request.file){
        return response.status(404).json("file not found")
    }
    const imageUrl = `${url}/file/${request.file.filename}`;
    return response.status(200).json(imageUrl);
}

route.js

//Route for file upload
route.post('/file/upload', upload.single("file"), uploadFile);

error

C:UsersuserOneDriveDocumentswebdevwhatsapp clone selfservernode_modulesmulter-gridfs-storagelibgridfs.js:306
                        id: f._id,
                              ^

TypeError: Cannot read properties of undefined (reading '_id')       
    at GridFSBucketWriteStream.emitFile (C:UsersSiddhOneDriveDocumentswebdevwhatsapp clone selfservernode_modulesmulter-gridfs-storagelibgridfs.js:306:31)
    at GridFSBucketWriteStream.emit (node:events:526:35)
    at finish (node:internal/streams/writable:807:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v20.9.0
[nodemon] app crashed - waiting for file changes before starting...

javascript from basic to advance learning [closed]

I want to learn javascript on free platform, which platform you suggest, I am thinking about code academy, but in code academy there are many courses of javascript, so which should i learn first? so what is the correct order to learn javascript at code academy ?

I want to learn javascript from basic to advance.

How to use with Facebook HTTP_REFERER (with php)

I would like to know how I can use this method so that if someone clicks on my website through a post on Facebook, it goes to another page, using HTTP_REFERER, and if possible, have cookies so that it only goes to that page once

I need that when clicking only on Facebook the person is taken to another page instead of the home page

Replacing div content with JavaScript – YouTube sidebar

I try to replace “opened persistent” with “persistent” on:

<div id="contentContainer" class="style-scope tp-yt-app-drawer" position="left" swipe-open style="transition-duration: 0ms;" opened persistent>

Any help much appreciated.

So far doesn’t work with the below:

document.getElementById('contentContainer').innerHTML = '';
var h1 = document.createElement('h1'); h1.innerHTML = “persistent; document.getElementById('contentContainer').appendChild(h1);

Event delegation on non nested elements

I’m using Bootstrap group radio button on which I would like to write event delegation.

<div class="btn-group" role="group" aria-label="Basic radio toggle button group">
  <input type="radio" class="btn-check" name="btnradio" id="btnradio1" autocomplete="off" checked>
  <label class="btn btn-outline-primary" for="btnradio1">Radio 1</label>

  <input type="radio" class="btn-check" name="btnradio" id="btnradio2" autocomplete="off">
  <label class="btn btn-outline-primary" for="btnradio2">Radio 2</label>

  <input type="radio" class="btn-check" name="btnradio" id="btnradio3" autocomplete="off">
  <label class="btn btn-outline-primary" for="btnradio3">Radio 3</label>
</div>

Since the labels are not nested in the button, the following is not returning the inputs.

event.target.closest('.btn-check');

Is there a proper way to write event delegation on this type of non-nested elements?

Sort numbers and NaN conditionally [duplicate]

I try to sort example array:

const array = [5, 9, NaN, 3, 15];

My expected result is:

const expected = [3, 5, 9, 15, NaN];

So the numbers are sorted ascending and the NaN values are at the end.

I tried with simple

const res = array.sort((a, b) => a - b);

or

const res = array.sort((a, b) => {
   if (a > b) return 1;
   if (b > a) return -1;
   return 0;
});

But none work. Side question – why the result is the same in both cases?

const array = [5, 9, NaN, 3, 15];

const res1 = array.sort((a, b) => a - b);
const res2 = array.sort((a, b) => b - a);

console.log(res1, res2);

How to place an image inside a SVG shape? [duplicate]

I have the following shape:

enter image description here

<svg width="64" height="64" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
<rect width="64" height="52" rx="4.66667" transform="matrix(-1 0 0 1 64 0)" fill="white"/>
<path d="M15 52H29L15 64V52Z" fill="white"/>
</svg>

I am trying to put an image inside this shape but I don’t want the image to overflow. I’d like to get something like the image below but instead of red background I’d like it to be a real image:

enter image description here

I already tried a few things:

<svg width="581" height="692" viewBox="0 0 581 692" fill="none" xmlns="http://www.w3.org/2000/svg">
  <clipPath id="cp">
    <use href="#thePath" />
  </clipPath>
  <rect width="64" height="52" rx="4.66667" transform="matrix(-1 0 0 1 64 0)" fill="white" />
  <image clip-path="url(#cp)" href={avatar} width="64" x="0" y="0" />
  <path d="M15 52H29L15 64V52Z" fill="white" />
</svg>

but that gives me this:
enter image description here

Can you please help me figure it out?

Thanks!

Issue with creating a tree with lines in HTML by modifying the Angular material Tree

I try to create a Tree with lines using the Angular material tree component.
The goal is to have a Tree with lines in order to see the sources of each Tree leaf. As you will able to see in the stackblitz i just adding some element to show the border for each node

I almost got it to work, but i have this issue as you can see here with the group lines, since the lines should appear the same as the root:

enter image description here

Should be like this:

enter image description here

Any help solving this issue will be highly appreciat.

Library or API to provide URL suggestions

I’m searching something to provide URL suggestion in my web app.
For instance, the input could be yout and it will return www.youtube.com and other possible match.

I’ve searched multiple times and I haven’t found something correct. Does anyone know something that can achieve that?

Thx

I’ve an error in my react-project(I’m doing an amazon-clone)

ERROR
undefined is not iterable (cannot read property Symbol(Symbol.iterator))
TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
at Header (http://localhost:3000/static/js/bundle.js:400:18)
at renderWithHooks (http://localhost:3000/static/js/bundle.js:35333:22)
at mountIndeterminateComponent (http://localhost:3000/static/js/bundle.js:38619:17)

This is my header.js

import React from "react";
import "./Header.css";
import ShoppingBasketIcon from "@mui/icons-material/ShoppingBasket";
import StorefrontIcon from "@mui/icons-material/Storefront";
import SearchIcon from "@mui/icons-material/Search";
import { Link } from "react-router-dom";
import { useStateValue } from "./StateProvider";
function Header() {
  const [{ basket }, dispatch] = useStateValue();
  return (
    <div className="header">
      <Link to="/" style={{ textDecoration: "none" }}>
        <div className="header_logo">
          <StorefrontIcon className="header_logoImage" fontSize="large" />
          <h2 className="header_logoTitle">eShop</h2>
        </div>
      </Link>
      <div className="header_search">
        <input type="text" className="header_searchInput" />
        <SearchIcon className="header_searchIcon" />
      </div>
      <div className="header_nav">
        <div className="nav_item">
          <span className="nav_itemLineOne">Hello Guest</span>
          <span className="nav_itemLineTwo">Sign In</span>
        </div>
        <div className="nav_item">
          <span className="nav_itemLineOne">Your</span>
          <span className="nav_itemLineTwo">Shop</span>
        </div>
        <Link to="/checkout" style={{ textDecoration: "none" }}>
          <div className="nav_itemBasket">
            <ShoppingBasketIcon />
            <span className="nav_iteminTwo nav_basketCount">
              {basket.length}
            </span>
          </div>
        </Link>
      </div>
    </div>
  );
}
export default Header;

This is my project on github

I’ve tried to install the latest versions of react-dom and etc, cause I’m watchin a tutorial how to create an amazon-clone and I did the same things like in tutorial, but my code doesn’t work