469,590 Members | 2,312 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,590 developers. It's quick & easy.

Stopping blank form fields being submitted.

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
<?php
$redirect = "/Product/Productsearchresults.php";
if( empty($CityTown) && empty($County)) {$redirect="";}

?>
<body>
<form action="../Product/$redirect" method="post" name="location search"
id="location search">
<p>Location search</p>
<p>
<label>City/Town
<input name="CityTown" type="text" id="CityTown" />
</label>
</p>
<p>
<label>County
<input name="County" type="text" id="County" />
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Search" />
</label>
<label> </label>
</p>
</form>
</body>
Jul 17 '05 #1
5 7383
"Batezz" wrote:
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
<?php
$redirect = "/Product/Productsearchresults.php";
if( empty($CityTown) && empty($County)) {$redirect="";}

?>
<body>
<form action="../Product/$redirect" method="post" name="location search"
id="location search">
<p>Location search</p>
<p>
<label>City/Town
<input name="CityTown" type="text" id="CityTown" />
</label>
</p>
<p>
<label>County
<input name="County" type="text" id="County" />
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Search" />
</label>
<label> </label>
</p>
</form>
</body>


If you want to stop a form to be submitted, then you have to use
javascript. Use search engine to check for "javascript form
validation" or similar phrases. You donít have to know too much
about javascript usually, as you can cut and paste from code examples.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Stopping...ict141477.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=472987
Jul 17 '05 #2
On Thu, 19 Aug 2004 20:03:59 +0100, "Batezz"
<ba************@hotmail.com> wrote:
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?


<?php
[filter for valid chars in both variables]
if(($_POST['CityTown'] == "") && ($_POST['County'] == ""))
{
?>
[FORM]
<?php
) else (
[REDIRECT]
}
?>

--
------------------------------------------------------------------
- Stuart Millington ALL HTML e-mail rejected -
- mailto:ph***@dsv1.co.uk http://w3.z-add.co.uk/ -
begin OE is broken read MS knowledgebase Q265230
Jul 17 '05 #3
On 19 Aug 2004 15:39:17 -0400, steve <Us************@dbForumz.com>
wrote:
If you want to stop a form to be submitted, then you have to use
javascript.


Technically, "to stop it being submitted". However, to stop the
re-direct being actioned when J(ava)script is off, or not available,
it needs to be backed up with server-side validation.

--
------------------------------------------------------------------
- Stuart Millington ALL HTML e-mail rejected -
- mailto:ph***@dsv1.co.uk http://w3.z-add.co.uk/ -
begin OE is broken read MS knowledgebase Q265230
Jul 17 '05 #4
The best way to do this (in my opinion) is to submit to $PHP_SELF --
in your form make the value of each field $_POST['thename'] -- then
you can keep the submitted info in the form, and do a
if(!isset($_POST['name'])){echo "enter the info dummy";} -- this also
allows you to go a step further and do email verification etc..

Phil Palmieri
page12.com

steve <Us************@dbForumz.com> wrote in message news:<41**********@news.athenanews.com>...
"Batezz" wrote:
> 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
>
>
> <?php
> $redirect = "/Product/Productsearchresults.php";
> if( empty($CityTown) && empty($County)) {$redirect="";}
>
> ?>
>
>
> <body>
> <form action="../Product/$redirect" method="post"

name="location
> search"
> id="location search">
> <p>Location search</p>
> <p>
> <label>City/Town
> <input name="CityTown" type="text" id="CityTown" />
> </label>
> </p>
> <p>
> <label>County
> <input name="County" type="text" id="County" />
> </label>
> </p>
> <p>
> <label>
> <input type="submit" name="Submit" value="Search" />
> </label>
> <label> </label>
> </p>
> </form>
> </body>


If you want to stop a form to be submitted, then you have to use
javascript. Use search engine to check for "javascript form
validation" or similar phrases. You don?t have to know too much
about javascript usually, as you can cut and paste from code examples.

Jul 17 '05 #5
Thank's to all who helped

Batezz

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jerry Sievers | last post: by
1 post views Thread by Ittay Dror | last post: by
2 posts views Thread by Tim Mills | last post: by
7 posts views Thread by h7qvnk7q001 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.