[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to carry an error message and pass it to the previous page

Posted on 2011-04-30
7
Medium Priority
?
403 Views
Last Modified: 2012-06-27
Dear experts,

I am trying to validate my email form that has been written using html tag.
i.e. the form is saved in contact.html and
the validater and functinality that used to send out an email is saved in sendemail.asp page.

What I want is, when ever the user try to send out an email with out filling his/her first name or sencond name, I want my form to redrect back to contact.htm page with an error message telling them that one of the field is not filled our.

Is it possible to append  an error message with the redirect function?
If so, how do I append a message?


' validation
Dim validationOK
validationOK=true
If (Trim(First)="") Then validationOK=false
If (Trim(Last)="") Then validationOK=false
If (Trim(Company)="") Then validationOK=false
If (validationOK=false) Then Response.Redirect("contact_support.html" & EmailFrom)
'Response.Write "Please fill out the requered fields: <b>" & EmailForm & "</b>"



Thank you inadvance
0
Comment
Question by:kate2001
  • 4
  • 2
7 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35498569
No, you can't send any info like that to an HTML page.  It will be ignored..  You could clone your "contact.html" as "contact.asp" and use ASP to put up the error message.  A more common way is to make the "contact.asp" as a self-contained page that posts to itself.  That way, you will have the data so you can put up error messages along with the original data or simply say 'Thanks' and send the email when they do it correctly.
0
 
LVL 13

Accepted Solution

by:
Cedric Obinna A. earned 1000 total points
ID: 35501586
You can also add the following function to your html page if java is enabled on the computers that will be accessing the page.

<script Language="JavaScript" Type="text/javascript"><!--
function FrontPage_Form1_Validator(theForm)
{
 
 if (theForm.Username.value == "")
  {
    alert("Please enter a value for the \"Username\" field.");
    theForm.Username.focus();
    return (false);
  }
}
//--></script>

In this case USERNAME is the field that MUST be filled out. You can change it and you can add as many subs (the bold part) as you want. But add them in the body of the html and before the FORM that contains the textboxes.

Hope this helps.
Cedlinx
0
 

Author Comment

by:kate2001
ID: 35514589
Dear Cedlinx,

I feel like it would work this way. I can't wait till I try your solution. I will let you know the result.

Thank you so much!
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:kate2001
ID: 35696010
What is wrong with my validation check? I couldnt get the error message when I leave "Last" name empty.
<form method="POST" action="sendmail.asp" id="myform">
<p><i>Fields marked (*) are required</i></p>
<fieldset style=" border-color:#FFFFFF">
<legend> <p><b>My Contact Form</b></p></legend>
<br/>
<table border="0">
<tr>
<td><p>Full Name:*</p> </td>
<td> <input type="text" name="Last" size="35"  ></td>
</tr>
<tr>
<td><p>Company:*</p></td>
<td> <input type="text" name="Company" size="35" ></td>
</tr>
<tr>
<td><p>Email:*</p> </td>
<td><input type="text" name="Email" size="35" ></td>
</tr>
<tr>
<td><p>Telephone:* </p></td>
<td> <input type="text" name="Telephone" size="35" > </td>
</tr>

<tr>
<td><p>User ID:</p> </td>
<td> <input type="text" name="Userid"  size="35" > </td>
</tr>
<tr>
<td><p>Project Owner:</p> </td>
<td> <input type="text" name="Projectowner"  size="35" > </td>
</tr>
</table>
</fieldset>
<fieldset style=" border-color:#FFFFFF" >
<legend> <p><b>Questions</b></p> </legend>
<table border="0">
<tr>
<td><p>Message:</p></td>
</tr>
<tr>
<td><textarea rows="10" cols="62%" name="Message"  >
</textarea></td>
</tr>
</table>

<p><center><input type="submit" name="submit" value="Submit"></center></p>
</fieldset>
</form>
<script Language="JavaScript" Type="text/javascript">
function FrontPage_Form1_Validator(myform)
{
 
 if (myform.Last.value == "")
  {
    alert("Please enter a value for the \"Username\" field.");
    myform.Last.focus();
    return (false);
  }}
</script>

Open in new window

0
 

Author Comment

by:kate2001
ID: 35696018
And all the code above is inside <body> tag. What am I missing? And how can I get the the validation check before the form is sending an email (going to sendemail.asp) page?




Thank you inadvance
0
 
LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 1000 total points
ID: 35696100
Try this.
<form method="POST" action="sendmail.asp" id="myform" onsubmit="FrontPage_Form1_Validator(this)">

Open in new window

0
 

Author Comment

by:kate2001
ID: 35696238
Perfect!

Thank you cedlinx and DaveBaldwin!!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question