flynny
asked on
ASP Form validation help
hi can anyone help me with asp form validation ( i'm new to this). i have a asp form page which a user will populate and then click the add form which moves to the validation page the code for this is attached, however all i get is a http 500 error can anyone tel me whats going wrong
regards the types, i want a product to have a number of (potentially) differnt types (same with flavours). so i have a list box with all the available types and a second ;ist box with will contain all the types or flavours associated with that product which the user will add to this list. i want to loop through and get all the values held in this second listbox.
( i know i dont actually add to the database yet i know how to do this i just want to test i'm getting all the variable first.)
any ideas?
matt.
regards the types, i want a product to have a number of (potentially) differnt types (same with flavours). so i have a list box with all the available types and a second ;ist box with will contain all the types or flavours associated with that product which the user will add to this list. i want to loop through and get all the values held in this second listbox.
( i know i dont actually add to the database yet i know how to do this i just want to test i'm getting all the variable first.)
any ideas?
matt.
<%@LANGUAGE="VBSCRIPT"%>
<%Option Explicit%>
<!--#include file="../../Connections/connection.asp" -->
<!-- #include file="upload.asp" -->
<html>
<head>
<%
' *** Restrict Access To Page: Grant or deny access to this page **********
MM_authorizedUsers="1"
MM_authFailedURL="../admin_access_denied.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
(InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
MM_referrer = Request.ServerVariables("URL")
if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
Response.Redirect(MM_authFailedURL)
End If
%>
<%
'now build up insert string
Dim supplier = Request.Form("supplier")
Alert(supplier)
Dim name = Request.Form("name")
Dim prod_types() As String
ReDim prod_types(5)
For i = 1 To Request.Form( "selected_prod_type" ).Count
if(i > UBound(prod_types) then
ReDim preserve prod_types(i+3)
end if
prod_types(i) = Request.Form("selected_prod_type" )( i )
Next
Dim size = Request.Form("size")
Dim brief_des = Request.Form("Brief_des")
Dim full_des = Request.Form("full_des")
Dim label_info = Request.Form("label_info")
Dim directions = Request.Form("directions")
Dim rrp = Request.Form("rrp")
Dim price = Request.Form("price")
Dim flavours() As String
ReDim flavours(5)
For i = 1 To Request.Form( "selected_flavours" ).Count
if(i > UBound(flavours) then
ReDim preserve flavours(i+3)
end if
flavours(i) = Request.Form("selected_flavours" )( i )
Next
Dim Uploader, File
Set Uploader = New FileUploader
' This starts the upload process
Uploader.Upload()
If Uploader.Files.Count <> 0 Then
File(0).SaveToDisk "..\..\images\thumbs\"
Dim thumbpath = "..\..\images\thumbs\" + File.FileName
File(1).SaveToDisk "..\..\images\images\"
Dim thumbpath = "..\..\images\images\" + File.FileName
End if
%>
</head>
</html>
Trying removing this line:
Alert(supplier)
There is no Sub called Alert in the code, and if you are wanting a javascript alert this cannot be contained inside an ASP block.
Alert(supplier)
There is no Sub called Alert in the code, and if you are wanting a javascript alert this cannot be contained inside an ASP block.
ASKER
hi,
ok, i've removed this and still get the same error?
ok, i've removed this and still get the same error?
Ensure that the ASP windows account has write permission on the directores it is saving to.
First off, make sure you turn off friendly error messages as found here:
http://www.webwizguide.com/kb/asp_knowledgebase/friendly_HTTP_error_messages.asp
Then load your page again. The error should now be more verbose. Let us know that error and any other important tid bits.
TIA
http://www.webwizguide.com/kb/asp_knowledgebase/friendly_HTTP_error_messages.asp
Then load your page again. The error should now be more verbose. Let us know that error and any other important tid bits.
TIA
ASKER
great thanks L00M, thats a big help. at least now i get more meaningful errors!!
ok, i get this now am i declaring the variables wrong?
Microsoft VBScript compilation error '800a0401'
Expected end of statement
Dim supplier = Request.Form("supplier")
-------------^
i've tried Dim supplier As String but this doesnt work either.
ok, i get this now am i declaring the variables wrong?
Microsoft VBScript compilation error '800a0401'
Expected end of statement
Dim supplier = Request.Form("supplier")
-------------^
i've tried Dim supplier As String but this doesnt work either.
ASKER
just to not having simply
supplier = Request.Form("supplier")
is ok. but if this is right then how will i delcare my array
Dim prodTypes() As String
many thanks for the help in advance!!
supplier = Request.Form("supplier")
is ok. but if this is right then how will i delcare my array
Dim prodTypes() As String
many thanks for the help in advance!!
It should be
Dim supplier
supplier = Request.Form("supplier")
The method you tried is for ASP.NET
ASP array functions:
http://www.codefixer.com/tutorials/array_functions.asp
Dim supplier
supplier = Request.Form("supplier")
The method you tried is for ASP.NET
ASP array functions:
http://www.codefixer.com/tutorials/array_functions.asp
As Rouchie showed, only use:
Dim supplier
In classic ASP, all variables are varient
Dim supplier
In classic ASP, all variables are varient
ASKER
ok great, thanks i'm getting further now ;)
ok i get the following
Request object error 'ASP 0206 : 80004005'
Cannot call BinaryRead
Cannot call BinaryRead after using Request.Form collection.
at the following line
prod_types(i) = Request.Form("selected_pro d_type" )( i )
basically i want to pull all the element from the list box "selected_prod_type" on the add page.
ok i get the following
Request object error 'ASP 0206 : 80004005'
Cannot call BinaryRead
Cannot call BinaryRead after using Request.Form collection.
at the following line
prod_types(i) = Request.Form("selected_pro
basically i want to pull all the element from the list box "selected_prod_type" on the add page.
Do you have BinaryRead anywhere in your code? Perhaps just before or after that line?
ASKER
no i assume the binary read is the (i) after the Request. the whole code is as follows.
Dim prod_types()
ReDim prod_types(5)
For i = 1 To Request.Form( "selected_prod_type" ).Count
if(i > UBound(prod_types)) then
ReDim preserve prod_types(i+3)
end if
prod_types(i) = Request.form("selected_pro d_type" )( i )
Next
Dim prod_types()
ReDim prod_types(5)
For i = 1 To Request.Form( "selected_prod_type" ).Count
if(i > UBound(prod_types)) then
ReDim preserve prod_types(i+3)
end if
prod_types(i) = Request.form("selected_pro
Next
ASKER
if this helps the form on the add page is created as follows
<form action="validateProduct.as p" method="POST" name="add_form" id="add_form" enctype="multipart/form-da ta">
<form action="validateProduct.as
I believe this answers the error you are getting.
http:/Q_20869066.html
You need to collect the posted items in the Uploader object, then refer to them through that instead of request.form
http:/Q_20869066.html
You need to collect the posted items in the Uploader object, then refer to them through that instead of request.form
ASKER
great thanks Rouchie thats helped alot almost there now.
i get the following
Object required: '[string: ""]'
for the line
For i = 1 To Uploader.Form( "selected_prod_type" ).Count
is this because the form will only pass the selected entry in the list box. i want to get hold of all the objects in the list box. is this possible?
i get the following
Object required: '[string: ""]'
for the line
For i = 1 To Uploader.Form( "selected_prod_type" ).Count
is this because the form will only pass the selected entry in the list box. i want to get hold of all the objects in the list box. is this possible?
>> is this because the form will only pass the selected entry in the list box
Yes, I think so. Is .Count an actual method of Upload.Form ? I know Count is used in ASP.NET.
You might have to check that Uploader.Form( "selected_prod_type" ) is not nothing before you do this...
If Uploader.Form( "selected_prod_type" ) <> "" then
For i = 1 To Uploader.Form( "selected_prod_type" ).Count
......
......
End If
Or alternatively create an array then use that to loop and count:
Dim prodArray()
prodArray = Split(Uploader.Form( "selected_prod_type" ), ",")
Dim i
For i = 0 to UBound(prodArray)
.....
.....
Next
Yes, I think so. Is .Count an actual method of Upload.Form ? I know Count is used in ASP.NET.
You might have to check that Uploader.Form( "selected_prod_type" ) is not nothing before you do this...
If Uploader.Form( "selected_prod_type" ) <> "" then
For i = 1 To Uploader.Form( "selected_prod_type" ).Count
......
......
End If
Or alternatively create an array then use that to loop and count:
Dim prodArray()
prodArray = Split(Uploader.Form( "selected_prod_type" ), ",")
Dim i
For i = 0 to UBound(prodArray)
.....
.....
Next
ASKER
hi i've tried both method and its appear to only send the highlighted value through ( added a few type and then highlighted one to test this using a response.write). i can't find much information on uploader.form and doing this. is there any other way you can think of for getting this information?
>> its appear to only send the highlighted value throug
I would have thought this was the correct behaviour? Surely you only need to know what values the user has chosen?
Within your form, do you allow theuser to select multiple values in each list?
I would have thought this was the correct behaviour? Surely you only need to know what values the user has chosen?
Within your form, do you allow theuser to select multiple values in each list?
ASKER
sorry i didn't exlpain it properly. Basically i have two listboxes. the first contains the list of all available product types which i pulled from the db.
the second list box initially is empty and this will contains all the type associated with that product.
i then have an add and remove button which moves the entries betweent eh two. i.e. the user highlights say toys and clicks add toys will be removed from the list of all product types an added to the second list box, with remove doing the reverse.
then when the user clicks the add record button i would like to get hold of all these entrys the users has added to the second list box. does this sound visable?
matt.
the second list box initially is empty and this will contains all the type associated with that product.
i then have an add and remove button which moves the entries betweent eh two. i.e. the user highlights say toys and clicks add toys will be removed from the list of all product types an added to the second list box, with remove doing the reverse.
then when the user clicks the add record button i would like to get hold of all these entrys the users has added to the second list box. does this sound visable?
matt.
Yes. There are 2 ways to achieve it. The first would be the ASP solution and would require 2 hits to the database (1 for each list). First get all the product types as you are doing, then the second gets all the product types currently assigned to the product.
A further 2 pages would be needed to add/remove entries from each box. Its a tedious process in classic ASP because you've got to keep hitting the database.
Alternatively, use javascript to copy the list items then save the list box in its populated state.
Here is a page that does what I'm thinking: http://javascript.internet.com/forms/items-popup-list.html
A further 2 pages would be needed to add/remove entries from each box. Its a tedious process in classic ASP because you've got to keep hitting the database.
Alternatively, use javascript to copy the list items then save the list box in its populated state.
Here is a page that does what I'm thinking: http://javascript.internet.com/forms/items-popup-list.html
ASKER
hi rouchie thanks for the reply. sorry about the delay in replying.
the javascript version is the way i'm trying to tackle it. the boxes are working fine (i can post the code if you think it'll help) its just passing the data from the form to the validation asp page that i can't do.
so the user has selected all the types they want and moved them into the second list box. (however only the last entry is highlighted.) they then click ok which will move submit the form to validate.asp and i need to get hold of all the entries from the second table here.
the javascript version is the way i'm trying to tackle it. the boxes are working fine (i can post the code if you think it'll help) its just passing the data from the form to the validation asp page that i can't do.
so the user has selected all the types they want and moved them into the second list box. (however only the last entry is highlighted.) they then click ok which will move submit the form to validate.asp and i need to get hold of all the entries from the second table here.
If you can post a link to a working example it might be better, or alternatively do a screen grab and highlight what's not working.
Double check that the ASP code that creates the lists (and the javascript too) is creating each list item with a text value (that the user see's), and an ID value (that's stored in HTML in the background).
Then when you do a request.form in the validation page, you should see the ID values in a long string, i.e. "3,46,73,67,78,234"
Double check that the ASP code that creates the lists (and the javascript too) is creating each list item with a text value (that the user see's), and an ID value (that's stored in HTML in the background).
Then when you do a request.form in the validation page, you should see the ID values in a long string, i.e. "3,46,73,67,78,234"
ASKER
hi Rouchie,
sorry for the delay in replying. ok i've had a look at this like you said. this is what i have
<script language="javascript">
function addOption_all_list(source, dest){
for(i=source.options.lengt h-1;i>=0;i --)
{
addOption(dest,source.opti ons[i].tex t,source.o ptions[i]. value);
removeOption(source,i);
}
}
function addOption(selectbox,text,v alue )
{
var optn = document.createElement("OP TION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn );
}
function removeOption(listbox,i)
{
listbox.remove(i);
}
function addOption_list(source,dest )
{
for(i=source.options.lengt h-1;i>=0;i --)
{
if(source.options[i].selec ted)
{
addOption(dest, source.options[i].text, source.options[i].value);
removeOption(source,i);
}
}
}
function removeAllOptions(selectbox )
{
var i;
for(i=selectbox.options.le ngth-1;i>= 0;i--)
{
//selectbox.options.remove (i);
selectbox.remove(i);
}
}
</script>
in the form i create the list like so
<select name="prod_type" size="8" id="prod_type">
<%
Set oRs=Server.CreateObject("a dodb.recor dset")
strSQL = "SELECT * FROM type ORDER BY type.type"
oRs.Open strSQL, conn
selected = false
While (NOT oRs.EOF)
if(selected=false) then
response.write "<OPTION value=" & oRs.Fields.Item("typeid"). Value & "SELECTED>" & oRs.Fields.Item("type").Va lue & "</OPTION>"
selected=true
else
response.write "<OPTION value=" & oRs.Fields.Item("typeid"). Value & ">" & oRs.Fields.Item("type").Va lue & "</OPTION>"
end if
oRs.MoveNext()
Wend
%>
</select>
<input onclick="addOption_all_lis t(prod_typ e,selected _prod_type )" ;="" value="Add All" type="button">
<input onclick="addOption_list(pr od_type,se lected_pro d_type)" ;="" value="Add >" type="button">
<input onclick="addOption_list(se lected_pro d_type,pro d_type)" ;="" value="Remove >" type="button">
<input onclick="addOption_all_lis t(selected _prod_type ,prod_type )" ;="" value="Remove All >" type="button">
<select name="selected_prod_type" size="8" id="selected_prod_type">
</select>
it just seems to be sending across the highlighted values. (if one is highlighted in the second table.)
any ideas?
thanks again for the help.
sorry for the delay in replying. ok i've had a look at this like you said. this is what i have
<script language="javascript">
function addOption_all_list(source,
for(i=source.options.lengt
{
addOption(dest,source.opti
removeOption(source,i);
}
}
function addOption(selectbox,text,v
{
var optn = document.createElement("OP
optn.text = text;
optn.value = value;
selectbox.options.add(optn
}
function removeOption(listbox,i)
{
listbox.remove(i);
}
function addOption_list(source,dest
{
for(i=source.options.lengt
{
if(source.options[i].selec
{
addOption(dest, source.options[i].text, source.options[i].value);
removeOption(source,i);
}
}
}
function removeAllOptions(selectbox
{
var i;
for(i=selectbox.options.le
{
//selectbox.options.remove
selectbox.remove(i);
}
}
</script>
in the form i create the list like so
<select name="prod_type" size="8" id="prod_type">
<%
Set oRs=Server.CreateObject("a
strSQL = "SELECT * FROM type ORDER BY type.type"
oRs.Open strSQL, conn
selected = false
While (NOT oRs.EOF)
if(selected=false) then
response.write "<OPTION value=" & oRs.Fields.Item("typeid").
selected=true
else
response.write "<OPTION value=" & oRs.Fields.Item("typeid").
end if
oRs.MoveNext()
Wend
%>
</select>
<input onclick="addOption_all_lis
<input onclick="addOption_list(pr
<input onclick="addOption_list(se
<input onclick="addOption_all_lis
<select name="selected_prod_type" size="8" id="selected_prod_type">
</select>
it just seems to be sending across the highlighted values. (if one is highlighted in the second table.)
any ideas?
thanks again for the help.
ASKER
hi guys just an idea but would i be able to pass an array of hidden fields across
ASKER
alternatively would i be able to create a single hidden field and populate this on the submit click?
so when the form has been filled in and the submit button clicked it call a method which would go through the values and append then together using join to make a long string which coul dbe split on the validation page
e.g type1,type2,..,..., etc.
if not then i could append to the string when the add button is clicked in the java method, however if it was subsequently removed then how would i remove it from the string?
so when the form has been filled in and the submit button clicked it call a method which would go through the values and append then together using join to make a long string which coul dbe split on the validation page
e.g type1,type2,..,..., etc.
if not then i could append to the string when the add button is clicked in the java method, however if it was subsequently removed then how would i remove it from the string?
>> alternatively would i be able to create a single hidden field and populate this on the submit click?
Yes, this is the approach to use. I don't actually know the javascript to loop through the fields and print their values to a text box, but this would work for sure.
>> f not then i could append to the string when the add button is clicked in the java method, however if it was subsequently removed then how would i remove it from the string?
You get around this problem by only copying the values when the submit button is pressed, not the Add/Remove buttons. The Add/Remove buttons can *appear* to copy the values as far as the user is concerned, but in actual fact the submit button would loop through the copied values and populate the hidden field when the form was submitted.
Yes, this is the approach to use. I don't actually know the javascript to loop through the fields and print their values to a text box, but this would work for sure.
>> f not then i could append to the string when the add button is clicked in the java method, however if it was subsequently removed then how would i remove it from the string?
You get around this problem by only copying the values when the submit button is pressed, not the Add/Remove buttons. The Add/Remove buttons can *appear* to copy the values as far as the user is concerned, but in actual fact the submit button would loop through the copied values and populate the hidden field when the form was submitted.
ASKER
hi rouchie thanks for the reply.
the first approach would be brilliant.
just to outline (sorry, i'm new to asp) it would i have to call the javascript function on the page when the submit button is clicked and then move to the validate page?
matt.
the first approach would be brilliant.
just to outline (sorry, i'm new to asp) it would i have to call the javascript function on the page when the submit button is clicked and then move to the validate page?
matt.
Yes that's right. Let the user do all the Add/Remove actions so the destination list gets populated on their screen. When they've finished and press Submit, get the javascript to execute and populate the hidden field BEFORE the form actually posts.
You can add an onsubmit event to the <form> tag which runs the script prior to it being submitted:
http://www.w3schools.com/jsref/jsref_onsubmit.asp
http://www.devguru.com/Technologies/ecmaScript/quickref/evhan_onsubmit.html
You can add an onsubmit event to the <form> tag which runs the script prior to it being submitted:
http://www.w3schools.com/jsref/jsref_onsubmit.asp
http://www.devguru.com/Technologies/ecmaScript/quickref/evhan_onsubmit.html
ASKER
great one last thing then, how can i access the form vairables through this method as i've tried the following (similar to what i was doing before) and its not working. I know tha the method is being called as i've added alert messages to test this, but cannot work out how to access the table.
heres what i have
function submitFormEvent(f)
{
alert("OK IN THE METHOD!!!!");
alert(f.selected_prod_type .options.l ength);
for(i=f.selected_prod_type .options.l ength-1;i> =0;i--)
{
productTypeString = productTypeString + f.selected_prod_type.optio ns[i].text ;
alert(productTypeString);
alert(f.selected_prod_type .options[i ].text);
if( i+1 < f.selected_prod_type.optio ns.length- 1 )
productTypeString = productTypeString + ",";
}
}
where the onsubmit is
"submitFormEvent(this.form )"
oh, and thanks for all your help you've been really patient with this.
heres what i have
function submitFormEvent(f)
{
alert("OK IN THE METHOD!!!!");
alert(f.selected_prod_type
for(i=f.selected_prod_type
{
productTypeString = productTypeString + f.selected_prod_type.optio
alert(productTypeString);
alert(f.selected_prod_type
if( i+1 < f.selected_prod_type.optio
productTypeString = productTypeString + ",";
}
}
where the onsubmit is
"submitFormEvent(this.form
oh, and thanks for all your help you've been really patient with this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
great thanks for you help!
ASKER
brilliant informative comments and ideas and filled in all the holes i needed!
Thanks :-)
ASKER
Open in new window