Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form field order/required fields

Status
Not open for further replies.

StephanieCC

Technical User
Aug 28, 2001
48
US
How do you specify an order for fields in the submitted email and how do you require fields in a form? I've seen various answers to both questions but maybe they are incomplete because I can't seem to get either to work--thanks

the current page in question
 
order for fields in the submitted email
they are ordered as they are on the page unless you manualy change it by using the Request collection and direct pointers to objects in a particular order

require fields in a form?
If Request.Form("this") = "" Then
Response.Write "Error!"
End If

Not sure you want to validate with ASP though. That's where the client comes in (JavaScript)

_____________________________________________________________________
onpnt2.gif

 
Thanks butthe fields do not come out in the order that they are on my form--and I have read that you are lucky if they do--I have tried a fieldorder command but that didn't work--as for the required field, can you give me a little more direction--the this is the field? what about multiple fields and where does that line of script go?
 
If the fields are not coming out the way they are ordered in the <form> then you are looping through the collection incorrectly. can you post the small section where you are requesting the objects


I'm not sure what else to say on the validation.
If Request.Form(&quot;this&quot;) = &quot;&quot; Then
Response.Write &quot;Error!&quot;
End If

this would be the name of the form field. if the value is sent to the server enpty then this conditional statement would catch it and write to the screen &quot;Error!&quot;
you can do things like adding the error message to a variable to send back to the form and have the error message directly aside the form object.
something like if you had a form input text named &quot;Fname&quot; you could do
<form method=&quot;post&quot;>
<input type=&quot;text&quot; name=&quot;Fname&quot;><%=varErrMsg%>
</form>

submit the form and have in the beginning of the page (before the form)
If Request.Form(&quot;Fname&quot;) = &quot;&quot; Then
varErrMsg = &quot;This field is required&quot;
End If

it will be written out then if the field is required. This is real basic explanation and you would need to validate if the form was ever submitted to not write the error message out on the first load though.

_____________________________________________________________________
onpnt2.gif

 
Here's the form code--including my attempt at requiring and ordering that I found at a few sites--

<input name=&quot;_requiredFields&quot; type=&quot;hidden&quot;
value=&quot;month, day, year, name, dept, email, eventname, eventdate,starttime, endtime, eventdescription&quot; />
<input name=&quot;_fieldOrder&quot; type=&quot;hidden&quot;
value=&quot;month, day, year, name, dept, email, eventname, eventdate, starttime, endtime, eventdescription, flyer, poster, bib, media, web, branchout, items, photo, sponsor, call, mail, meet&quot; />
<fieldset>
<p>*Today's Date
<input type=&quot;text&quot; name=&quot;date&quot; value=&quot;&quot; size=&quot;30&quot; />
&nbsp;(MM/DD/YY)</p>
</fieldset>
<fieldset>
<p>*Your Name <o:p>
<input type=&quot;text&quot; name=&quot;name&quot; size=&quot;40&quot; />
</o:p> </p>
<p>*Department/Branch
<input type=&quot;text&quot; name=&quot;dept&quot; size=&quot;40&quot; />
</p>
<p>*Email
<input type=&quot;text&quot; name=&quot;email&quot; size=&quot;30&quot; />
</p>
</fieldset>
<fieldset>
<legend> Event Details </legend>
<p>*Event Name
<input type=&quot;text&quot; name=&quot;eventname&quot; size=&quot;40&quot; />
</p>
<p>*Event Date(s)
<input type=&quot;text&quot; name=&quot;eventdate&quot; size=&quot;40&quot; />
</p>
<p>*Event Start Time
<input type=&quot;text&quot; name=&quot;starttime&quot; />
</p>
<p>*Event End Time
<input type=&quot;text&quot; name=&quot;endtime&quot; />
</p>
<p>*Event Description
<textarea name=&quot;eventdescription&quot; rows=&quot;5&quot; cols=&quot;80&quot;>
</textarea>
</p>
</fieldset>
<fieldset>
<legend> Materials Needed: Check all that apply </legend>
<p>Please note: We will do our best to honor all requested items.</p>
<p>
<fieldset>
<p>
<input type=&quot;checkbox&quot; name=&quot;flyer&quot; value=&quot;Flyer&quot; />
Flyer</p>
<p>
<input type=&quot;checkbox&quot; name=&quot;posters&quot; value=&quot;Posters&quot; />
Posters(created in house or ordered from ALA etc.)</p>
<p>
<input type=&quot;checkbox&quot; name=&quot;bib&quot; value=&quot;bibliographybrochure&quot; />
Bibliography/Brochure</p>
<p>
<input type=&quot;checkbox&quot; name=&quot;media&quot; value=&quot;mediacoverage&quot; />
Press Release/Media Coverage</p>
<p>
<input type=&quot;checkbox&quot; name=&quot;web&quot; value=&quot;webannouncementcalendar&quot; />
Website announcement/calendar</p>
<p>
<input type=&quot;checkbox&quot; name=&quot;branchout&quot; value=&quot;branchout&quot; />
Branch Out Announcement</p>
<p>
<input type=&quot;checkbox&quot; name=&quot;items&quot; value=&quot;incentiveitems&quot; />
Incentive Items(as available)</p>
<p>
<input type=&quot;checkbox&quot; name=&quot;photo&quot; value=&quot;onsitephoto&quot; />
On-site digital photography during event</p>
<p>
<input type=&quot;checkbox&quot; name=&quot;sponsor&quot; value=&quot;sponsorrecognition&quot; />
Sponsor recognition (please include sponsors or grant information in your
event description)</p>
</fieldset>
<p>Additional Materials (please describe):
<textarea name=&quot;additionalmaterials&quot; rows=&quot;5&quot; cols=&quot;80&quot;>
</textarea>
</p>
</fieldset>
<fieldset>
<legend>Follow-up: Please check all that apply</legend>
<p>
<input type=&quot;checkbox&quot; name=&quot;call&quot; value=&quot;call&quot; />
Please call me to follow up on this request.</p>
<p>
<input type=&quot;checkbox&quot; name=&quot;mail&quot; value=&quot;mail&quot; />
I am sending additional materials to you via email or mail within the next
5 days.</p>
<p>
<input type=&quot;checkbox&quot; name=&quot;meet&quot; value=&quot;meeting&quot; />
I would like to schedule a meeting to discuss this event.</p>
</fieldset>
<p>
<input type=&quot;submit&quot; value=&quot;Submit&quot; />
<input type=&quot;reset&quot; value=&quot;Reset&quot; />
</p>
</form>
 
Not sure why the order of your post is significant. It's great to be neat but I usually don't care about order unless I'm posting multiple rows of multiple columns that all need to be inserted or updated. As far as required fields try typeing 'javascript form validation' into Google.
 
the form is for another department to use--if it was for me fields out of order would be fine--but the results need to be user friendly--
 
I guess that I don't understand. I looked at your form. It says that it's going to email the Marketing Department. If you are taking the results of the form fields then you can format the email any way you like. The order of the fields makes no difference. If you were writing the results to a database and wished to display them later, once again order makes no difference. There must be more than meets the eye here.
 
For instance I want todays date first, then there is an event date which pops up wherever it lands--sometimes end time begins the email while start time is at the bottom--so I don't want folks to sift around for the details if that can be prevented--

 
OK. Delete this line from the HTML on your page:
onSubmit=&quot;MM_validateForm('Name','','R');MM_validateForm('Email address','','RisEmail');return document.MM_returnValue&quot;

Replace it with this:
onSubmit=&quot;return formvalidator(this)&quot;

Paste this function somewhere on your page. It's pretty easy to understand so you should be able to change the alert text.

<script Language=&quot;JavaScript&quot;>
<!--
function formvalidator(theForm)
{
if (theForm.date.value == &quot;&quot;)
{
alert(&quot;Please enter a date.&quot;);
theForm.date.focus();
return (false);
}
if (theForm.name.value == &quot;&quot;)
{
alert(&quot;Please enter your name.&quot;);
theForm.name.focus();
return (false);
}
if (theForm.dept.value == &quot;&quot;)
{
alert(&quot;Please enter your department&quot;);
theForm.dept.focus();
return (false);
}
if (theForm.email.value == &quot;&quot;)
{
alert(&quot;Please enter your email&quot;);
theForm.email.focus();
return (false);
}
if (theForm.event_name.value == &quot;&quot;)
{
alert(&quot;Please an event name&quot;);
theForm.event_name.focus();
return (false);
}
if (theForm.dept.value == &quot;&quot;)
{
alert(&quot;Please enter your department&quot;);
theForm.dept.focus();
return (false);
}
if (theForm.event_date.value == &quot;&quot;)
{
alert(&quot;Please enter an event date&quot;);
theForm.event_date.focus();
return (false);
}
if (theForm.start_time.value == &quot;&quot;)
{
alert(&quot;Please enter a start time&quot;);
theForm.start_time.focus();
return (false);
}
if (theForm.end_time.value == &quot;&quot;)
{
alert(&quot;Please enter an end time&quot;);
theForm.end_time.focus();
return (false);
}
if (theForm.event_description.value == &quot;&quot;)
{
alert(&quot;Please enter an event description&quot;);
theForm.event_description.focus();
return (false);
}
return (true);
}
//-->
</script>

That should take care of some simple validation problems. It appears that there was already some validation code in the page but someone screwed it up by trying to validate with Dreamweaver. Hence the &quot;MM_'s&quot;
 
I guess if that's the way your emails come out on the receiving end you really need to get rid of that CGIWare mailing software and find an more robust alternative.
 
so do you think that the cgi software is what is preventing required fields and order from working? By the way thanks a lot for your time on this--
 
Well, from what you're saying it sort of throws your form fields out there in random order. You should find out what type of Web servers your hosting company is using. If it's IIS then you probably have SMTP mail service available as IIS comes with it's own SMTP server. Many hosting companies also add a few bells and whistles to their packages and offer some of the better mail components for you to use. It's worth looking into. If the news is good you'll just have to change some of the code in the page that your form posts to and you'll be able to format emails just like a web page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top