PDA

View Full Version : I need some help coding a Form


CSUjr
05-27-2006, 02:53 AM
I am new to writing HTML.

I have read HTML tuts, looked at examples and tried different things, but I'm stuck on how to make my Form do what I need it to do.

I have a simple Form that a user inputs information in and clicks a submit button.

When the information is submitted, it must match a specific line of text (which is always the same and is specified somewhere within the code of that same page).

If the submitted information does not match the specified line of text, then I need to present a message to the user to enter the correct information.

If the submitted information does match the specified line of text, then I want to send the user to another (specified) page within the site.

This is what I have so far;

<html>
<body>
<form name="input" action="html_form_action.asp"
method="get">



<font face="Verdana, Arial, Helvetica, sans-serif" size="2">
Enter your answer and click Go
</p>
<form>
Answer:
<input type="text" name="answer">
<input type="submit" value="Go">
</form>

Question>>>If the answer is not correct, what code do I need to put in here (???) to return a message like, "Please enter the correct answer"

Question>>>If the answer is correct, what code do I need to put in here (???) to send the user to a specified page within the site?

</font>
</body>
</html>

Also, is this the correct type of form for what I am trying to do? <form name="input" action="html_form_action.asp"
method="get">

Can anyone help by providing me with the code that I need to make this Form do what I need it to do?

Thank you,
Charles

edbr
05-27-2006, 03:36 AM
I am guessing that you wouls have to validate in your "html_form_action.asp"

CSUjr
05-27-2006, 04:13 AM
I am guessing that you wouls have to validate in your "html_form_action.asp"

I don't understand what you mean by that.

Can you please explain.

edbr
05-27-2006, 05:42 AM
with forms i have used (php) the field would be check to see if it had been correctly filled in and if so you could then direct to answer a, or if not correct then answer b.
I am clueless with asp but I would think the same will apply. i hope some one out there can be of more use than me!

CSUjr
05-27-2006, 05:55 AM
Thank you for your response.

I am also clueless with much of this.

As I said I am new to almost all of this and I am hoping that someone here will understand what I am trying to achieve and provide me with the code that I need to make this work.

dthomsen8
05-27-2006, 11:42 AM
<html>
<body>
<form name="input" action="html_form_action.asp"
method="get">


The action specifies where the form sends the information entered by the user.

The first question you have to answer is whether you are using PHP or ASP to handle the information entered. Either one can return the user to the form to change invalid information or enter required fields. I have always used PHP for forms, myself, and don't know anything about ASP. The example you cite says ASP.

Your web hosting company supplies the ability to process PHP (or ASP), and you cannot make the action code work on your local computer unless you run a server, such as APACHE.

There are services that supply the required processing and send you an email with the results, but they aren't cheap. I don't suggest that as an alternative.

You also need to decide what you do with the information entered by the user once it is validated. Do you want it sent to you as an email? Recorded in a database? What kind of database?

There is a lot to learn about form processing. You have to provide more information before I or any other forum member can help you further.

CSUjr
05-27-2006, 04:39 PM
Okay, this is what I have now.

It doesn't work, but I think that it's closer;

<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: small;
}
-->
</style>
</head>

<body>

<form name="input" action="html_form_action.asp" >
<p class="style1">
Enter your answer and click Go</p>


<span class="style1">Answer:</span>
<input type="text" name="answer">
<input type="submit" value="Go">

<% if request.form('answer')="correct answer"

<% else %>
<p class="style1">Please enter the correct answer</p>

<% end if %>
</form>
</body>
</html>

Can anyone please help me with the correct coding?

dthomsen8
05-27-2006, 06:24 PM
What is in the file html_form_action.asp?

CSUjr
05-27-2006, 08:17 PM
dthomsen8 Wrote:
You also need to decide what you do with the information entered by the user once it is validated.

1. The User enters text into the Form
2. The User clicks the submit button
3. If the text does not match the text that is specified in the Form then, the User recieves a message, "Please enter the correct text"
4. If the text does match the text that is specified in the Form then, the User is sent to a Page that is specified in the Form.

dthomsen8 Wrote:
What is in the file html_form_action.asp?
1. The correct text
2. The name (address) of the page that the User is sent to (success.html) when they have entered the correct text.

If I am using the wrong Form (.asp or method=Get, etc) or if there is another way or Form that I can use to accomplish this, please let me know.

Anyone, please.

CSUjr
05-28-2006, 06:28 AM
Okay, let me try again.

The code below sends the User to the desired page regardless of what is in the text box, and even if it is empty.

This means that I have not put the right information in the right place in this code.

I want it so that the User Must enter the correct information
if not, the User will receive a message such as; “Please enter the correct information”
if so, the User will be sent to the specified page


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Answer Validation</title>
<style type="text/css">
<!--
.style1 {
font-family: Geneva, Arial, Helvetica, sans-serif;
font-size: small;
}
-->
</style>
</head>

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!--
function validateForm()
{
var count=0;
var msg="correct";

for(i=0;i<=4;i++)
{
if(document.UD.elements[i].value=="correct")
{
count=1;
msg=msg+"\n"+document.UD.elements[i].name;
}
else if((i>3) && (count==0))
{
return(true);
}
}
for(i=0;i<=4;i++)
{
if(document.UD.elements[i].value=="correct")
{
alert("Please enter Correct Answer\n "+msg);
document.UD.elements[i].focus();
return(false);
}

}


}
//-->
</SCRIPT>
</HEAD>

<BODY>

<FORM METHOD=POST ACTION="success.html" NAME="UD">
<TABLE ALIGN="CENTER">
<TR>
<TD><span class="style1">Enter Correct Answer </span></TD>
<TD><INPUT NAME="correct" TYPE="TEXT" size="40"></TD><TD><INPUT TYPE="SUBMIT" VALUE="Go"
onClick="return validateForm()"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>

Will someone please help me make this so that it works the way that I need it to?

Charles