By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,971 Members | 900 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,971 IT Pros & Developers. It's quick & easy.

Stopping blank form fields being submitted.

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
Thank's to all who helped

Batezz

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.