Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
React Bootstrap using EmailJs show toast/modal on successful sent

I want a toast/modal notification once the form is submitted, right now its only "alert" message. And i want it like this:

<div className="toast_modal">We've received your inquiry, we'll get back to you as soon as possible. Thank you!"</div>

here is my code:

import {useState} from 'react';
import emailjs from 'emailjs-com';

const NameForm = () => {
  const [showModal,setShowModal] = useState(false);
  const sendEmail = (e) => {
      e.preventDefault();

      emailjs.sendForm('service_ID', 'template_ID', e.target, 'user_ID')
        .then((result) => {
            console.log(result.text);
            setShowModal(true);

        }, (error) => {
            console.log(error.text);
        });
        e.target.reset();
    }
    
    return (
      <div>
        <h1 className="text-center text-md-left mb-3">Get in Touch</h1>
        <form className="contact-form" onSubmit={sendEmail}>
            <div className="form-group mb-0 py-3">
              <textarea className="form-control custom--fields-mod text-the-primary" id="message" rows="3" placeholder="Message *" name="message" required></textarea>
            </div>
            <div className="form-group row py-2 mb-0">
              <div className="col-md-6 text-center text-md-left py-2 py-md-0">
                <input className="buttons-width float-md-right btn btn-dark-moderate-orange rounded-0" type="submit" value="SEND MESSAGE" />
              </div>
            </div>
        </form>
        {showModal && (
        <div className="modal fade show d-block" tabIndex={-1}>
          <div className="modal-dialog modal-dialog-centered modal-dialog-scrollable">
            <div className="modal-content bg-white border border-the-primary">
              <div className="modal-body text-center py-4">
                <p>We've received your inquiry, we'll get back to you as soon as possible. Thank you!"</p>
                <button type="button" class="btn btn-dark-moderate-orange px-5" data-dismiss="modal">Close</button>
              </div>
            </div>
          </div>
        </div>
        )}

      </div>
    );
  
}
export default NameForm;

Im trying to achieve the toast/modal notifications once the form is submitted.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First of all I prefer to you to use functional component. To show toast_modal you can use a state. Then use this state in return.

import {useState} from 'react';
import emailjs from 'emailjs-com';

const NameForm = () => {
  const [showModal,setShowModal] = useState(false);
  const sendEmail = (e) => {
      e.preventDefault();

      emailjs.sendForm('service_ID', 'template_ID', e.target, 'user_ID')
        .then((result) => {
            console.log(result.text);
            setShowModal(true);

        }, (error) => {
            console.log(error.text);
        });
        e.target.reset();
    }
    
    return (
      <div>
        <h1 className="text-center text-md-left mb-3">Get in Touch</h1>
        <form className="contact-form" onSubmit={sendEmail}>
            <div className="form-group mb-0 py-3">
              <textarea className="form-control custom--fields-mod text-the-primary" id="message" rows="3" placeholder="Message *" name="message" required></textarea>
            </div>
            <div className="form-group row py-2 mb-0">
              <div className="col-md-6 text-center text-md-left py-2 py-md-0">
                <input className="buttons-width float-md-right btn btn-dark-moderate-orange rounded-0" type="submit" value="SEND MESSAGE" />
              </div>
            </div>
        </form>
        {showModal && (
        <div className="modal fade show d-block" tabIndex={-1}>
          <div className="modal-dialog modal-dialog-centered modal-dialog-scrollable">
            <div className="modal-content bg-white border border-the-primary">
              <div className="modal-body text-center py-4">
                <p>We've received your inquiry, we'll get back to you as soon as possible. Thank you!"</p>
                <button type="button" onClick={() => setShowModal(false)} className="btn btn-dark-moderate-orange px-5" data-dismiss="modal">Close</button>
              </div>
            </div>
          </div>
        </div>
        )}

      </div>
    );
  
}
export default NameForm;
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda