Topic: Modal Response for Contact Form
Expected behavior The form is functioning as intended, but when an email is submitted post verification it just displays console text. I would like a modal "email sent" to pop up rather than leave the website. I have a minimal understanding of JS and no understanding of things like JSON or PHP; I'm trying to build a design portfolio, but I need some help with the dev stuff!
Actual behavior on submit the form sends confirmation from a new page in JSON? format
Resources (screenshots, code snippets etc.) https://mdbootstrap.com/snippets/jquery/jlstory/2666054
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Open
- User: Free
- Premium support: No
- Technology: MDB jQuery
- MDB Version: 4.9.0
- Device: MacBook Pro
- Browser: Any
- OS: Catalina
- Provided sample code: No
- Provided link: Yes
Grzegorz Bujański staff commented 4 years ago
Hi. Maybe this post will be able to help you achieve the desired effect: https://stackoverflow.com/questions/17333901/php-form-on-submit-stay-on-same-page
jlstory commented 4 years ago
This post says to remove the action tag? If I do this will it not disable the email from being sent?
Also, using php to self is different setup that does not include JSON, which is included in the MDB setup: (the onclick JS command is not used in this solution, should I remove it?)
Submit
Grzegorz Bujański staff commented 4 years ago
This solution should work. But if you use the solution from our documentation, there is also a section that tells you what to do to prevent the page from reloading -
Sending an email without reloading the page using AJAX
. Did you see her?jlstory commented 4 years ago
I'm using the AJAX method, I think, as described in the instructions. I adding a link to the older version of JQuery that is noted in the instructions to the body. Submit still loads a new page with JSON data. I have created a snippet:
https://mdbootstrap.com/snippets/jquery/jlstory/2671906
My understanding is that action to self opens up security risks? Also, action appears to be the link to mail.php. Would I need to embed my php content into index.html for this to work? (Forgive me, I'm learning design; I would like to learn JS and the backend fundamentals, but my sill level is not there yet. I'm a graphic design major, and I'm just trying to get a portfolio up and running.)
Grzegorz Bujański staff commented 4 years ago
I noticed in
mail.php
you didn't addcode = 1
to the message 'Thank you for cantacting Intakt Design!'. Note thatcode
is taken into account for the ajax function. Add it and check if it is enough or it will still redirect you to another page.