Home arrow ASP arrow Page 4 - Building a WYSIWYG HTML Editor Part 2/2

Building a WYSIWYG HTML Editor Part 2/2

In part one of this two part article we took a look at a simple way to create a fully functional browser-based HTML editor. In this article Mitchell shows us how to put it to good use, creating a database driven news system using the WYSIWYG editor, ASP and SQL Server 2000.

Author Info:
By: Mitchell Harper
Rating: 5 stars5 stars5 stars5 stars5 stars / 105
April 12, 2002
  1. · Building a WYSIWYG HTML Editor Part 2/2
  2. · Creating the database
  3. · Implementing the WYSIWYG HTML editor
  4. · Implementing the WYSIWYG HTML editor (contd.)
  5. · Displaying the news posts
  6. · Conclusion

print this article

Building a WYSIWYG HTML Editor Part 2/2 - Implementing the WYSIWYG HTML editor (contd.)
(Page 4 of 6 )

I've also included the following code at the top of the page:

<!-- #INCLUDE file="db.asp" -->
<% dim objConn dim objRS set objConn = Server.CreateObject("ADODB.Connection") set objRS = Server.CreateObject("ADODB.Recordset")
objConn.Open dbConnString
objRS.ActiveConnection = objConn %>

Our newsposts.asp file now contains all of the fields we need for our news posts: title, author, topic(s) and content. It looks like this:

 Our revamped news form

The <form> element that we added to newsposts.asp looks like this:

<form onSubmit="return ProcessNews()" name="frmNews" action="newsposts.asp" method="post">

As you can see, the action attribute means that all data from the form will be sent back to the same page, newsposts.asp. We need a way to tell whether or not we should display the news form or actually add the news to our SQL Server database, and the hidden form variable action gives us all of the info we need:

<input type="hidden" name="action" value="addNews">

If action is equal to addNews then we add the news to the database. If not, we display the news form…simple. At the top of newsposts.asp, just under the code that connects to our database, we add the following code that separates newsposts.asp into two separate sub-routines:

dim action action = Request.Form("action")
if action = "addNews" then
end if
sub showNewsForm()
 'HTML Code for news form goes below %>
<% end sub
sub addNews()
dim author
dim title
dim topics
dim newsPost
author = Request.Form("author")
title = Replace(Request.Form("title"), "'", "''")
topics = Request.Form("topics")
newsPost = Replace(Request.Form("newsPost"), "'", "''")
objConn.Execute "insert into newsPosts(title,topics,newsPost,authorId) values('" & title & "', '" & topics & "','" & newsPost & "'," & author & ")"
Response.Write "<b>New news post added OK, here's what you added:<br><br></b>" Response.Write Request.Form("newsPost")
set objConn = nothing
end sub

Refresh newsposts.asp and complete the form. You'll notice that if you leave any fields blank or not selected that a dialog box will popup telling you to complete the empty fields. JavaScript isn't the best form of data validation, however we’re already making heavy use of JavaScript for our HTML editor so I thought I would continue with it. In a production environment you would of course implement server side error handling and data validation techniques in the addNews sub-routine. The addNews sub-routine adds our news to the newsPosts table and also shows us a preview of the news once it's been added, like this:

Adding a news posts and previewing it 

In the example above I've copy-pasted directly from socket6.com into the WYSIWYG editor, in fact, I could even copy-paste straight from Microsoft Word if I wanted to!

blog comments powered by Disqus

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials