If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

Interactive Comment Window: Seeking Tips

Started by hoitressedil, Jul 16, 2024, 12:48 AM

Previous topic - Next topic

hoitressedilTopic starter

Hey there!

I'm just starting out and diving into html and css to craft a website showcasing some cool photos.
Could you please assist me in understanding the process of creating comments? For example, when I hit the "leave a comment" button, can a new window pop up (let's say, 200x200px) on the content, giving me the option to choose a smiley face and leave a comment?

I've done some online hunting, and it seems like this involves a form, but do I also need some php files for this?

Knowledgeable folks out there, I'd greatly appreciate your guidance on this!

  •  


dozerin

To achieve the desired functionality, you can utilize HTML, CSS, JavaScript, and potentially server-side scripting languages such as PHP to handle form submissions and data storage.

First, let's address the creation of the popup window for leaving comments. You can use HTML to structure the content of the popup, CSS to style its appearance, and JavaScript to control its behavior.

HTML:
<button id="commentButton">Leave a Comment</button>
<div id="popup" class="popup">
  <span class="close" onclick="closePopup()">&times;</span>
  <h2>Leave a Comment</h2>
  <form id="commentForm">
    <input type="text" placeholder="Your Name">
    <textarea placeholder="Your Comment"></textarea>
    <button type="submit">Submit</button>
  </form>
</div>


CSS:
.popup {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200px;
  height: 200px;
  padding: 20px;
  background: white;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.close {
  position: absolute;
  top: 10px;
  right: 10px;
  cursor: pointer;
}


JavaScript:
dоcument.getElementById('commentButton').addEventListener('click', function() {
  dоcument.getElementById('popup').style.display = 'block';
});

dоcument.getElementById('commentForm').addEventListener('submit', function(event) {
  event.preventDefault(); // Prevent the default form submission
  // Here you can handle the form data using JavaScript or submit it to a server using AJAX
  // For simplicity, we can just close the popup after submission
  closePopup();
});

function closePopup() {
  dоcument.getElementById('popup').style.display = 'none';
}


When a user clicks the "Leave a Comment" button, the JavaScript event listener triggers the display of the popup window. Inside the popup, a form is included for the user to input their name and comment. The JavaScript event listener for the form submission prevents the default behavior and allows you to handle the data using JavaScript or submit it to a server using AJAX.

If you choose to use server-side scripting for data processing and storage, PHP can be used. With PHP, you can capture the form data, perform validation and sanitization, and then store the comments in a database. The PHP script can then respond to the form submission and save the comment data for future display or analysis.

By integrating HTML, CSS, JavaScript, and potentially PHP, you can create a seamless "leave a comment" functionality with a popup window on your website. This approach provides an engaging and interactive way for visitors to share their thoughts and feedback on your photo showcase.
  •  

NaseSookela

It's not as simple as HTML, you'll need a scripting language like php to make it work.

The best approach would be to use a php+mysql combination.


In general, there are multiple approaches. Do you simply have images stored on a server without utilizing a database? In that case, you may need to either redesign it to incorporate a database or create a table with the following fields:
- id: a unique number for each comment
- file: the image path to differentiate between the images
- text: the comment itself

Depending on the requirements, you might also need a field for the date and user.

Alternatively, if the project isn't too large and doesn't anticipate more than a few dozen comments, you might be able to manage without a database. You could create a text file with the same name as the picture, for example, and store the comments there.
  •  

Onemenvinge

Is there a repository accessible? Storing comments in it is definitely more convenient, even though they can also be stored in files. In order to achieve seamless functionality (such as a floating window at the top of the page and saving/showing comments without page reload), a combination of AJAX and PHP is essential.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...