Skip to content

Commit

Permalink
Merge pull request #1 from harshjain777/main
Browse files Browse the repository at this point in the history
adding server
  • Loading branch information
YashChikhale authored Jan 10, 2025
2 parents 823aafa + 15e9401 commit 67ee759
Show file tree
Hide file tree
Showing 1,855 changed files with 298,740 additions and 4 deletions.
Binary file added .DS_Store
Binary file not shown.
48 changes: 44 additions & 4 deletions Task-4/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,56 @@ <h2>We will Love to Hear from You</h2>
<p>123 RB Lane, R-City, Mumbai-400036</p>
</div>
</div>
<form action="#" method="post">
<input type="text" name="name" placeholder="Your Name" required>
<input type="email" name="email" placeholder="Your Email" required>
<textarea name="message" placeholder="Your Message" rows="5" required></textarea>
<form id="contactForm">
<input type="text" name="name" id="name" placeholder="Your Name" required>
<input type="email" name="email" id="email" placeholder="Your Email" required>
<textarea name="message" id="message" placeholder="Your Message" rows="5" required></textarea>
<button type="submit">Send Message</button>
</form>
<div id="responseMessage" style="display:none; margin-top:10px;"></div>
</section>
</div>
<footer>
<p>&copy; 2025 PAWs | <a href="#privacy-policy">Privacy Policy</a></p>
</footer>

<script>
const form = document.getElementById('contactForm');
const responseMessage = document.getElementById('responseMessage');

form.addEventListener('submit', async (e) => {
e.preventDefault();

const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const message = document.getElementById('message').value;

try {
const response = await fetch('http://localhost:8000/api/contact/contactuser', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ userName: name, email, description: message }),
});

const data = await response.json();

if (data.success) {
responseMessage.style.color = 'green';
responseMessage.textContent = data.message;
} else {
responseMessage.style.color = 'red';
responseMessage.textContent = 'Failed to send message. Please try again later.';
}
} catch (error) {
responseMessage.style.color = 'red';
responseMessage.textContent = 'An error occurred while sending the message.';
console.error('Error:', error);
}

responseMessage.style.display = 'block';
});
</script>
</body>
</html>
Binary file added server/.DS_Store
Binary file not shown.
Empty file added server/.gitignore
Empty file.
30 changes: 30 additions & 0 deletions server/controllers/Contact.Controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const Contact = require('../models/contact.model.js')

const contactUser = async(req,res)=>{
const {userName,email,description} = req.body;

try {

const newContact = new Contact({
userName,
email,
description
})
await newContact.save();

res.status(200).json({
success:true,
message:"message sent successfully"
})

} catch (error) {
console.log(error);
res.status(500).json({
success:false,
message:'error while sending message'
})

}
}

module.exports = {contactUser}
19 changes: 19 additions & 0 deletions server/models/contact.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const mongoose = require('mongoose')

const ContactSchema = new mongoose.Schema({
userName:{
type:String,
required:true
},
email:{
type:String,
required:true
},
description:{
type:String,
required:true
}
});

const Contact = mongoose.model('Contact',ContactSchema)
module.exports = Contact;
1 change: 1 addition & 0 deletions server/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/nodemon

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/nodetouch

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 67ee759

Please sign in to comment.