# ASP.  Correct way to check a form has been sent.

**URL:** <https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759>\
**Category:** Factual Questions\
**Created:** [October 13, 2008, 7:33pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759 "2008-10-13T19:33:00Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [October 13, 2008, 7:33pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/1 "2008-10-13T19:33:00Z")

</div>

I have decided to write a template ASP file as most of the ones I write do the same thing (run a query and show a table) with slight variations between each one.

I usually check one field to see if it’s time to start processing the input…

if request.querystring(“field”) = “” then

But I am pretty sure this isn’t the most correct way of doing it. So what is?

As this is a template I want to be correct 🙂

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [October 13, 2008, 7:41pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/2 "2008-10-13T19:41:54Z")

</div>

Another question. I want to give me the option of including a file or not. Since an ASP include is _already_ using html comments is there a way of doing it without adding asp wrappers (\<% and %\> and then adding a quote?) that seems ott and only confuses the code… I’m tring to simplify the code.  
In other words I want a way to disable a line like this…

\<!–#include file=“includes\aninclude.asp”–\>

without resorting to this…

\<%

'\<!–#include file=“includes\aninclude.asp”–\>

%\>

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [October 13, 2008, 7:58pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/3 "2008-10-13T19:58:28Z")

</div>

And one more question. How do I reset the page from a link on the page so the fields are blanked again, without having to use the name of the page?

---

<div class="post-metadata">

**Author:** ![toadspittle](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@toadspittle](https://boards.straightdope.com/u/toadspittle)\
**Post date:** [October 13, 2008, 8:18pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/4 "2008-10-13T20:18:10Z")

</div>

Re: question 2:

You can’t do an include that way. Includes are processed BEFORE any code is executed. If you want to do a conditional include, you need to use the [EXECUTE method.](http://www.w3schools.com/asp/met_execute.asp)

---

<div class="post-metadata">

**Author:** ![toadspittle](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@toadspittle](https://boards.straightdope.com/u/toadspittle)\
**Post date:** [October 13, 2008, 8:23pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/5 "2008-10-13T20:23:04Z")

</div>

> [@Lobsang](#):
>
> And one more question. How do I reset the page from a link on the page so the fields are blanked again, without having to use the name of the page?

The [reset button?](http://www.w3.org/TR/html401/interact/forms.html)

---

<div class="post-metadata">

**Author:** ![ZipperJJ](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zipperjj/32/211_2.png) [@ZipperJJ](https://boards.straightdope.com/u/ZipperJJ)\
**Post date:** [October 13, 2008, 8:31pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/6 "2008-10-13T20:31:01Z")

</div>

In your form use a hidden tag

```auto

<input type="hidden" name="IsPostBack" value="1">

```

Then, on the code that handles the submission:

```auto

If Request.Form("IsPostBack") = 1 Then 
 .... do form stuff
End If

```

If you want a button to reset a form, use a reset button

```auto

<input type="reset" id="btnReset" value="Clear Form">

```

If you want to get a page’s name w/o knowing it:

```auto

request.servervariables("script_name")

```

And then look into using [ASP.NET](http://ASP.NET) instead because ASP classic is on it’s way out in a big way.

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [October 13, 2008, 9:09pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/7 "2008-10-13T21:09:55Z")

</div>

> [@toadspittle](#):
>
> Re: question 2:
> 
> You can’t do an include that way. Includes are processed BEFORE any code is executed. If you want to do a conditional include, you need to use the [EXECUTE method.](http://www.w3schools.com/asp/met_execute.asp)

It works.

What you might not be realizing is that I’m creating a template. The idea being that I’ll create a new file with it and manually, with my fingers, make the include ‘work’ again.

So the thing that decides the condition is not code, it’s me. (in the future when I come to use this template)

But your link might work anyway 🙂

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [October 13, 2008, 9:11pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/8 "2008-10-13T21:11:14Z")

</div>

> [@ZipperJJ](#):
>
> In your form use a hidden tag
> 
> ```auto
> 
> <input type="hidden" name="IsPostBack" value="1">
> 
> ```
> 
> Then, on the code that handles the submission:
> 
> ```auto
> 
> If Request.Form("IsPostBack") = 1 Then 
> .... do form stuff
> End If
> 
> ```
> 
> If you want a button to reset a form, use a reset button
> 
> ```auto
> 
> <input type="reset" id="btnReset" value="Clear Form">
> 
> ```
> 
> If you want to get a page’s name w/o knowing it:
> 
> ```auto
> 
> request.servervariables("script_name")
> 
> ```
> 
> And then look into using [ASP.NET](http://ASP.NET) instead because ASP classic is on it’s way out in a big way.

I think I’ll convert to PHP when I decide to ditch ASP.

Thanks for the answers BTW 🙂

---

<div class="post-metadata">

**Author:** ![Mbossa](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mbossa](https://boards.straightdope.com/u/Mbossa)\
**Post date:** [October 13, 2008, 9:27pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/9 "2008-10-13T21:27:35Z")

</div>

> [@Lobsang](#):
>
> It works.
> 
> What you might not be realizing is that I’m creating a template. The idea being that I’ll create a new file with it and manually, with my fingers, make the include ‘work’ again.
> 
> So the thing that decides the condition is not code, it’s me. (in the future when I come to use this template)
> 
> But your link might work anyway 🙂

In that case, couldn’t you just include it like this?

```auto

<!--include file="includes\aninclude.asp"-->

```

Without the ‘#’ it would be treated as a standard HTML comment. To actually include it, add the ‘#’

```auto

<!--#include file="includes\aninclude.asp"-->

```

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [October 13, 2008, 9:32pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/10 "2008-10-13T21:32:41Z")

</div>

Is there a variant of request.servervariables(“script\_name”) that gets the url without any passed data (nothing after the .asp)

It’s for a ‘back to data entry’ link. I don’t want to use the ‘reset’ way because that means extra code in places.

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [October 13, 2008, 9:34pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/11 "2008-10-13T21:34:17Z")

</div>

> [@Mbossa](#):
>
> In that case, couldn’t you just include it like this?
> 
> ```auto
> 
> <!--include file="includes\aninclude.asp"-->
> 
> ```
> 
> Without the ‘#’ it would be treated as a standard HTML comment. To actually include it, add the ‘#’
> 
> ```auto
> 
> <!--#include file="includes\aninclude.asp"-->
> 
> ```

If that works then perfect! I’ll use that in my template, and in the comments above I’ll put…

'If you need to use this include add the ‘#’ key before ‘include’

Thanks again all. I am looking for this template to require the minimum of thinking for it to be turned into something useable.

---

<div class="post-metadata">

**Author:** ![toadspittle](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@toadspittle](https://boards.straightdope.com/u/toadspittle)\
**Post date:** [October 13, 2008, 9:49pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/12 "2008-10-13T21:49:35Z")

</div>

> [@Lobsang](#):
>
> Is there a variant of request.servervariables(“script\_name”) that gets the url without any passed data (nothing after the .asp)
> 
> It’s for a ‘back to data entry’ link. I don’t want to use the ‘reset’ way because that means extra code in places.

Not to my knowledge (not that it’s impossible … I’m no encyclopedia …). I would just [split](http://www.w3schools.com/vbscript/func_split.asp) the string at “.asp”, take Array(0), and re-concatenate it with a new “.asp” on the end.

---

<div class="post-metadata">

**Author:** ![toadspittle](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@toadspittle](https://boards.straightdope.com/u/toadspittle)\
**Post date:** [October 13, 2008, 9:52pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/13 "2008-10-13T21:52:27Z")

</div>

> [@Lobsang](#):
>
> If that works then perfect! I’ll use that in my template, and in the comments above I’ll put…
> 
> 'If you need to use this include add the ‘#’ key before ‘include’
> 
> Thanks again all. I am looking for this template to require the minimum of thinking for it to be turned into something useable.

Who will be viewing this template? If you might publish the page without activating the include, I’d recommend commenting it out with the leading apostrophe, instead. The way you do it above, anyone can see the name of your included file by choosing “view source” in their browser. The other way, it’s invisible. Just something to consider.

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [October 14, 2008, 3:27pm UTC](https://boards.straightdope.com/t/asp-correct-way-to-check-a-form-has-been-sent/467759/14 "2008-10-14T15:27:32Z")

</div>

> [@toadspittle](#):
>
> Who will be viewing this template? If you might publish the page without activating the include, I’d recommend commenting it out with the leading apostrophe, instead. The way you do it above, anyone can see the name of your included file by choosing “view source” in their browser. The other way, it’s invisible. Just something to consider.

Is it right for comments to be included as page source? Wouldn’t it be more sensible for the browser to leave them out?

Anyway, the template is likely only ever to be seen by me, but anyone who uses my creations (a medium size team of people) can, if they wanted to, view source and see what’s in those includes anyway… That is to say they’ll see the compiled HTML, not the ASP 😃

p.s. I’ll give your string manipulation idea a try.  
I think what I was asking might be possible in PHP but that isn’t much more than a guess.
