31. oktober 2003 - 11:32Der er
5 kommentarer og 1 løsning
Fjerne unødvendig kodning
Jeg sidder med det problem, at jeg gerne vil have fjernet e-mailen fra min formular, men det virker som om, det går galt hver gang. Nedenfor har jeg indsat mine koder, så jeg håber, der er en, der kan hjælpe mig?
Første fil er min formular, som kalder valideringen;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Systematics homekitchen</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
Anden fil er min validering, som blandt spørg efter e-mailen;
function validering() {
if (new_comment.navn.value == " ") alert('Husk at indtaste en overskrift!')
else
{
error = 0;
placering=0; tekst=(new_comment.email.value).toLowerCase(); placering=tekst.indexOf("@"); if(tekst ==""){ alert ("You must type in your e-mail!"); error = 1; } else{ tegn=tekst.indexOf(" "); if(tegn!=-1){ alert ("Space can not be used in your e-mail address!"); error = 1; } else{ if (tekst.indexOf("æ")!=-1 || tekst.indexOf("ø")!=-1 || tekst.indexOf("å")!=-1 || tekst.indexOf("Æ")!=-1 || tekst.indexOf("Ø")!=-1 || tekst.indexOf("Å")!=-1 || tekst.indexOf(";")!=-1 || tekst.indexOf(",")!=-1){ alert ("These characters æ ø å Æ Ø Å , ; can not be used in your e-mail address!"); error = 1; } else{ if (placering<1 || tekst.length<=(placering+1)){ alert ("Your e-mail address is wrong - try again!"); error = 1; } } } } if(error == 0) new_comment.submit(); } }
Tredje er den fil, der tilføjer;
<%
'Set the response buffer to true as we maybe redirecting Response.Buffer = True
strMode = request.form("strMode")
'If the session variable is False or does not exsist then redirect the user to the unauthorised user page If strMode <> "new_comment" then 'Redirect to user start page Response.Redirect "index.asp" End If
'Dimension variables Dim strInputComments 'Holds the Users comments Dim saryCommentWord 'Array to hold each word in the comments enetred by the user Dim intCheckWordLengthLoopCounter 'Loop counter Dim intWordLength 'Holds the length of the word to be checked Dim blnWordLenthOK 'Boolean set to False if any words in the description are above 80 characters Dim intLongestWordLength 'Holds the number of characters in the longest word entered in the
'Read in user deatils from the kokken (DB users.db) form strInputComments = Request.Form("text")
'Split-up each word in the comments from the user to check that no word entered is over 50 characters saryCommentWord = Split(Trim(strInputComments), " ")
'Initialse the word length variable blnWordLenthOK = True
'Loop round to check that each word in the comments entered by the user is not above 70 characters For intCheckWordLengthLoopCounter = 0 To UBound(saryCommentWord)
'Initialise the intWordLength variable with the length of the word to be searched intWordLength = Len(saryCommentWord(intCheckWordLengthLoopCounter))
'Get the number of characters in the longest word If intWordLength => intLongestWordLength Then intLongestWordLength = intWordLength End If
'If the word length to be searched is more than or equal to 70 then set the blnWordLegthOK to false If intWordLength => 80 Then blnWordLenthOK = False End If Next
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Systematics homekitchen</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
Anden fil er min validering, som blandt spørg efter e-mailen;
function validering() { var error; error = 0;
if (new_comment.navn.value == " ") { alert('Husk at indtaste en overskrift!') error = 1 } if(error == 0) new_comment.submit(); }
Tredje er den fil, der tilføjer;
<%
'Set the response buffer to true as we maybe redirecting Response.Buffer = True
strMode = request.form("strMode")
'If the session variable is False or does not exsist then redirect the user to the unauthorised user page If strMode <> "new_comment" then 'Redirect to user start page Response.Redirect "index.asp" End If
'Dimension variables Dim strInputComments 'Holds the Users comments Dim saryCommentWord 'Array to hold each word in the comments enetred by the user Dim intCheckWordLengthLoopCounter 'Loop counter Dim intWordLength 'Holds the length of the word to be checked Dim blnWordLenthOK 'Boolean set to False if any words in the description are above 80 characters Dim intLongestWordLength 'Holds the number of characters in the longest word entered in the
'Read in user deatils from the kokken (DB users.db) form strInputComments = Request.Form("text")
'Split-up each word in the comments from the user to check that no word entered is over 50 characters saryCommentWord = Split(Trim(strInputComments), " ")
'Initialse the word length variable blnWordLenthOK = True
'Loop round to check that each word in the comments entered by the user is not above 70 characters For intCheckWordLengthLoopCounter = 0 To UBound(saryCommentWord)
'Initialise the intWordLength variable with the length of the word to be searched intWordLength = Len(saryCommentWord(intCheckWordLengthLoopCounter))
'Get the number of characters in the longest word If intWordLength => intLongestWordLength Then intLongestWordLength = intWordLength End If
'If the word length to be searched is more than or equal to 70 then set the blnWordLegthOK to false If intWordLength => 80 Then blnWordLenthOK = False End If Next
Den kommer nu med denne fejl, når jeg ikke taster noget ind i overskriften, kan du se, hvad fejlen nu er? Det virker dog fint nok, hvis jeg taster noget ind i overskriften.
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Microsoft Access Driver] Field 'kokken.nick' cannot be a zero-length string.
Indstillingerne er sådan i min DB 'kokken.nick'. Jeg tæntke mere på, om eagleeye ikke kunne hjælpe eller en anden, der kan se, hvad det er, der går galt i det, han har sendt. For det virker ellers fint med mindre jeg ikke indtaster noget i overskrift...mon ikke det bare er en lille scriptfejl?
det er ikke koden der er fejl i, det er DB'en. Den tillader ikke NULL værdi og derfor melder den den fejl du skriver. Hvis man skal kunne lade være med at indtaste en værdi i det felt (som det er nu) skal du tillade NULL værdi for den kolonne i din DB, ellers skal du jave en test på om feltet er udfyldt når man submitter formen.
Okay, hvordan laver jeg så denne test i koder, hvis feltet IKKE er udfyldt?
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.