mi fornite un banale esempio per la controllare l'invio di un form con asp
Posso fare tutto in unica pagina?
mi fornite un banale esempio per la controllare l'invio di un form con asp
Posso fare tutto in unica pagina?
Cosa intendi per controllare l'invio di una form?
ho due campi data da controllare, vorrei fare comparire ad esempio un segno di spunta rosso, se il campo non è correttamente compilato...
codice:<% submit = request.serverVariables("REQUEST_METHOD") = "POST" thisPage = request.serverVariables("PATH_INFO") if submit then errore = false data1 = request.form("data1") data2 = request.form("data2") if not isDate(data1) then errore = true data1error = true end if if not isDate(data2) then errore = true data2error = true end if if not errore then ' qui fai le operazioni qualora le date sono corrette... end if end if %> <form method="post" action="<%=thisPage%>"> Data 1 <input type="text" name="data1" value="<%=data1%>" /><% if data1error then %> <font color="red">V</font><% end if %> Data 2 <input type="text" name="data2" value="<%=data2%>" /><% if data2error then %> <font color="red">V</font><% end if %> <input type="submit" value="VAI" /> </form>
scusami ma nel caso in cui il form sia stato compilato in maniera corretta, come faccio ad inviare il form?
La form viene inviata, nel mio esempio, alla stessa pagina che la contiente.
Se guardi il codice c'è un blocco del tipo:
Dentro quel blocco fai le operazioni che devi fare con i dati presi dalla form.codice:if not errore then ' qui fai le operazioni qualora le date sono corrette... end if
Se poi vuoi fare apparire un messaggio alla fine fai così:
[code]
codice:<% submit = request.serverVariables("REQUEST_METHOD") = "POST" thisPage = request.serverVariables("PATH_INFO") if submit then errore = false data1 = request.form("data1") data2 = request.form("data2") if not isDate(data1) then errore = true data1error = true end if if not isDate(data2) then errore = true data2error = true end if if not errore then ' qui fai le operazioni qualora le date sono corrette... outMessage = "Operazione eseguita" data1 = "" data2 = "" else outMessage = "Si sono verificati degli errori" end if end if %> <form method="post" action="<%=thisPage%>"> Data 1 <input type="text" name="data1" value="<%=data1%>" /><% if data1error then %> <font color="red">V</font><% end if %> Data 2 <input type="text" name="data2" value="<%=data2%>" /><% if data2error then %> <font color="red">V</font><% end if %> <input type="submit" value="VAI" /> </form> <% if submit then response.write outMessage end if %>
si ma se voglio inviare la form ad una altra pagina? solo ovviamente se i dati sono corretti?
codice:<html> <head><title></title> </head> <body> <% submit = request.serverVariables("REQUEST_METHOD") = "POST" thisPage = request.serverVariables("PATH_INFO") if submit then errore = false data1 = request.form("data1") data2 = request.form("data2") if not isDate(data1) then errore = true data1error = true end if if not isDate(data2) then errore = true data2error = true end if if not errore then %> <form name="form2" method="post" action="altrapagina.asp"> <input type="hidden" name="data1" value="<%=data1%>" /> <input type="hidden" name="data2" value="<%=data2%>" /> </form> <script language="javascript" type="text/javascript"> <!-- document.form2.submit(); //--> </script> <% else outMessage = "Si sono verificati degli errori" end if end if %> <form name="form1" method="post" action="<%=thisPage%>"> Data 1 <input type="text" name="data1" value="<%=data1%>" /><% if data1error then %> <font color="red">V</font><% end if %> Data 2 <input type="text" name="data2" value="<%=data2%>" /><% if data2error then %> <font color="red">V</font><% end if %> <input type="submit" value="VAI" /> </form> <% if submit then response.write outMessage end if %> </body> </html>