How to replace a form with tesxt after it is processed?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bruce W...1

    How to replace a form with tesxt after it is processed?

    My PHP html file includes a header include, a form, and a footer include. After
    the user submits their information I want to replace the form part of the page
    with a thank you note.

    All the code for processing the form is in another file called submitsite.php,
    at the bottom of which I echo "Thank you".

    This is in the html file:
    <?php include 'head.php' ?>
    <?php if(!isset($_POS T[$action])){ ?>
    <input name="action" type="hidden" value="nomatter ">
    <table width="600" border="0" cellspacing="0" cellpadding="0" >
    <tr>
    <td><form action="submits ite.php" method="post">
    textboxes etc....
    </table>
    </form>
    <?php } ?>
    <?php include 'foot.php' ?>

    After the user submits the form they are redirected to submitsite.php and see
    "Thank you" without the header and footer.

    How do I redirect back to the original page, so they see the same URL, header,
    and footer, but with the form replaced with "Thank you"?

    Thanks for your help.
  • lecichy

    #2
    Re: How to replace a form with tesxt after it is processed?


    Uzytkownik "Bruce W...1" <bruce@noDirect Email.com> napisal w wiadomosci
    news:3F8725FF.C F97A9DC@noDirec tEmail.com...[color=blue]
    > My PHP html file includes a header include, a form, and a footer include.[/color]
    After[color=blue]
    > the user submits their information I want to replace the form part of the[/color]
    page[color=blue]
    > with a thank you note.
    >
    > All the code for processing the form is in another file called[/color]
    submitsite.php,[color=blue]
    > at the bottom of which I echo "Thank you".
    >
    > This is in the html file:
    > <?php include 'head.php' ?>
    > <?php if(!isset($_POS T[$action])){ ?>
    > <input name="action" type="hidden" value="nomatter ">
    > <table width="600" border="0" cellspacing="0" cellpadding="0" >
    > <tr>
    > <td><form action="submits ite.php" method="post">
    > textboxes etc....
    > </table>
    > </form>
    > <?php } ?>
    > <?php include 'foot.php' ?>
    >
    > After the user submits the form they are redirected to submitsite.php and[/color]
    see[color=blue]
    > "Thank you" without the header and footer.
    >
    > How do I redirect back to the original page, so they see the same URL,[/color]
    header,[color=blue]
    > and footer, but with the form replaced with "Thank you"?
    >
    > Thanks for your help.[/color]


    I do such forms sites in one .php file.

    Let's say we got a "Name:" field somewhere in the form that gives us
    variable $name when filled.
    PHP file generally looks like (starts with condition):

    if (name != "") { // means page is reloaded after filling the form with
    variables so they can be processed

    php_processing_ code

    echo "Thank You!";

    } else { // if one or all variables are empty, (it means
    that form is about to be filled, so it prints form.)

    echo ("
    html_form
    ");
    }

    This way when the page is opended ther's no var $name provided so the php
    code is not executed and site is just an empty form. When $name and other
    fields are filled php takes care of processing and what is shown is "Thank
    You". Ofcourse Its all one file e.g index.php with html form and php
    processing code and form action is index.php so it is just reloading page wi
    th supplied data.


    Comment

    • Bruce W...1

      #3
      Re: How to replace a form with tesxt after it is processed?

      lecichy wrote:[color=blue]
      >
      > I do such forms sites in one .php file.
      >
      > Let's say we got a "Name:" field somewhere in the form that gives us
      > variable $name when filled.
      > PHP file generally looks like (starts with condition):
      >
      > if (name != "") { // means page is reloaded after filling the form with
      > variables so they can be processed
      >
      > php_processing_ code
      >
      > echo "Thank You!";
      >
      > } else { // if one or all variables are empty, (it means
      > that form is about to be filled, so it prints form.)
      >
      > echo ("
      > html_form
      > ");
      > }
      >
      > This way when the page is opended ther's no var $name provided so the php
      > code is not executed and site is just an empty form. When $name and other
      > fields are filled php takes care of processing and what is shown is "Thank
      > You". Ofcourse Its all one file e.g index.php with html form and php
      > processing code and form action is index.php so it is just reloading page wi
      > th supplied data.[/color]
      =============== =============== =============== ==============

      It would be easy to put everthing in one file. But I'm trying to
      separate code from html.

      What I don't understand is this. On post or postback the file includes
      the header file then goes to an if/else. If first time it displays the
      form (in the same file). If postback it should display the header then
      execute the code in the other file which sends an email and says "Thank
      you". After this code executes (and says "Thank you") it should return
      and display the footer include.

      Sequentially, if it didn't return it should display the header and
      "Thank you", but not the footer. But NO! It doesn't display the header
      or footer, just "Thank you" from the file which sends the email.

      The code branching here is all messed up. Maybe I should be taking a
      more OOP approach but I doubt that would help any.

      Comment

      • Dalibor Karlovic

        #4
        Re: How to replace a form with tesxt after it is processed?

        lecichy wrote:
        [color=blue]
        > I do such forms sites in one .php file.
        >
        > Let's say we got a "Name:" field somewhere in the form that gives us
        > variable $name when filled.[/color]

        This is how I used to do it, but got sick of it. Then I wrote my own form
        generation and validation class...

        <?php
        $oForm = new form;
        if ($oForm->validate()){
        /*
        do foo with form-submited data which looks like something we wanted
        this block will get executed only when form is submited and valid
        */
        } else {
        // build form
        $oForm->addText("name" , "value");
        $oForm->addButton("nam e", "value");
        // etc.
        }
        ?>

        If you get used to build the form after it has been validated (looks kinda
        weird at first but works wery well), you can build complex forms very easy.

        I recommend using that approach. Free classes are waiting to be downloaded
        :)

        --
        Dado

        Never settle with words what you can accomplish with a flame thrower.

        Comment

        • Bruce W...1

          #5
          Re: How to replace a form with tesxt after it is processed?

          Never mind all. I got it to work. Just had to remove the action from
          the form.

          <form action="" method="post">

          Comment

          Working...