This project involves creating a contact form, saving the data as a CSV file, and displaying the data in a table. It is designed for beginner developers to practice HTML, CSS, and JavaScript concepts. Every intern should be able to complete this project before beginning work on real world projects.
First start by forking this repo so that you can show your work.
- Create an
index.html
file. - Add a
<form>
element with fields for:- Name (text input)
- Email (text input)
- Phone Number (text input)
- A "Submit" button.
- Style the form using CSS for better usability.
Resources:
- Use JavaScript to check if the form fields are valid:
- Ensure no field is empty.
- Validate the email format using a regular expression.
- Check that the phone number contains only digits.
- Show error messages near invalid fields.
Resources:
- Use JavaScript to collect form values on submit.
- Format the data as a CSV string:
- Create a header row:
Name,Email,Phone
. - Append a data row with the form inputs.
- Create a header row:
Resources:
- Use the
Blob
API to create a CSV file from the string. - Trigger a file download using an anchor (
<a>
) element.
Resources:
- Add a
<input type="file">
element to the HTML. - Style it for better visibility.
Resources:
- Use the
FileReader
API to read the uploaded file. - Parse the CSV content into rows and columns (use
split('\\n')
for rows andsplit(',')
for columns).
Resources:
- Create an empty
<table>
element in the HTML. - Use JavaScript to:
- Create rows and cells dynamically based on the CSV data.
- Append the rows to the table.
Resources:
- Use CSS to make the table visually appealing:
- Add borders, padding, and alternating row colors.
Resources:
-
Add Sorting Functionality: Allow users to sort the table by name, email, or phone number. Resources:
-
Enhance the User Experience: Add a "Clear Table" button to remove all rows and reset the table.
- Part 1: A form that collects contact data, validates it, and allows users to download it as a CSV file.
- Part 2: A file upload option that reads the CSV and displays its content in a styled table.