Tricky Form Problem

B

Bill

I'm building a simple file management application using Classic ASP VBScript that has a
form to input page content, and file name.

After the form is submitted, the application will check to see if a page with that file
name already exists - if the file name already exists the user is quickly notified and
asked to provide a different file name for that page.

What I would like to do is, when the user submits the form, if the file name already
exists, stay on the form page (instead of changing to another page) and just have some
red letters next to the file name say "file name already in use".

Can anyone tell me how to do this???

Thanks,

Bill.
 
B

Bob Barrows [MVP]

Bill said:
I'm building a simple file management application using Classic ASP
VBScript that has a form to input page content, and file name.

After the form is submitted, the application will check to see if a
page with that file name already exists - if the file name already
exists the user is quickly notified and asked to provide a different
file name for that page.

What I would like to do is, when the user submits the form, if the
file name already exists, stay on the form page (instead of changing
to another page) and just have some red letters next to the file name
say "file name already in use".

Can anyone tell me how to do this???

Like this?

<%
dim FileName, msg
FileName=Request.Form("filename")
if len(FileName)> 0 then
if CheckForFile(FileName) then
msg="File name already used"
end if
end if
function CheckForFile(pfilename)
'put your code to check for the file here
'let's simulate it finding the file:
CheckForFile=true
end function
%>
<HTML>
<BODY>

<FORM action="" method=post>
<INPUT id=text1 name=filename value=" <%=filename%>">
<span style="FONT-SIZE: large; COLOR: red"><%=msg%>
</span><br>
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</FORM>

</BODY>
</HTML>
 
B

Bill

Like this?

<%
dim FileName, msg
FileName=Request.Form("filename")
if len(FileName)> 0 then
if CheckForFile(FileName) then
msg="File name already used"
end if
end if
function CheckForFile(pfilename)
'put your code to check for the file here
'let's simulate it finding the file:
CheckForFile=true
end function
%>
<HTML>
<BODY>

<FORM action="" method=post>
<INPUT id=text1 name=filename value=" <%=filename%>">
<span style="FONT-SIZE: large; COLOR: red"><%=msg%>
</span><br>
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</FORM>

</BODY>
</HTML>

Bob, thanks! I believe I can use this, but first, let me understand, your code assumes
that the form submits to itself, right? So, the page refreshes after submission?
 
B

Bob Barrows [MVP]

Bill said:
Bob, thanks! I believe I can use this, but first, let me understand,
your code assumes that the form submits to itself, right? So, the
page refreshes after submission?

Correct. Leaving the action attribute empty causes it to submit to itself
 
D

Daniel Crichton

Bill wrote on Wed, 9 May 2007 12:15:29 -0400:
Bob, thanks! I believe I can use this, but first, let me understand, your
code assumes that the form submits to itself, right? So, the page
refreshes after submission?

Yes, that's the way to do it without using something like AJAX. It's simple
to code, and all work is done server side.

Dan
 
A

Adrienne Boswell

Gazing into my crystal ball I observed "Bob Barrows [MVP]" <reb01501
@NOyahoo.SPAMcom> writing in
<FORM action="" method=post>
<INPUT id=text1 name=filename value=" <%=filename%>">
<span style="FONT-SIZE: large; COLOR: red"><%=msg%>
</span><br>
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</FORM>

Better because it gives the user other visual clues - you would want to
use Strong because it should give an audible indication to a speaking
browser:
<% if len(FileName)> 0 then
if CheckForFile(FileName) then
message="File name already used"
required = "text1"
end if
end if
if message <> "" then
message = "<div class='message'><strong>" & message & "</strong>
</div>"
"<script type='text/javascript'>alert " & message & ";</script>"
end if
%>
<style type="text/css">
..message {color:red; background-color:transparent; font-weight:bold;}
<% if required <> "" then%>
#<%=required%>1 {background-color:yellow; color:#000}
#<%=required%> {background-color:pink; color:#000}
<% end if%>
</style>
</head>
<body>
<form method="post" action="">
<%=message%>
<label for="text1" id="text11">Text</label>
<input type="text" name="text1" id="text1" value="<%=filename%>">
<input type="submit" value="Submit">
</form>
</body>
 
B

Bill

...
:
Yes, that's the way to do it without using something like AJAX. It's simple
to code, and all work is done server side.

Dan

Ah, your comment led me to find XMLHttpRequest!

A bit of JavaScript, and I'll teach myself how to do this with XMLHttpRequest - seems a
good function to add to my toolbox.

Thanks all,

Bill.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,101
Messages
2,570,637
Members
47,243
Latest member
RustyPalin

Latest Threads

Top