By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

How do I setup php script to return a browser page?

P: n/a
Don
I want the server-side php script to return a browser page that is essentially a copy of the
original client page that contained the <form> which referenced the php script in the first place.
However, the php script will need to change a couple html lines in that returned page. I sure could
you some help on how to go about this.

Thanks in advance,
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Don
On Mon, 11 Oct 2004 10:07:20 -0700, Don <no@adr.com> wrote:
I want the server-side php script to return a browser page that is essentially a copy of the
original client page that contained the <form> which referenced the php script in the first place.
However, the php script will need to change a couple html lines in that returned page. I sure could
you some help on how to go about this.

Thanks in advance,
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


Guess what I really need to know is how should I construct the form's <input> tag, using a hidden
field, to pass the client page as an array. And, how should the server-side php script retrieve and
print it to the returned browser page? I'm still pretty new at html and php programming. Sure
would appreciate a little help with this.

Thanks in advance,
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 17 '05 #2

P: n/a

"Don" <no@adr.com> wrote in message
news:8g********************************@4ax.com...
On Mon, 11 Oct 2004 10:07:20 -0700, Don <no@adr.com> wrote:
I want the server-side php script to return a browser page that is
essentially a copy of the
original client page that contained the <form> which referenced the php
script in the first place.
However, the php script will need to change a couple html lines in that
returned page. I sure could
you some help on how to go about this.

Thanks in advance,
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


Guess what I really need to know is how should I construct the form's
<input> tag, using a hidden
field, to pass the client page as an array. And, how should the
server-side php script retrieve and
print it to the returned browser page? I'm still pretty new at html and
php programming. Sure
would appreciate a little help with this.

Thanks in advance,
Don


Hi Don,
I'm not sure I have understood you, but here is a quick sample form.
Save the form to a file called 'TestForm.php' or it will not work correctly
(unless you also modify the post action field). The form just displays 2
fields to enter a forname and surname. A hidden field called 'action' is
used to tell the form to redisplay the post data.

So basically, when the form is submitted, the post data is used for the
value fields of the text boxes. This technique should be able to be easily
adapted to your needs. Note the 'addslashes' will protect your database from
abuse assuming the data will go into a database at some point. This is just
a quick and dirty sample, but should give you a general idea of what to do.

Martin

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Test Form</TITLE>
</HEAD>
<BODY>

<form method="post" action="TestForm.php" NAME="form1" >
<table WIDTH="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0>

<?php

function AddTextField($Description, $Name, $Length, $value)
{
echo "<tr>";
echo '<td align="right" width="250">';

echo '<b>' . $Description . '&nbsp;</b></td>';

echo '<td align="left"><input type="text" class="formfield"
size="27" maxlength=' . $Length;
echo ' name="' . $Name . '" id="' . $Name . '" value="' . $value .
'"></td>';
echo "</tr>";
}

// 'action' will only be 'modify' after the submit button has
// been pressed for the first time
if ($_POST['action'] == 'modify')
{
AddTextField('First Name', 'Forname', 20, $_POST['Forname']);
AddTextField('Last Name', 'Surname', 20, $_POST['Surname']);
$Forname = addslashes($_POST['Forname']);
$Surname = addslashes($_POST['Surname']);

// validate and use data here
}
else
{
AddTextField('First Name', 'Forname', 20, '');
AddTextField('Last Name', 'Surname', 20, '');
}

?>

<tr>
<td align="center" width="600">
<br>
<input type="hidden" name="action" id="idName" value="modify">
<br>
<input type="submit" name="Submit" value="Submit" class="formfield"
border="0" WIDTH="79" HEIGHT="25">
<td>
<tr>
</table>
</form>
</body>
</html>
Jul 17 '05 #3

P: n/a
Don
On Mon, 11 Oct 2004 23:07:50 +0100, "Martin Cooper" <us********@martinc.me.uk> wrote:

"Don" <no@adr.com> wrote in message
news:8g********************************@4ax.com.. .
On Mon, 11 Oct 2004 10:07:20 -0700, Don <no@adr.com> wrote:
I want the server-side php script to return a browser page that is
essentially a copy of the
original client page that contained the <form> which referenced the php
script in the first place.
However, the php script will need to change a couple html lines in that
returned page. I sure could
you some help on how to go about this.

Thanks in advance,
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


Guess what I really need to know is how should I construct the form's
<input> tag, using a hidden
field, to pass the client page as an array. And, how should the
server-side php script retrieve and
print it to the returned browser page? I'm still pretty new at html and
php programming. Sure
would appreciate a little help with this.

Thanks in advance,
Don


Hi Don,
I'm not sure I have understood you, but here is a quick sample form.
Save the form to a file called 'TestForm.php' or it will not work correctly
(unless you also modify the post action field). The form just displays 2
fields to enter a forname and surname. A hidden field called 'action' is
used to tell the form to redisplay the post data.

So basically, when the form is submitted, the post data is used for the
value fields of the text boxes. This technique should be able to be easily
adapted to your needs. Note the 'addslashes' will protect your database from
abuse assuming the data will go into a database at some point. This is just
a quick and dirty sample, but should give you a general idea of what to do.

Martin

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Test Form</TITLE>
</HEAD>
<BODY>

<form method="post" action="TestForm.php" NAME="form1" >
<table WIDTH="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0>

<?php

function AddTextField($Description, $Name, $Length, $value)
{
echo "<tr>";
echo '<td align="right" width="250">';

echo '<b>' . $Description . '&nbsp;</b></td>';

echo '<td align="left"><input type="text" class="formfield"
size="27" maxlength=' . $Length;
echo ' name="' . $Name . '" id="' . $Name . '" value="' . $value .
'"></td>';
echo "</tr>";
}

// 'action' will only be 'modify' after the submit button has
// been pressed for the first time
if ($_POST['action'] == 'modify')
{
AddTextField('First Name', 'Forname', 20, $_POST['Forname']);
AddTextField('Last Name', 'Surname', 20, $_POST['Surname']);
$Forname = addslashes($_POST['Forname']);
$Surname = addslashes($_POST['Surname']);

// validate and use data here
}
else
{
AddTextField('First Name', 'Forname', 20, '');
AddTextField('Last Name', 'Surname', 20, '');
}

?>

<tr>
<td align="center" width="600">
<br>
<input type="hidden" name="action" id="idName" value="modify">
<br>
<input type="submit" name="Submit" value="Submit" class="formfield"
border="0" WIDTH="79" HEIGHT="25">
<td>
<tr>
</table>
</form>
</body>
</html>

Thanks very much Martin. I really appreciate you taking the time to put together the code. I'm
starting to get a pretty fair handle on HTML and JS, but this one has really got me. I'll study
this and give it a try. I'll let you know how it goes.

Regards, Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 17 '05 #4

P: n/a
Don
On Mon, 11 Oct 2004 23:07:50 +0100, "Martin Cooper" <us********@martinc.me.uk> wrote:

"Don" <no@adr.com> wrote in message
news:8g********************************@4ax.com.. .
On Mon, 11 Oct 2004 10:07:20 -0700, Don <no@adr.com> wrote:
I want the server-side php script to return a browser page that is
essentially a copy of the
original client page that contained the <form> which referenced the php
script in the first place.
However, the php script will need to change a couple html lines in that
returned page. I sure could
you some help on how to go about this.

Thanks in advance,
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


Guess what I really need to know is how should I construct the form's
<input> tag, using a hidden
field, to pass the client page as an array. And, how should the
server-side php script retrieve and
print it to the returned browser page? I'm still pretty new at html and
php programming. Sure
would appreciate a little help with this.

Thanks in advance,
Don


Hi Don,
I'm not sure I have understood you, but here is a quick sample form.
Save the form to a file called 'TestForm.php' or it will not work correctly
(unless you also modify the post action field). The form just displays 2
fields to enter a forname and surname. A hidden field called 'action' is
used to tell the form to redisplay the post data.

So basically, when the form is submitted, the post data is used for the
value fields of the text boxes. This technique should be able to be easily
adapted to your needs. Note the 'addslashes' will protect your database from
abuse assuming the data will go into a database at some point. This is just
a quick and dirty sample, but should give you a general idea of what to do.

Martin

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Test Form</TITLE>
</HEAD>
<BODY>

<form method="post" action="TestForm.php" NAME="form1" >
<table WIDTH="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0>

<?php

function AddTextField($Description, $Name, $Length, $value)
{
echo "<tr>";
echo '<td align="right" width="250">';

echo '<b>' . $Description . '&nbsp;</b></td>';

echo '<td align="left"><input type="text" class="formfield"
size="27" maxlength=' . $Length;
echo ' name="' . $Name . '" id="' . $Name . '" value="' . $value .
'"></td>';
echo "</tr>";
}

// 'action' will only be 'modify' after the submit button has
// been pressed for the first time
if ($_POST['action'] == 'modify')
{
AddTextField('First Name', 'Forname', 20, $_POST['Forname']);
AddTextField('Last Name', 'Surname', 20, $_POST['Surname']);
$Forname = addslashes($_POST['Forname']);
$Surname = addslashes($_POST['Surname']);

// validate and use data here
}
else
{
AddTextField('First Name', 'Forname', 20, '');
AddTextField('Last Name', 'Surname', 20, '');
}

?>

<tr>
<td align="center" width="600">
<br>
<input type="hidden" name="action" id="idName" value="modify">
<br>
<input type="submit" name="Submit" value="Submit" class="formfield"
border="0" WIDTH="79" HEIGHT="25">
<td>
<tr>
</table>
</form>
</body>
</html>


Martin,

I studied the script and think I understand how it works. However, the client-side page in my case
is dynamically built using JS, so it isn't as simple as storing the page on the server as you
suggest. I really need to submit the page's initial <form> to server A, along with all the page
content via an array, have server A process the form, and rebuild (via print) the client-side page
that came along, modify the embedded <form> to address server B. Then, when server A has finished
processing the initial <form> it will return the initial client-side page, with the modified <form>.
That modified <form> will have an onload event handler, so it will fire without client intervention.
All of this happens as a result of the client clicking one and only one submit button.

By the way, the initial <form> uploads one or more files to server A. And, the second <form> just
submits some data to server B. Server B will return an appropriate browser page.

I just don't know how to pass the client-side page to server A, via an <input type=hidden...> using
an array. And, I don't know how to retrieve it in the PHP script on the server.

What do you think?
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 17 '05 #5

P: n/a

<snip>

Martin,

I studied the script and think I understand how it works. However, the
client-side page in my case
is dynamically built using JS, so it isn't as simple as storing the page
on the server as you
suggest. I really need to submit the page's initial <form> to server A,
along with all the page
content via an array, have server A process the form, and rebuild (via
print) the client-side page
that came along, modify the embedded <form> to address server B. Then,
when server A has finished
processing the initial <form> it will return the initial client-side page,
with the modified <form>.
That modified <form> will have an onload event handler, so it will fire
without client intervention.
All of this happens as a result of the client clicking one and only one
submit button.

By the way, the initial <form> uploads one or more files to server A.
And, the second <form> just
submits some data to server B. Server B will return an appropriate
browser page.

I just don't know how to pass the client-side page to server A, via an
<input type=hidden...> using
an array. And, I don't know how to retrieve it in the PHP script on the
server.

What do you think?
Don


Hi Don,
I can't think of a way to submit the complete page, but you could write
an event handler for the 'onsubmit' event in javascript that would parse the
page, gather the information you required from the page, and create a series
of post fields each containing a peice of the information.

Sorry, I'm not familiar enough with javascript to tell you exactly how, but
once you have gathered the info, embed each peice of data in a hidden field
called 'arrayXXXXX' where XXXXX is an incrimenting number. This would
arrive on the server in the _POST array. You can then parse the post array
with a foreach loop such as :-

foreach ($_POST as $key=>$value)
{
if (preg_match ("/^array([0-9\-]+)/i", $key, $matches))
{
$array[$matches[1]] = $value;
}
}

// process data here

So after this script has run, the various post elements (each having a
unique number generated by javascript) would be accessable via a standard
PHP array containing the data gathered from the webpage by the javascript.

The javascript would have to recursively parse the DOM, gathering the needed
information as it went from the document.

In the DOM, as you probably know, each HTML tag is accessable, so by
recusring through the entire page, you can build an array for the post that
contains a copy of every part of the page. By submitting these with an
incrimenting number, the foreach loop above could be used to reconstruct the
page. For the javascript side, take a look at
http://www.webreference.com/programm.../chap17/6.html
for a recursive function that can traverse the entire document.

This may not be the only way, but I can't think of an easier way right now.

Martin
Jul 17 '05 #6

P: n/a
red
Don wrote:
On Mon, 11 Oct 2004 10:07:20 -0700, Don <no@adr.com> wrote:

I want the server-side php script to return a browser page that is essentially a copy of the
original client page that contained the <form> which referenced the php script in the first place.
However, the php script will need to change a couple html lines in that returned page. I sure could
you some help on how to go about this.

Thanks in advance,
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---

Guess what I really need to know is how should I construct the form's <input> tag, using a hidden
field, to pass the client page as an array. And, how should the server-side php script retrieve and
print it to the returned browser page? I'm still pretty new at html and php programming. Sure
would appreciate a little help with this.

Thanks in advance,
Don

Maybe I don't understand the question, but I don't see why you need a
hidden feild for this or why you need to pass the entire page at all.
Instead of passing the page, just make the part you want to use again
appear again after the changes are submitted. Save this as test.php:
<?
if($_POST[submit]){
$value =$_POST[value];
}
else $value="This is the value which will appear on the original
page but which will be changed after the form is submitted";

?>
<form action="/test/test.php" method="post" enctype="multipart/form-data">
<input type="text" name="value"><input type="submit" name="submit"
value="submit">
</form>
This part of the page will appear before and after the page is changed<br>
<?
echo $value;
?>
Jul 17 '05 #7

P: n/a
red
red wrote:
Don wrote:
On Mon, 11 Oct 2004 10:07:20 -0700, Don <no@adr.com> wrote:

I want the server-side php script to return a browser page that is
essentially a copy of the
original client page that contained the <form> which referenced the
php script in the first place.
However, the php script will need to change a couple html lines in
that returned page. I sure could
you some help on how to go about this.

Thanks in advance,
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World!
>100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


Guess what I really need to know is how should I construct the form's
<input> tag, using a hidden
field, to pass the client page as an array. And, how should the
server-side php script retrieve and
print it to the returned browser page? I'm still pretty new at html
and php programming. Sure
would appreciate a little help with this.

Thanks in advance,
Don


Maybe I don't understand the question, but I don't see why you need a
hidden feild for this or why you need to pass the entire page at all.
Instead of passing the page, just make the part you want to use again
appear again after the changes are submitted. Save this as test.php:

actually I meant to post this simpler version:
<form action="/test/test.php" method="post" enctype="multipart/form-data">
<input type="text" name="value"><input type="submit" name="submit"
value="submit">
</form>
This part of the page will appear before and after the page is changed<br>
<?
if($_POST[submit]){
echo $_POST[value];
}
else echo "This is the value which will appear on the original page
but which will be changed on the second page";

?>
Jul 17 '05 #8

P: n/a
Don
On Tue, 12 Oct 2004 14:18:43 GMT, red <gr*****@reenie.org> wrote:
red wrote:
Don wrote:
On Mon, 11 Oct 2004 10:07:20 -0700, Don <no@adr.com> wrote:
I want the server-side php script to return a browser page that is
essentially a copy of the
original client page that contained the <form> which referenced the
php script in the first place.
However, the php script will need to change a couple html lines in
that returned page. I sure could
you some help on how to go about this.

Thanks in advance,
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World!
>100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---

Guess what I really need to know is how should I construct the form's
<input> tag, using a hidden
field, to pass the client page as an array. And, how should the
server-side php script retrieve and
print it to the returned browser page? I'm still pretty new at html
and php programming. Sure
would appreciate a little help with this.

Thanks in advance,
Don


Maybe I don't understand the question, but I don't see why you need a
hidden feild for this or why you need to pass the entire page at all.
Instead of passing the page, just make the part you want to use again
appear again after the changes are submitted. Save this as test.php:

actually I meant to post this simpler version:
<form action="/test/test.php" method="post" enctype="multipart/form-data">
<input type="text" name="value"><input type="submit" name="submit"
value="submit">
</form>
This part of the page will appear before and after the page is changed<br>
<?
if($_POST[submit]){
echo $_POST[value];
}
else echo "This is the value which will appear on the original page
but which will be changed on the second page";

?>


Thanks very much. I'll give it a try. Appreciate your help.
Regards, Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 17 '05 #9

P: n/a
red
Don wrote:


Thanks very much. I'll give it a try. Appreciate your help.
Regards, Don

Just so you know, you don't need the enctype="multipart/form-data" I
accidently left in the form in my last post.Here it is again:

<form action="/test/test.php" method="post">
<input type="text" name="value">
<input type="submit" name="submit" value="submit">
</form>
This part of the page will appear before and after the page is changed<br>
<?
if($_POST[submit]){
echo $_POST[value];
}
else echo "This is the value which will appear on the original page
but which will be changed on the second page";

?>
Jul 17 '05 #10

P: n/a
Don
On Tue, 12 Oct 2004 15:19:27 GMT, red <gr*****@reenie.org> wrote:
Don wrote:


Thanks very much. I'll give it a try. Appreciate your help.
Regards, Don

Just so you know, you don't need the enctype="multipart/form-data" I
accidently left in the form in my last post.Here it is again:

<form action="/test/test.php" method="post">
<input type="text" name="value">
<input type="submit" name="submit" value="submit">
</form>
This part of the page will appear before and after the page is changed<br>
<?
if($_POST[submit]){
echo $_POST[value];
}
else echo "This is the value which will appear on the original page
but which will be changed on the second page";

?>

Thank you!
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.