Form validation

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

    Form validation

    I am a newbie to PHP and finding even the simple stuff quite hard.

    I am trying to validate an email address using a recursive page.

    The validation is done using a regular expression which works fine , and the
    valid/invalid messages shows as expected.

    My input tag is as follows:
    <input type="text" name="emailAddr ess" value="<?php
    $HTTP_POST_VARS['emailAddress'] ?>">

    When the page refreshes the input field is blank!

    How do retain the value typed?

    TIA

    Roger

  • Andy Hassall

    #2
    Re: Form validation

    On Fri, 6 Feb 2004 23:53:09 +0000 (UTC), Roger Price
    <roger_price@bt internet.com> wrote:
    [color=blue]
    >I am a newbie to PHP and finding even the simple stuff quite hard.
    >
    >I am trying to validate an email address using a recursive page.
    >
    >The validation is done using a regular expression which works fine , and the
    >valid/invalid messages shows as expected.
    >
    >My input tag is as follows:
    ><input type="text" name="emailAddr ess" value="<?php
    >$HTTP_POST_VAR S['emailAddress'] ?>">
    >
    >When the page refreshes the input field is blank!
    >
    >How do retain the value typed?[/color]

    You have:

    <?php $HTTP_POST_VARS['emailAddress'] ?>

    This does nothing. You probably mean:

    <?php echo htmlentities($_ POST['emailAddress']); ?>


    --
    Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
    <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>

    Comment

    • Yang Li Ke

      #3
      Re: Form validation

      do this:

      <input type="text" name="emailAddr ess" value="<? echo
      $HTTP_POST_VARS['emailAddress']; ?>">


      --


      "Roger Price" <roger_price@bt internet.com> wrote in message
      news:BC49D964.F E34%roger_price @btinternet.com ...[color=blue]
      > I am a newbie to PHP and finding even the simple stuff quite hard.
      >
      > I am trying to validate an email address using a recursive page.
      >
      > The validation is done using a regular expression which works fine , and[/color]
      the[color=blue]
      > valid/invalid messages shows as expected.
      >
      > My input tag is as follows:
      > <input type="text" name="emailAddr ess" value="<?php
      > $HTTP_POST_VARS['emailAddress'] ?>">
      >
      > When the page refreshes the input field is blank!
      >
      > How do retain the value typed?
      >
      > TIA
      >
      > Roger
      >[/color]


      Comment

      • Roger Price

        #4
        Re: Form validation

        Hi thanks for that which solves the question I asked. However when the page
        is requested for the first time the input field displays:

        <br /><b>Notice</b>: Undefined index: emailAddress in
        <b>d:\inetpub\w wwroot\Projects \group13\email. php</b> on line
        <b>50</b><br />

        Please do you have any suggestions?

        Roger



        in article VGXUb.24432$bp1 .771071@news20. bellglobal.com, Yang Li Ke at
        yanglike@sympat ico.ca wrote on 7/2/04 2:02 am:
        [color=blue]
        > do this:
        >
        > <input type="text" name="emailAddr ess" value="<? echo
        > $HTTP_POST_VARS['emailAddress']; ?>">
        >
        >
        > --
        >
        >
        > "Roger Price" <roger_price@bt internet.com> wrote in message
        > news:BC49D964.F E34%roger_price @btinternet.com ...[color=green]
        >> I am a newbie to PHP and finding even the simple stuff quite hard.
        >>
        >> I am trying to validate an email address using a recursive page.
        >>
        >> The validation is done using a regular expression which works fine , and[/color]
        > the[color=green]
        >> valid/invalid messages shows as expected.
        >>
        >> My input tag is as follows:
        >> <input type="text" name="emailAddr ess" value="<?php
        >> $HTTP_POST_VARS['emailAddress'] ?>">
        >>
        >> When the page refreshes the input field is blank!
        >>
        >> How do retain the value typed?
        >>
        >> TIA
        >>
        >> Roger
        >>[/color]
        >[/color]

        Comment

        • Filth

          #5
          Re: Form validation

          > Hi thanks for that which solves the question I asked. However when the
          page[color=blue]
          > is requested for the first time the input field displays:
          >
          > <br /><b>Notice</b>: Undefined index: emailAddress in
          > <b>d:\inetpub\w wwroot\Projects \group13\email. php</b> on line
          > <b>50</b><br />
          >
          > Please do you have any suggestions?
          >[/color]

          <input type="text" name="emailAddr ess" value="<? if (isset
          ($HTTP_POST_VAR S['emailAddress']; )){echo $HTTP_POST_VARS['emailAddress']};
          ?>">


          Comment

          • Roger Price

            #6
            Re: Form validation

            Hi Filth (interesting name!)

            It never occurred to me that it was possible to include a conditional inside
            an attribute value. You can learn so much that they never show you in the
            books on lists like this.

            The code did not work first time as the ";" did not seem to be in the
            correct place!

            The following worked though:

            <input type="text" name="emailAddr ess" value="<?php if (isset
            ($HTTP_POST_VAR S['emailAddress'] )){echo $HTTP_POST_VARS['emailAddress'];}
            ?>">

            The web server is IIS 5.0 which does not seem to like the "<?=...?>
            shortened form so "<?php" works better.

            Thank you

            Roger
            --

            Roger Price

            Email: roger_price@bti nternet.com



            in article PY7Vb.4453$P32. 286@news-binary.blueyond er.co.uk, Filth at
            p.macdonald@blu eyonder.co.uk wrote on 7/2/04 4:00 pm:
            [color=blue]
            >
            > <input type="text" name="emailAddr ess" value="<? if (isset
            > ($HTTP_POST_VAR S['emailAddress']; )){echo $HTTP_POST_VARS['emailAddress']};
            > ?>">
            >
            >[/color]

            Comment

            • Filth

              #7
              Re: Form validation

              [color=blue]
              > <input type="text" name="emailAddr ess" value="<?php if (isset
              > ($HTTP_POST_VAR S['emailAddress'] )){echo $HTTP_POST_VARS['emailAddress'];}
              > ?>">
              >
              > The web server is IIS 5.0 which does not seem to like the "<?=...?>
              > shortened form so "<?php" works better.[/color]

              Doh!!! thats what happens when you cut and paste forgot to delete the ;, you
              should always use <?php as it works on all set ups <? doesnt amongst several
              other variations.


              Comment

              Working...