473,471 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to ommit form fields if empty using asp?

1 New Member
Hello I am new to asp programing (classic asp) and I am teaching myself this language. I am having some difficulty finding the syntax to this problem I have having.

I am trying to omit the empty fields in my form so that those empty fields are not output to the email I receive.

I found this fix in php, but not in asp. Can someone help me with this?

My form, see below: ASP Vbscripting:

Expand|Select|Wrap|Line Numbers
  1. <%@ Language="VBscript" %>
  2. <% Option Explicit %>
  3.  
  4. <html>
  5. <head>
  6. <title>some title goes here</title>
  7. </head>
  8.  
  9. <body>
  10. <%
  11. Dim warehouse, userid, domain, customerno, vendor, specialrequirements, item1, desc1, qty1, brand1, freeform1, item2, desc2, qty2, brand2, freeform2, item3, desc3, qty3, brand3, freeform3, item4, desc4, qty4, brand4, freeform4, item5, desc5, qty5, brand5, freeform5, item6, desc6, qty6, brand6, freeform6, NewMailObj
  12.  
  13. warehouse=request.form("warehouse")
  14. userid=request.form("userid")
  15. domain=request.form("domain")
  16. customerno=request.form("customerno")
  17. vendor=request.form("vendor")
  18. specialrequirements=request.form("specialrequirements")
  19. item1=request.form("item1")
  20. desc1=request.form("desc1")
  21. qty1=request.form("qty1")
  22. brand1=request.form("brand")
  23. freeform1=request.form("freeform1")
  24. item2=request.form("item2")
  25. desc2=request.form("desc2")
  26. qty2=request.form("qty2")
  27. brand2=request.form("brand2")
  28. freeform2=request.form("freeform2")
  29. item3=request.form("item3")
  30. desc3=request.form("desc3")
  31. qty3=request.form("qty3")
  32. brand3=request.form("brand3")
  33. freeform3=request.form("freefrom3")
  34. item4=request.form("item4")
  35. desc4=request.form("desc4")
  36. qty4=request.form("qty4")
  37. brand4=request.form("brand4")
  38. freeform4=request.form("freeform4")
  39. item5=request.form("item5")
  40. desc5=request.form("desc5")
  41. qty5=request.form("qty5")
  42. brand5=request.form("brand5")
  43. freeform5=request.form("freeform5")
  44. item6=request.form("item6")
  45. desc6=request.form("desc6")
  46. qty6=request.form("qty6")
  47. brand6=request.form("brand6")
  48. freeform6=request.form("freeform6")
  49.  
  50. ' create the form results in a HTML table format to be sent to the email
  51. Dim FormResults
  52. FormResults = FormResults & "<html>"
  53. FormResults = FormResults & "<head>"
  54. FormResults = FormResults & "<title></title>"
  55. FormResults = FormResults & "</head>"
  56. FormResults = FormResults & "<body>"
  57. FormResults = FormResults & "<table border='0' width='100%' align='center'>"
  58. FormResults = FormResults & "<tr>"
  59. FormResults = FormResults & "<td>&nbsp;</td>"
  60. FormResults = FormResults & "</tr>"
  61. FormResults = FormResults & "<tr>"
  62. FormResults = FormResults & "<td align='right' width='50%'>User's IP Address:</td>"
  63. FormResults = FormResults & "<td align='left'>" & Request.ServerVariables("REMOTE_ADDR") & "</td>"
  64. FormResults = FormResults & "</tr>"
  65. FormResults = FormResults & "<tr>"
  66. FormResults = FormResults & "<tr>"
  67. FormResults = FormResults & "<td colspan='5' align='center' nowrap>-------------------------------------------</td>"
  68. FormResults = FormResults & "</tr>"
  69. FormResults = FormResults & "<tr>"
  70. FormResults = FormResults & "<td align='right' width='50%'>Warehouse Number:</td>"
  71. FormResults = FormResults & "<td align='left'>" & warehouse & "</td>"
  72. FormResults = FormResults & "</tr>"
  73. FormResults = FormResults & "<tr>"
  74. FormResults = FormResults & "<td align='right' width='50%'>User Email Address:</td>"
  75. FormResults = FormResults & "<td align='left'>" & userid & "@" & domain & "</td>"
  76. FormResults = FormResults & "</tr>"
  77. FormResults = FormResults & "<tr>"
  78. FormResults = FormResults & "<td align='right' width='50%'>Customer No:</td>"
  79. FormResults = FormResults & "<td align='left'>" & customerno & "</td>"
  80. FormResults = FormResults & "</tr>"
  81. FormResults = FormResults & "<tr>"
  82. FormResults = FormResults & "<td align='right' width='50%'>Have already contacted this vendor?</td>"
  83. FormResults = FormResults & "<td align='left'>" & vendor & "</td>"
  84. FormResults = FormResults & "</tr>"
  85. FormResults = FormResults & "<tr>"
  86. FormResults = FormResults & "<td align='right' width='50%'>Freeform Description:</td>"
  87. FormResults = FormResults & "<td align='left' style='vertical-align:top'>" & specialrequirements & "</td>"
  88. FormResults = FormResults & "</tr>"
  89. FormResults = FormResults & "<tr>"
  90. FormResults = FormResults & "<td colspan='5' align='center' nowrap>-------------------------------------------</td>"
  91. FormResults = FormResults & "</tr>"
  92. FormResults = FormResults & "<tr>"
  93. FormResults = FormResults & "<td>&nbsp;</td>"
  94. FormResults = FormResults & "</tr>"
  95. FormResults = FormResults & "<tr>"
  96. FormResults = FormResults & "<td align='right' width='50%'>Item Number [1]</td>"
  97. FormResults = FormResults & "<td align='left'>Item Number [1]</td>"
  98. FormResults = FormResults & "</tr>"
  99. FormResults = FormResults & "<tr>"
  100. FormResults = FormResults & "<td align='right' width='50%'>Item #:</td>"
  101. FormResults = FormResults & "<td align='left'>" & item1 & "</td>"
  102. FormResults = FormResults & "</tr>"
  103. FormResults = FormResults & "<tr>"
  104. FormResults = FormResults & "<td align='right' width='50%'>Qty:/b></td>"
  105. FormResults = FormResults & "<td align='left'>" & qty1 & "</td>"
  106. FormResults = FormResults & "</tr>"
  107. FormResults = FormResults & "<tr>"
  108. FormResults = FormResults & "<td align='right' width='50%'>Industry Description:</td>"
  109. FormResults = FormResults & "<td align='left'>" & desc1 & "</td>"
  110. FormResults = FormResults & "</tr>"
  111. FormResults = FormResults & "<tr>"
  112. FormResults = FormResults & "<td align='right' width='50%'>Required Brand:</td>"
  113. FormResults = FormResults & "<td align='left'>" & brand1 & "</td>"
  114. FormResults = FormResults & "</tr>"
  115. FormResults = FormResults & "<tr>"
  116. FormResults = FormResults & "<td align='right' width='50%'>Freeform Description:</td>"
  117. FormResults = FormResults & "<td align='left' style='vertical-align:top'>" & freeform1 & "</td>"
  118. FormResults = FormResults & "</tr>"
  119. FormResults = FormResults & "<tr>"
  120. FormResults = FormResults & "<td colspan='5' align='center' nowrap>-------------------------------------------</td>"
  121. FormResults = FormResults & "</tr>"
  122. FormResults = FormResults & "<tr>"
  123. FormResults = FormResults & "<td align='right' width='50%'>Item Number [2]</td>"
  124. FormResults = FormResults & "<td align='left'>Item Number [2]</td>"
  125. FormResults = FormResults & "</tr>"
  126. FormResults = FormResults & "<tr>"
  127. FormResults = FormResults & "<td align='right' width='50%'>Item #:</td>"
  128. FormResults = FormResults & "<td align='left'>" & item2 & "</td>"
  129. FormResults = FormResults & "</tr>"
  130. FormResults = FormResults & "<tr>"
  131. FormResults = FormResults & "<td align='right' width='50%'>Qty:</td>"
  132. FormResults = FormResults & "<td align='left'>" & qty2 & "</td>"
  133. FormResults = FormResults & "</tr>"
  134. FormResults = FormResults & "<tr>"
  135. FormResults = FormResults & "<td align='right' width='50%'>Industry Description:</td>"
  136. FormResults = FormResults & "<td align='left'>" & desc2 & "</td>"
  137. FormResults = FormResults & "</tr>"
  138. FormResults = FormResults & "<tr>"
  139. FormResults = FormResults & "<td align='right' width='50%'>Required Brand:</td>"
  140. FormResults = FormResults & "<td align='left'>" & brand2 & "</td>"
  141. FormResults = FormResults & "</tr>"
  142. FormResults = FormResults & "<tr>"
  143. FormResults = FormResults & "<td align='right' width='50%'>Freeform Description:</td>"
  144. FormResults = FormResults & "<td align='left' style='vertical-align:top'>" & freeform2 & "</td>"
  145. FormResults = FormResults & "</tr>"
  146. FormResults = FormResults & "<tr>"
  147. FormResults = FormResults & "<td colspan='5' align='center' nowrap>-------------------------------------------</td>"
  148. FormResults = FormResults & "</tr>"
  149. FormResults = FormResults & "<tr>"
  150. FormResults = FormResults & "<td align='right' width='50%'>Item Number [3]</td>"
  151. FormResults = FormResults & "<td align='left'>Item Number [3]</td>"
  152. FormResults = FormResults & "</tr>"
  153. FormResults = FormResults & "<tr>"
  154. FormResults = FormResults & "<td align='right' width='50%'>Item #:</td>"
  155. FormResults = FormResults & "<td align='left'>" & item3 & "</td>"
  156. FormResults = FormResults & "</tr>"
  157. FormResults = FormResults & "<tr>"
  158. FormResults = FormResults & "<td align='right' width='50%'>Qty:</td>"
  159. FormResults = FormResults & "<td align='left'>" & qty3 & "</td>"
  160. FormResults = FormResults & "</tr>"
  161. FormResults = FormResults & "<tr>"
  162. FormResults = FormResults & "<td align='right' width='50%'>Industry Description:</td>"
  163. FormResults = FormResults & "<td align='left'>" & desc3 & "</td>"
  164. FormResults = FormResults & "</tr>"
  165. FormResults = FormResults & "<tr>"
  166. FormResults = FormResults & "<td align='right' width='50%'>Required Brand:</td>"
  167. FormResults = FormResults & "<td align='left'>" & brand3 & "</td>"
  168. FormResults = FormResults & "</tr>"
  169. FormResults = FormResults & "<tr>"
  170. FormResults = FormResults & "<td align='right' width='50%'>Freeform Description:</td>"
  171. FormResults = FormResults & "<td align='left' style='vertical-align:top'>" & freeform3 & "</td>"
  172. FormResults = FormResults & "</tr>"
  173. FormResults = FormResults & "<tr>"
  174. FormResults = FormResults & "<td colspan='5' align='center' nowrap>-------------------------------------------</td>"
  175. FormResults = FormResults & "</tr>"
  176. FormResults = FormResults & "<tr>"
  177. FormResults = FormResults & "<td align='right' width='50%'>Item Number [4]</td>"
  178. FormResults = FormResults & "<td align='left'>Item Number [4]</td>"
  179. FormResults = FormResults & "</tr>"
  180. FormResults = FormResults & "<tr>"
  181. FormResults = FormResults & "<td align='right' width='50%'>Item #:</td>"
  182. FormResults = FormResults & "<td align='left'>" & item4 & "</td>"
  183. FormResults = FormResults & "</tr>"
  184. FormResults = FormResults & "<tr>"
  185. FormResults = FormResults & "<td align='right' width='50%'>Qty:</td>"
  186. FormResults = FormResults & "<td align='left'>" & qty4 & "</td>"
  187. FormResults = FormResults & "</tr>"
  188. FormResults = FormResults & "<tr>"
  189. FormResults = FormResults & "<td align='right' width='50%'>Industry Description:</td>"
  190. FormResults = FormResults & "<td align='left'>" & desc4 & "</td>"
  191. FormResults = FormResults & "</tr>"
  192. FormResults = FormResults & "<tr>"
  193. FormResults = FormResults & "<td align='right' width='50%'>Required Brand:</td>"
  194. FormResults = FormResults & "<td align='left'>" & brand4 & "</td>"
  195. FormResults = FormResults & "</tr>"
  196. FormResults = FormResults & "<tr>"
  197. FormResults = FormResults & "<td align='right' width='50%'>Freeform Description:</td>"
  198. FormResults = FormResults & "<td align='left' style='vertical-align:top'>" & freeform4 & "</td>"
  199. FormResults = FormResults & "</tr>"
  200. FormResults = FormResults & "<tr>"
  201. FormResults = FormResults & "<td colspan='5' align='center' nowrap>-------------------------------------------</td>"
  202. FormResults = FormResults & "</tr>"
  203. FormResults = FormResults & "<tr>"
  204. FormResults = FormResults & "<td align='right' width='50%'>Item Number [5]</td>"
  205. FormResults = FormResults & "<td align='left'>Item Number [5]</td>"
  206. FormResults = FormResults & "</tr>"
  207. FormResults = FormResults & "<tr>"
  208. FormResults = FormResults & "<td align='right' width='50%'>Item #:</td>"
  209. FormResults = FormResults & "<td align='left'>" & item5 & "</td>"
  210. FormResults = FormResults & "</tr>"
  211. FormResults = FormResults & "<tr>"
  212. FormResults = FormResults & "<td align='right' width='50%'>Qty:</td>"
  213. FormResults = FormResults & "<td align='left'>" & qty5 & "</td>"
  214. FormResults = FormResults & "</tr>"
  215. FormResults = FormResults & "<tr>"
  216. FormResults = FormResults & "<td align='right' width='50%'>Industry Description:</td>"
  217. FormResults = FormResults & "<td align='left'>" & desc5 & "</td>"
  218. FormResults = FormResults & "</tr>"
  219. FormResults = FormResults & "<tr>"
  220. FormResults = FormResults & "<td align='right' width='50%'>Required Brand:</td>"
  221. FormResults = FormResults & "<td align='left'>" & brand5 & "</td>"
  222. FormResults = FormResults & "</tr>"
  223. FormResults = FormResults & "<tr>"
  224. FormResults = FormResults & "<td align='right' width='50%'>Freeform Description:</td>"
  225. FormResults = FormResults & "<td align='left' style='vertical-align:top'>" & freeform5 & "</td>"
  226. FormResults = FormResults & "</tr>"
  227. FormResults = FormResults & "<tr>"
  228. FormResults = FormResults & "<td colspan='5' align='center' nowrap>-------------------------------------------</td>"
  229. FormResults = FormResults & "</tr>"
  230. FormResults = FormResults & "<tr>"
  231. FormResults = FormResults & "<td align='right' width='50%'>Item Number [6]</td>"
  232. FormResults = FormResults & "<td align='left'>Item Number [6]</td>"
  233. FormResults = FormResults & "</tr>"
  234. FormResults = FormResults & "<tr>"
  235. FormResults = FormResults & "<td align='right' width='50%'>Item #:</td>"
  236. FormResults = FormResults & "<td align='left'>" & item6 & "</td>"
  237. FormResults = FormResults & "</tr>"
  238. FormResults = FormResults & "<tr>"
  239. FormResults = FormResults & "<td align='right' width='50%'>Qty:</td>"
  240. FormResults = FormResults & "<td align='left'>" & qty6 & "</td>"
  241. FormResults = FormResults & "</tr>"
  242. FormResults = FormResults & "<tr>"
  243. FormResults = FormResults & "<td align='right' width='50%'>Industry Description:</td>"
  244. FormResults = FormResults & "<td align='left'>" & desc6 & "</td>"
  245. FormResults = FormResults & "</tr>"
  246. FormResults = FormResults & "<tr>"
  247. FormResults = FormResults & "<td align='right' width='50%'>Required Brand:</td>"
  248. FormResults = FormResults & "<td align='left'>" & brand6 & "</td>"
  249. FormResults = FormResults & "</tr>"
  250. FormResults = FormResults & "<tr>"
  251. FormResults = FormResults & "<td align='right' width='50%'>Freeform Description:</td>"
  252. FormResults = FormResults & "<td align='left' style='vertical-align:top'>" & freeform6 & "</td>"
  253. FormResults = FormResults & "</tr>"
  254. FormResults = FormResults & "</table>"
  255. FormResults = FormResults & "</body>"
  256. FormResults = FormResults & "</html>"
  257.  
  258. 'create the mail object and send the details
  259. Set NewMailObj=Server.CreateObject("CDONTS.NewMail")
  260. NewMailObj.From = userid & "@" & domain
  261. NewMailObj.To = "some@email.here"
  262. NewMailObj.Subject = "a subject here" 
  263. NewMailObj.Body = FormResults 
  264.  
  265. 'you need to add the following lines FOR the mail to be sent in HTML format
  266. NewMailObj.BodyFormat = 0 
  267. NewMailObj.MailFormat = 0 
  268. NewMailObj.Send
  269. 'Close the email object and free up resources 
  270. Set NewMailObj = nothing
  271. Response.redirect("thankyou.asp")
  272. %> 
  273.  
This script works perfectly, though it is also sending the empty fields in the email. I need to omitt them out so that only the fields that contain the information is being sent in the email.

Can someone please help with this?
Oct 27 '10 #1
1 2501
danp129
323 Recognized Expert Contributor
You need to use an If statement like this:
Expand|Select|Wrap|Line Numbers
  1. If warehouse <> "" Then
  2.   FormResults = FormResults & "<tr>"
  3.   FormResults = FormResults & "<td align='right' width='50%'>Warehouse Number:</td>"
  4.   FormResults = FormResults & "<td align='left'>" & warehouse & "</td>"
  5.   FormResults = FormResults & "</tr>"
  6. End If
Or an iif() statement like this:
Expand|Select|Wrap|Line Numbers
  1. FormResults = FormResults & iif(warehouse="","", "<tr><td align='right' width='50%'>" & _
  2.                         "Warehouse Number:</td><td align='left'>" & _
  3.                         warehouse & "</td></tr>")
Since VBScript does not have an iif function, you will need to create one if you decide to use it.:
Expand|Select|Wrap|Line Numbers
  1. function iif(expr, returnWhenTrue, returnWhenFalse)
  2.   if expr then
  3.     iif = returnWhenTrue
  4.   else 
  5.     iif = returnWhenFalse
  6.   end if
  7. end function
Oct 28 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: JDJones | last post by:
I have a form I'm putting together. The processing will be on a PHP script that will take all the field names and print them out on the email it sends to me. No problem there. But what I'd like to...
5
by: Batezz | last post by:
I have created a form (below) How do I stop it redirecting to another page (productsearchresults.php) when form is submitted if both the fields are blank? Any help appreciated. Batezz
4
by: jwlum | last post by:
I have the following problem under Internet Explorer only: 1. User fills out form data (myform.php) and clicks a button that fires myFunction() 2. myFunction() spawns a "hello, world" popup page...
7
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a...
4
by: Mike De Petris | last post by:
I am using itextsharp to fill in and flatten some fields from data filled in a web form field and all works quite well. The question now is how to manage the pdf template that has the fields to...
4
by: Anthony P | last post by:
Hello Everyone, I am having some trouble getting my JavaScript to validate my form fields. I've included more information below. My explaination of the code is in ALL CAPS so it stands out from...
26
by: pepper.gabriela | last post by:
Hello, a stupid question but... page_A.php is a page with a form. The user inserts text in four fields, then he clicks a submit button. The data goes to page_B.php: this page controls the data...
0
by: marcopolo8 | last post by:
Wierd thing is happening during my xHTML development. When I set the width attribute of a text field in a form and use percentages, if the text field's value is extremely long, IE6 automatically...
1
by: ERobishaw | last post by:
Using Winform app writing a HTTP Post using the following... on the server side, I get no form fields. Request.Form.AllKeys.Length = 0. If I put the field/value paris in the URL I can use...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.