473,322 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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($_POST[$action])){ ?>
<input name="action" type="hidden" value="nomatter">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><form action="submitsite.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.
Jul 17 '05 #1
4 4458

Uzytkownik "Bruce W...1" <br***@noDirectEmail.com> napisal w wiadomosci
news:3F***************@noDirectEmail.com...
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($_POST[$action])){ ?>
<input name="action" type="hidden" value="nomatter">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><form action="submitsite.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.

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.
Jul 17 '05 #2
lecichy wrote:

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.

================================================== =========

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.
Jul 17 '05 #3
lecichy wrote:
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.


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("name", "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.
Jul 17 '05 #4
Never mind all. I got it to work. Just had to remove the action from
the form.

<form action="" method="post">
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: rbt | last post by:
Here's the scenario: You have many hundred gigabytes of data... possible even a terabyte or two. Within this data, you have private, sensitive information (US social security numbers) about your...
12
by: Barnes | last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form? Here is the scenario: I have a form that cannot accept apostrophes. I want to use the replace() so...
2
by: Jack | last post by:
Hi, I got a simple form where one needs to input data. The data is being processed in an asp page. However, I cannot figure out why couple of values I am typing in the form is not being retrived...
9
by: Bernd.Moos | last post by:
Given the following XML document: <text> <p> <w>Ronaldo</w> <w>scoredw> <w>the</w> <w>1</w> <c>:</c> <w>1</w>
26
by: Stav | last post by:
Hi there. I'm working on an application that currently uses DAO to connect to an Access 97 database. The database is created by and used exclusively by the product to store search results and...
5
by: donet programmer | last post by:
Wondering if anybody knows how to get around this problem ... I am creating a "Please wait..." page to show a friendly message to my site users while the data is being loaded. I am using...
4
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays...
22
by: Zytan | last post by:
I have public methods in a form. The main form calls them, to update that form's display. This form is like a real-time view of data that is changing. But, the form may not exist (it is...
5
by: Rachel Garrett | last post by:
If I created a Recordset in VBA, how do I make certain fields show up in a form?
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.