Re-draw a form with user's input.

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

    Re-draw a form with user's input.

    Hi everybody!

    Please help me with this problem. I try to write code for server side
    data validation. Initially, I have a html file called "form.html" which
    just contains all the necessary fields for user to submit their contact
    info (name, phone, email, address.....etc ...). All user's input will be
    sent to "processForm.ph p" using POST. In processForm.php , I want to be
    able to re-display the form in "form.html" with valid user's input and
    error message on top of the form in case user enter invalid data.
    Currently, a simple code that I could think of is the following:

    <?php

    if (!empty($_POST['submit']))
    {
    $isAllValid = false;


    //Check for invalid data
    //Code for checking data will be written here.

    //Invalid data occur.
    if(!$isAllValid )
    {
    include("form.h tml");

    //set user's input in the form's fields. How to access
    //form's field form here ?
    }
    }
    else
    {
    echo "User not submit";
    }

    ?>


    My questions are:

    1. Is there a way to access the form's fields in "form.html" to set
    their values ? (given all the form's fields in form.html have unique
    name)

    2. If (1) is not doable, then how would I this in PHP ?

    Thank you in advance !!

    Jay Hana

  • larry@portcommodore.com

    #2
    Re: Re-draw a form with user's input.

    roll the form in with the validation

    check for $_POST
    - (process form data/validate, etc)
    - (if valid add to DB, use HEADER to exit)
    check for $_GET
    - (create default/blank data or read in data from database)
    HTML headings
    HTML
    - HTML form with PHP 'echo()' statements to put in data from above and
    validation clues)

    It is a bit more complex, but that is the basics of how to organize the
    file.

    larry

    Comment

    • Jay

      #3
      Re: Re-draw a form with user's input.

      Dear Larry,

      It's me again. Thanks for your quick response, but I am still stuck.
      [color=blue]
      > - (create default/blank data or read in data from database)
      > HTML headings
      > HTML[/color]

      I don't want to add data to Database unless all data are valid.
      [color=blue]
      > - HTML form with PHP 'echo()' statements to put in data from above and
      > validation clues)[/color]

      I don't want to re-write the HTML code for the form. That's why I use
      include("form.h tml") in the processForm.php .

      I think you misunderstood my question. I try to access form's field
      within processForm.php page. For example,

      Using document.getEle mentByID('eleme nt') to set the values of the
      form's fields. May I do that ?

      Thanks again,

      Jay Hana

      Comment

      • Jerry Stuckle

        #4
        Re: Re-draw a form with user's input.

        Jay wrote:[color=blue]
        >
        >
        > I don't want to add data to Database unless all data are valid.
        >[/color]
        That's standard.
        [color=blue]
        >[color=green]
        >>- HTML form with PHP 'echo()' statements to put in data from above and
        >>validation clues)[/color]
        >
        >
        > I don't want to re-write the HTML code for the form. That's why I use
        > include("form.h tml") in the processForm.php .
        >[/color]

        Then include the echo statements in the form itself. Just ensure the variables
        are set to an empty string ('');

        [color=blue]
        > I think you misunderstood my question. I try to access form's field
        > within processForm.php page. For example,
        >
        > Using document.getEle mentByID('eleme nt') to set the values of the
        > form's fields. May I do that ?
        >[/color]

        No you can't. PHP knows nothing about the HTML. Larry's response was correct
        and accurate.
        [color=blue]
        > Thanks again,
        >
        > Jay Hana
        >[/color]


        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Kimmo Laine

          #5
          Re: Re-draw a form with user's input.

          "Jay" <goofyfish@gmai l.com> kirjoitti
          viestissä:11203 44469.430289.22 0610@g14g2000cw a.googlegroups. com...[color=blue]
          > Hi everybody!
          >
          > Please help me with this problem. I try to write code for server side
          > data validation. Initially, I have a html file called "form.html" which
          > just contains all the necessary fields for user to submit their contact
          > info (name, phone, email, address.....etc ...). All user's input will be
          > sent to "processForm.ph p" using POST. In processForm.php , I want to be
          > able to re-display the form in "form.html" with valid user's input and
          > error message on top of the form in case user enter invalid data.
          > Currently, a simple code that I could think of is the following:
          >
          > <?php
          >
          > if (!empty($_POST['submit']))
          > {
          > $isAllValid = false;
          >
          >
          > //Check for invalid data
          > //Code for checking data will be written here.
          >
          > //Invalid data occur.
          > if(!$isAllValid )
          > {
          > include("form.h tml");
          >
          > //set user's input in the form's fields. How to access
          > //form's field form here ?
          > }
          > }
          > else
          > {
          > echo "User not submit";
          > }
          >
          > ?>
          >
          >
          > My questions are:
          >
          > 1. Is there a way to access the form's fields in "form.html" to set
          > their values ? (given all the form's fields in form.html have unique
          > name)
          >
          > 2. If (1) is not doable, then how would I this in PHP ?[/color]


          Simply set the value attribute of each field.

          <input type="text" name="foo" value="<?= $_GET['foo'] ?>">

          I'd say it works even though the file is called form.html, since you are
          including the page, not passing it thru. In that case php tags should be
          executed...

          --
          "I am pro death penalty. That way people learn
          their lesson for the next time." -- Britney Spears

          eternal.erectio nN0@5P4Mgmail.c om


          Comment

          • SAndrejev@gmail.com

            #6
            Re: Re-draw a form with user's input.

            I'm new to web programming but i think that you can make a function,
            somthing like print_content($ error) which will be printed if you open
            the page for the first time or if validation didn't pass(then you will
            probably would like to pass #error variable)

            Comment

            • Manuel Lemos

              #7
              Re: Re-draw a form with user's input.

              Hello,

              on 07/03/2005 03:23 PM SAndrejev@gmail .com said the following:[color=blue]
              > I'm new to web programming but i think that you can make a function,
              > somthing like print_content($ error) which will be printed if you open
              > the page for the first time or if validation didn't pass(then you will
              > probably would like to pass #error variable)[/color]

              That is the way this forms validation and generation works. You post the
              form to the same page where it is presented. If it was submitted the
              class can validate the form values. If there is an invalid field, the
              form may be presented again with information about the invalid fields.




              --

              Regards,
              Manuel Lemos

              PHP Classes - Free ready to use OOP components written in PHP
              Free PHP Classes and Objects 2025 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials


              PHP Reviews - Reviews of PHP books and other products


              Metastorage - Data object relational mapping layer generator

              Comment

              Working...