Stopping blank form fields being submitted.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Batezz

    Stopping blank form fields being submitted.

    I have created a form (below)

    How do I stop it redirecting to another page (productsearchr esults.php) when
    form is submitted if both the fields are blank?

    Any help appreciated.

    Batezz


    <?php
    $redirect = "/Product/Productsearchre sults.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>


  • steve

    #2
    Re: Stopping blank form fields being submitted.

    "Batezz" wrote:[color=blue]
    > I have created a form (below)
    >
    > How do I stop it redirecting to another page
    > (productsearchr esults.php) when
    > form is submitted if both the fields are blank?
    >
    > Any help appreciated.
    >
    > Batezz
    >
    >
    > <?php
    > $redirect = "/Product/Productsearchre sults.php";
    > if( empty($CityTown ) && empty($County)) {$redirect="";}
    >
    > ?>
    >
    >
    > <body>
    > <form action="../Product/$redirect" method="post"[/color]
    name="location[color=blue]
    > 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>[/color]

    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

    Comment

    • Stuart Millington

      #3
      Re: Stopping blank form fields being submitted.

      On Thu, 19 Aug 2004 20:03:59 +0100, "Batezz"
      <batezzSPAMTRAP @hotmail.com> wrote:
      [color=blue]
      >I have created a form (below)
      >How do I stop it redirecting to another page (productsearchr esults.php) when
      >form is submitted if both the fields are blank?[/color]

      <?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:phupp@ds v1.co.uk http://w3.z-add.co.uk/ -
      begin OE is broken read MS knowledgebase Q265230

      Comment

      • Stuart Millington

        #4
        Re: Stopping blank form fields being submitted.

        On 19 Aug 2004 15:39:17 -0400, steve <UseLinkToEmail @dbForumz.com>
        wrote:
        [color=blue]
        >If you want to stop a form to be submitted, then you have to use
        >javascript.[/color]

        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:phupp@ds v1.co.uk http://w3.z-add.co.uk/ -
        begin OE is broken read MS knowledgebase Q265230

        Comment

        • Page12

          #5
          Re: Stopping blank form fields being submitted.

          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($_POS T['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 <UseLinkToEmail @dbForumz.com> wrote in message news:<412501e5$ 1_6@news.athena news.com>...[color=blue]
          > "Batezz" wrote:[color=green]
          > > I have created a form (below)
          > >
          > > How do I stop it redirecting to another page
          > > (productsearchr esults.php) when
          > > form is submitted if both the fields are blank?
          > >
          > > Any help appreciated.
          > >
          > > Batezz
          > >
          > >
          > > <?php
          > > $redirect = "/Product/Productsearchre sults.php";
          > > if( empty($CityTown ) && empty($County)) {$redirect="";}
          > >
          > > ?>
          > >
          > >
          > > <body>
          > > <form action="../Product/$redirect" method="post"[/color]
          > name="location[color=green]
          > > 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>[/color]
          >
          > 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.[/color]

          Comment

          • Batezz

            #6
            Thank you all

            Thank's to all who helped

            Batezz



            Comment

            Working...