HTML Form processing script

Thanks again guys.

I got it working this morning. Just added file://<server name> to my trusted sites, even though local should bypass the ActiveX settings (based on my understanding). It wouldn't work until I added that to the list of trusted sites. Weird. I'd mocked up a chocolate chip cookie questionnaire since my director loves them and it dumps very nicely.

Now to learn CSS so I can put the department logo in and generally make it more visually appealing than plain HTML.
 
After speaking with the director again, she really just wants a simple text field (textarea form field) by which people can type in their anonymous feedback. But the textarea type of input doesn't have a maxlength variable and she did mention wanted to limit the # of characters people can use so they don't end up venting with page after page. I've found a link to a javascript that would limit the text someone can type, but I have no idea how to integrate it with the <script> are Diplo's VB script is using. Could I expand the script area and start a new section with language="javascript" and have that work?

And of course if someone knows a better way to limit the textarea, please let me know.
 
In that case, forget about html and just write a simple program. Pick any language of your choice, and we'll help you with the code. In Delphi, I would add a Rich edit to a form, let the user do it's stuff, and on exit:

Code:
const MaxText = 1000;

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  Path: string;
  s: string;
begin
  RichEdit1.PlainText := True;
  if Length(RichEdit1.Lines.Text) > MaxText then
  begin
    Application.MessageBox(PAnsiChar('Your text is too long!'), PAnsiChar('Anonymous form'));
  end
  else
  begin
    Path := ExtractFilePath(ParamStr(0));
    for i := 0 to 99999999 do
    begin
      s := IntToStr(i);
      while Length(s) < 8 do
      begin
        s := '0' + s;
      end;
      s := Path + s + '.txt';
      if not FileExists(s) then
      begin
        RichEdit1.Lines.SaveToFile(s);
        Break;
      end;
    end;
    Application.Terminate;
  end;
end;

Like this.
 
I've modified the script so that it will check the length of a textarea called "feedback" and will alert the user if the number of characters entered is over a pre-defined limit. You can edit the constant variable MaxCharacters to say how many these are.

I've attached the script as a text file to preserve formatting (just rename extension to .html)
 

Attachments

  • feedback.txt
    1.4 KB · Views: 9
Awesome, Diplo, it works great. I changed it to 500 characters, which is roughly 100 words. Though I have to admit, looking at this new script and your original one I'm confused over the differences between the two, such as the first's sub submitform compared to the new one's Function myForm_OnSubmit and its retval lines.
 
Yeah, VBScript can be confusing as there are mores ways than one to skin a cat, so to speak... So I can understand why you are confused. I'll try and explain:

The original script called a VBScript subroutine when the submit button was clicked (a subroutine is basically a function that doesn't return a value back). This was fine if you didn't want to do validation that stopped the form being submitted upon a certain condition arising. However, as soon as you want to perform validation where an invalid result means the form is not submitted, then you need to do two things:

First, you need to call the function when the form is submitted, and not when the submit button is clicked. There is a very subtle difference. The main difference is that you can stop the form being submitted using the former method, but not the latter. It is essential to stop the form being submitted upon an error otherwise whatever the user has typed in is lost when the error occurs (which would be annoying!). VBScript has a shorthand way of associating a function with the id of an element in the HTML - so because the form is called myForm then you can automatically call the function myForm_OnSubmit when the form is submitted.

Second, you need to have a way of returning either true or false from the OnSubmit function. If the function returns true then the form is submitted but if it returns false then it halts where it is. This is the key reason. So by default I set the variable retVal = False and only if the form passes validation do I set it to true (success). The value of retVal is then passed back from the function and the browser either submits the form or stops depending on whether it equals true (fine) or false (problem).

Hope that makes some sense :)
 
Last edited by a moderator:
Haven't had much time yesterday or today to work on this, but here's where I'm currently at with learning CSS. I've still got to put the organization's logo (a small jpg file) into the top of the left menu, with text beneath that. I'm also getting an ActiveX pop-up ("a control on this page might be unsafe to interact with other parts of the page, blah blah") that I've made a small image file of to put toward the bottom of the right-hand menu, followed by text explaining to users to just click Yes when they see this. The middle blue will have more text, whatever the director would like to say beneath the title page. I'll have to learn padding for the text within those two menus, and I'm horrible with colors (such as the white title on the blue background not being/looking the best).

Code:
<html>
<head>
<title>SMSG Feedback Form</title>
<style>
html, body {
background-color: #0000ff;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
font-size; 0,10em}
p {font-family: garamond; 
font-size: 24pt; 
text-align: center;
color: #ffffff;}
p.2 {font-family: verdana; 
font-size: 12pt;
color: #ffffff;}
#menu {
float: left;
height: 100%;
width: 190px;
background-color: #f0f0f0;
padding: 3px; border: 1px solid black;}
#menu2 {
float: right;
height: 100%;
width: 190px;
background-color: #f0f0f0;
padding: 3px; border: 1px solid black;}
</style>
</head>
<body>
<script language="VBScript">
Function myForm_OnSubmit
Dim item, strFilePath
Dim objFSO, myFile
Dim TheForm
Dim retVal
Const ForAppending = 8
Const MaxCharacters = 500
Set TheForm = Document.forms("myform")
retVal = False
 
If Len(TheForm.feedback.value) > MaxCharacters Then
MsgBox "Your feedback is too long. Please enter a maximum of 500 characters."
Else
strFilePath = "[url="file://\\server\Feedback.txt"]\\server\Feedback.txt[/url]"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If NOT objFSO.FileExists(strFilePath) Then
objFSO.CreateTextFile(strFilePath)
End If
Set myFile = objFSO.OpenTextFile (strFilePath, ForAppending, True)
myFile.WriteLine("Form submitted at " & now())
For Each item In TheForm
If item.name <> "submitter" Then
	myFile.WriteLine(item.name & " : " & item.value)
End If
Next
myFile.WriteLine(vbNewLine)
myFile.Close
Set myFile = Nothing
Set objFSO = Nothing
MsgBox "Thank you for submitting feedback."
retVal = True
End If
 
myForm_OnSubmit = retVal
End Function
</script>
 
<div id="menu">
</div>
<div id="menu2">
</div>
<p>Simulator Systems Group's<br>Anonymous Feedback Form</p>
<form id="myform" method="post" onsubmit="SubmitForm()">
<p><center><textarea rows="9" cols="50" name="Feedback"></textarea><br>
<p class="2">Feedback is limited to 500 characters in length.</p>
<p><input name="submitter" type="reset" value="Reset the Form">
<p><input name="submitter" type="submit" value="Submit Feedback"></center>
</form>
 
</body>
</html>

Comments, hopefully positive/constructive, are welcome. :p
 
Last edited by a moderator:
Here's a little feedback...

Nice work, John! Design is a personal issue so I won't comment so much on the design as the implementation and how it could be improved in terms of efficiency and validity.

So, here's how I would have done the same design (I've removed VBScript for clarity):
Code:
<html>
<head>
<title>SMSG Feedback Form</title>
<style type="text/css">
body
{
	background-color: #0000ff;
	margin: 0;
	padding: 0;
	color:white;
	font-family: verdana, sans-serif;
}

h1
{
	font-family: garamond, sans-serif;
	font-size: 24pt;
	text-align: center;
}

#menu, #menu2
{
	height: 100%;
	width: 190px;
	background-color: #f0f0f0;
	padding: 3px;
	border: 1px solid black;
}

#menu
{
	float: left;
}

#menu2
{
	float: right;
}

form
{
	text-align:center;
}

</style>

</head>
<body>

<div id="menu">&nbsp;</div>
<div id="menu2">&nbsp;</div>
<h1>Simulator Systems Group's<br>Anonymous Feedback Form</h1>

<form id="myform" method="post" onsubmit="SubmitForm()">
	<p><textarea rows="9" cols="50" name="Feedback"></textarea></p>
	<p>Feedback is limited to 500 characters in length.</p>
	<p><input name="submitter" type="submit" value="Submit Feedback"></p>
	<p><input name="submitter" type="reset" value="Reset the Form"></p>
</form>

</body>
</html>

I'll explain my changes as best I can so you can understand my reasoning:

First, it's quicker to use padding:0 than to use padding:0px 0px 0px 0px - they both do the same thing. If you specifiy just one parameter then it assumes the same value for all four sides of the box. There's also no need to specify a unit (px, em) for 0 because it's redundant, if you think about it!

Second, always have a default font-family and colour for your body (no need to do HTML as body is content element). Always fall back on a generic font, too. So instead of just having font-family:veradana have font-family:verdana, sans-serif. The reason is that if a user doesn't have verdana font installed they will have sans-serif (as it's a generic font included with ever css compatible browser).

Third, you can compact your left and right #menu ids to share the same core attributes like I have done. Then you just specificy that one floats left and the other right. That way you need only edit the core attributes once and they will both share them.

Fourth, it's not valid in HTML to have empty containers, so use a non-breaking space (&nbsp;) to put between empty tags, such as your two divs.

Fifth, always remember to close paragraph tags. Whilst not strictly essential in HTML it's a good habit to get into if you move to XHTML.

Sixth, don't use the <CENTER> tag as it's deprecated. Try and do all styling via CSS. See how I've done same by adding text-align:center style to the container FORM tag.

Seventh, I think it's preferable to put Submit button before Reset button as that should be default choice for most situations.

Eigth, it's a good habit to indent all code, HTML, CSS as it makes it more readable (though most programmers are guilty of not doing this!). I personally prefer to align brackets too.

Anyway, good job, John and hope my feedback proves useful :)
 
Thanks Diplo.

Now I just need to figure out why the VB script works on my machine and no one else's, despite the fact that all IE settings are user GPO driven. :cool:
 
John Reynolds said:
Now I just need to figure out why the VB script works on my machine and no one else's, despite the fact that all IE settings are user GPO driven. :cool:

Hey, John, it helps if you type the server's name correctly when pushing the GPO out. The things you catch when you walk away from a problem and recoup a little.
 
Diplo,

Wondering if you might know how to make a textarea form block transparent so that a watermark would show within the block?
Code:
<html>
<head>
<title>SMSG Feedback Form</title>
<style>
html, body {background-image: url(logo.jpg);
background-repeat: no-repeat;
background-position: center 20px;
background-color: #f0f0f0;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
font-size; 0,10em}
p {font-family: "times new roman";
font-size: 11pt;
color: #0000ff;
text-align: center;}
p.1 {font-family: garamond; 
font-size: 20pt; 
text-align: center;
color: #0000ff;
font-weight: bolder;
margin: 25px;
text-align: center;}
p.2 {font-family: "times new roman"; 
font-size: 11pt;
color: #0000ff;
font-style: oblique;}
p.3 {font-family: "times new roman";
font-size: 11pt;
color: #0000ff;
text-align: center;
margin: 55px 0px 5px 10px;}
#menu {float: left;
height: 100%;
width: 200px;
background-color: #0000ff;
padding: 2px;
border-right: 1px solid black;}
#menu2 {float: right;
height: 100%;
width: 200px;
background-color: #0000ff;
padding: 2px;
border-left: 1px solid black;}
</style>
</head>
<body>
<script language="VBScript">
Function myForm_OnSubmit
Dim item, strFilePath
Dim objFSO, myFile
Dim TheForm
Dim retVal
Const ForAppending = 8
Const MaxCharacters = 500
Set TheForm = Document.forms("myform")
retVal = False
 
If Len(TheForm.feedback.value) > MaxCharacters Then
MsgBox "Your feedback is too long. Please enter a maximum of 500 characters."
Else
strFilePath = "[url="file://\\server\Feedback.txt"]\\server\Feedback.txt[/url]"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If NOT objFSO.FileExists(strFilePath) Then
objFSO.CreateTextFile(strFilePath)
End If
Set myFile = objFSO.OpenTextFile (strFilePath, ForAppending, True)
myFile.WriteLine("Form submitted at " & now())
For Each item In TheForm
If item.name <> "submitter" Then
	myFile.WriteLine(item.name & " : " & item.value)
End If
Next
myFile.WriteLine(vbNewLine)
myFile.Close
Set myFile = Nothing
Set objFSO = Nothing
MsgBox "Thank you for submitting feedback."
retVal = True
End If
 
myForm_OnSubmit = retVal
End Function
</script>
<div id="menu"></div>
<div id="menu2"></div>
<p class="1">Simulator Systems Group's<br>Anonymous Feedback Form</p>
<form id="myform" method="post" onsubmit="SubmitForm()">
<p><center><textarea rows="9" cols="50" name="Feedback"></textarea><br>
<p class="2">- Feedback is limited to 500 characters in length. -</p>
<p><input name="submitter" type="submit" value="Submit Feedback"></p>
<p><input name="submitter" type="reset" value="Reset the Form"></p>
</form>
<p class="3">After clicking on the "Submit Feedback" button,<br>you will see this window.</p>
<center><img src="error.jpg"></center>
<p>Choose "Yes" to finish submitting your feedback.</p>
</body>
</html>

Yes, it's a bit out of control right now. :p

I've attached the watermark file so you can see what I'm trying to do. I'm also designing around a 1024x768 viewing (don't ask, it's an AF thing). If you know how to make the watermark show through that textarea block, I'll be indebted (again).
 

Attachments

  • logo.jpg
    logo.jpg
    14.6 KB · Views: 21
Last edited by a moderator:
Hi John,

Just add the following to your CSS:
Code:
 textarea
 {
 	background-color:transparent;
 }

That should do the trick :)
 
OK, here's another one. I've got the blue menu along the left (dropped it along the right-hand side and widened the one on the left) and everything within the rest of the page centers all nicely (within the rest of the page outside the menu rather than the entire page). How do I get the watermark to likewise center? As it is, it's centering across the entire page rather than directly behind the textarea block, the buttons, and the the rest of the text.
 
Not exactly sure what you are trying to do, but if I guess right then try this:
Code:
.....
<div id="menu"></div>
<div id="menu2"></div>
<div id="watermark">
<p class="1">Simulator Systems Group's<br>Anonymous Feedback Form</p>
<form id="myform" method="post" onsubmit="SubmitForm()">
  <p><center><textarea rows="9" cols="50" name="Feedback"></textarea><br>
  <p class="2">- Feedback is limited to 500 characters in length. -</p>
  <p><input name="submitter" type="submit" value="Submit Feedback"></p>
  <p><input name="submitter" type="reset" value="Reset the Form"></p>
</form>
<p class="3">After clicking on the "Submit Feedback" button,<br>you will see this window.</p>
<center><img src="error.jpg"></center>
<p>Choose "Yes" to finish submitting your feedback.</p>
</div>
</body>
</html>
And in the CSS add:
Code:
#watermark
{
background-image: url(logo.jpg);
  background-repeat: no-repeat;
  background-position: center 20px;
}
(And remove the corresponding background image from the body part of the CSS).

I've basicalluy create a container DIV that holds the background image.
 
Thanks for the response, but that doesn't center it. It's the same result as what I had in the html, body section of the CSS code. Let me try to explain better.

I have the blue menu along the left that's 200px wide. My textarea block, the button, the logo of SMSG Anonymous Feedback Form, etc., are all centered within the remaining grey area, not centered from the perspective of the entire page. So when looking at this those items I listed above are slight offset to the right since the 200px-wide menu is pushing them over from the exact center of my screen. I want the watermark to likewise be centered in such a way so that it's right behind these items. Hope this makes sense.
 
Ahh, OK, I think I understand what you mean now - you only have one blue border on the left? OK, this should do it (I'll post entire code minus VB so you can see):
Code:
<html>
<head>
<title>SMSG Feedback Form</title>
<style>
html, body {
  background-color: #f0f0f0;
  margin: 0px 0px 0px 0px;
  padding: 0px 0px 0px 0px;
  font-size; 0,10em}
p {font-family: "times new roman";
  font-size: 11pt;
  color: #0000ff;
  text-align: center;}
p.1 {font-family: garamond;
  font-size: 20pt;
  text-align: center;
  color: #0000ff;
  font-weight: bolder;
  margin: 25px;
  text-align: center;

  }
p.2 {font-family: "times new roman";
  font-size: 11pt;
  color: #0000ff;
  font-style: oblique;}
p.3 {font-family: "times new roman";
  font-size: 11pt;
  color: #0000ff;
  text-align: center;
  margin: 55px 0px 5px 10px;}
#menu {float: left;
  height: 100%;
  width: 200px;
  background-color: #0000ff;
  padding: 2px;
  border-right: 1px solid black;}
#menu2 {float: right;
  height: 100%;
  width: 200px;
  background-color: #0000ff;
  padding: 2px;
  border-left: 1px solid black;}

#watermark
{
  background-image: url(logo.jpg);
  background-repeat: no-repeat;
  background-position: center 20px;
  margin-left:200px;
}

 textarea
 {
 	background-color:transparent;
 }

</style>
</head>
<body>
<div id="menu">&nbsp;</div>
<div id="watermark">
<p class="1">Simulator Systems Group's<br>Anonymous Feedback Form</p>
<form id="myform" method="post" onsubmit="SubmitForm()">
  <p><center><textarea rows="9" cols="50" name="Feedback"></textarea><br>
  <p class="2">- Feedback is limited to 500 characters in length. -</p>
  <p><input name="submitter" type="submit" value="Submit Feedback"></p>
  <p><input name="submitter" type="reset" value="Reset the Form"></p>
</form>
<p class="3">After clicking on the "Submit Feedback" button,<br>you will see this window.</p>
<center><img src="error.jpg"></center>
<p>Choose "Yes" to finish submitting your feedback.</p>
</div>
</body>
</html>

Just make the margin-left: attribute of the #watermark match the width of the left-hand blue border.
 
Diplo said:
Ahh, OK, I think I understand what you mean now - you only have one blue border on the left? OK, this should do it (I'll post entire code minus VB so you can see):

Just make the margin-left: attribute of the #watermark match the width of the left-hand blue border.

God damnit, that's too easy. I need to read this CSS book I have instead of haphazardly hacking away at it like this. But thanks again.
 
Back
Top