473,405 Members | 2,187 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,405 software developers and data experts.

How to process text from HTML form?

This may be a basic question -

I have a form on my web page that looks like this:

<span id="site_search">
<form name="frmSearch" method="post" action="" style=" margin: 0 0 0
15px ">
Search This Site:
<input type="text" name="search_field"><input name="Go" type="submit"
value="Go" style="font-family:Arial, Helvetica, sans-serif">
</form>
</span><br/>

How do take the input from this form and use it to populate another form (on
another page within the same site) when the user clicks the Go button?
Also, how do I cancel any action if the form is empty?

Thanks in advance.
Jul 17 '05 #1
17 3068
deko wrote:
This may be a basic question -

I have a form on my web page that looks like this:

<span id="site_search">
<form name="frmSearch" method="post" action="" style=" margin: 0 0 0
15px ">
Search This Site:
<input type="text" name="search_field"><input name="Go" type="submit"
value="Go" style="font-family:Arial, Helvetica, sans-serif">
</form>
</span><br/>

How do take the input from this form and use it to populate another form (on
another page within the same site) when the user clicks the Go button?
Also, how do I cancel any action if the form is empty?

Thanks in advance.


The input from user can be found in eiher $_GET or $_POST arrays
depending on the method your form uses. You should read
http://www.php.net/manual/en/languag...predefined.php

In you case you can use something like this:
if (empty($_POST['search_field'])) {
// Error message
} else {
// Search code
}
Jul 17 '05 #2
I noticed that Message-ID: <cd**********@plaza.suomi.net> from eXeonical
contained the following:
The input from user can be found in eiher $_GET or $_POST arrays
depending on the method your form uses. You should read
http://www.php.net/manual/en/languag...predefined.php

In you case you can use something like this:
if (empty($_POST['search_field'])) {
// Error message
} else {
// Search code
}


And you populate a text box like this

<input type="text" name="name"value="<?php echo $_POST['search_field'];
?>">
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
.oO(deko)
I have a form on my web page that looks like this:

<span id="site_search">
<form name="frmSearch" method="post" [...]


span is an inline-element, you can't put block-elements like a form in
it. Use a div or a more reasonable element instead.

Micha
Jul 17 '05 #4
"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:v7********************************@4ax.com...
I noticed that Message-ID: <cd**********@plaza.suomi.net> from eXeonical
contained the following:
The input from user can be found in eiher $_GET or $_POST arrays
depending on the method your form uses. You should read
http://www.php.net/manual/en/languag...predefined.php

In you case you can use something like this:
if (empty($_POST['search_field'])) {
// Error message
} else {
// Search code
}


And you populate a text box like this

<input type="text" name="name"value="<?php echo $_POST['search_field'];
?>">
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/


Don't forget to escape HTML special characters. Hence

<input type="text" name="name"value="<?php echo
htmlspecialchars($_POST['search_field']); ?>">
Jul 17 '05 #5
> span is an inline-element, you can't put block-elements like a form in
it. Use a div or a more reasonable element instead.


Thanks for the tip.
Jul 17 '05 #6
> And you populate a text box like this

<input type="text" name="name"value="<?php echo $_POST['search_field'];
?>">


Hi and thanks for the reply.

So, the receiving form should look like this:

<INPUT TYPE=text value="<?php echo $_POST['search_field'];?>">
<INPUT type=submit VALUE='Search'>

But the receiving form is on a different page - how do I pass the value of
$_POST to this other page? The idea is for the user to click Go on one page
and then be taken to another page with another form which will be
automatically populated with $_POST from the first page/form.

I tried this on the sending form/page:

<div id="site_search">
<form name="frmSearch" method="post" action="" style=" margin: 0 0 0
15px ">
Search This Site:
<input type="text" name="search_field"><input name="Go" type="submit"
value="Go" style= "font-family:Arial, Helvetica, sans-serif">
</form>
<?php echo ($_POST['search_field']);?>
<meta http-equiv="refresh" "csi_search.php"> <!-- Here I want to
redirect to csi_search.php where the receiving form is. -->
</div><br/>

The value I entered in the form was echoed on the sending page, but I didn't
get redirected to csi_search.php. Suggestions?
Jul 17 '05 #7
I noticed that Message-ID: <qP********************@comcast.com> from
Chung Leong contained the following:
Don't forget to escape HTML special characters. Hence

<input type="text" name="name"value="<?php echo
htmlspecialchars($_POST['search_field']); ?>">


Nah, that's the wrong place for it. Besides, he may want to preserve
markup.

He might want to use stripslashes($_POST['search_field']) though

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #8
I noticed that Message-ID:
<55****************@newssvr21.news.prodigy.com> from deko contained the
following:
But the receiving form is on a different page - how do I pass the value of
$_POST to this other page?


<form name="frmSearch" method="post" action="other_page.php">

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #9
> <form name="frmSearch" method="post" action="other_page.php">

I'll give it a shot....

Regarding cancelling action if a form is blank, I'm trying to get this to
work:

<form method="POST" action=
"<?
if ( empty($_POST['message']) || empty($_POST['email_address']) )
{
} //by the way, is there a better way to construct this without the else
statement?
else
{
include "send_mail.php";
}
?>"
style="font-family: Arial, Helvetica, sans-serif; font-size:12px">
Email address: <input name="email_address" type="text" /><br />
Message:<br />
<textarea name="message" rows="12" cols="25"></textarea><br />
<input type="submit" value="Send" style="font-family: Arial, Helvetica,
sans-serif">
</form>

The problem is that get errors the second time I try ti use the form - but
it seems to work the first around. The error I get is something like:

Warning</b>:%20%20Cannot%20modify%20header%20information%2 0-%20headers%20alr
eady%20sent%20by%20(output%20started%20at%20/home/clearpoi/public_html/beta/
contact.php:19)%20in%20<b

My guess is that I need to reset the form after processing it. Should I
have some kind of reset action in send_mail.php? Below is the script. As
you will see, I am trying to send the user to a thank you page after
submitting feedback. This seems to be buttering things up somehow...

<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail( "da**@ClearpointSystems.com", "CSI Feedback Form", $message, "From:
$email_address" );
header( "Location: http://www.ClearpointSystems.com/beta/thankyou.html" );
?>
Jul 17 '05 #10
> <form name="frmSearch" method="post" action="other_page.php">

That did the trick. Thanks.
Jul 17 '05 #11
I noticed that Message-ID:
<%C***************@newssvr27.news.prodigy.com> from deko contained the
following:
My guess is that I need to reset the form after processing it. Should I
have some kind of reset action in send_mail.php? Below is the script. As
you will see, I am trying to send the user to a thank you page after
submitting feedback. This seems to be buttering things up somehow...

<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail( "da**@ClearpointSystems.com", "CSI Feedback Form", $message, "From:
$email_address" );
header( "Location: http://www.ClearpointSystems.com/beta/thankyou.html" );
?>


Yes, but where is that in the script? If you have output html before
it, it will not work.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #12
> Yes, but where is that in the script? If you have output html before
it, it will not work.


where is what? output html? before what? sorry, no comprenday...
Jul 17 '05 #13
I noticed that Message-ID:
<5e***************@newssvr27.news.prodigy.com> from deko contained the
following:
Yes, but where is that in the script? If you have output html before
it, it will not work.


where is what? output html? before what? sorry, no comprenday...


Post the full script
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #14
> Post the full script

Here's the whole enchlada. To duplicate the problem: go to
http://www.clearpointsystems.com/beta/contact.php and enter anything in the
Email Address form, and the Message form, and click send. You *should* be
taken to the "Thank You" page at
http://clearpointsystems.com/beta/thankyou.html. Now go back to contact.php
and click on the Send button *without entering anything* in either form.
You will receive a 404 - File not found error - with something that looks
like this in your browser's address bar:

Warning</b>:%20%20Cannot%20modify%20header%20information%2 0-%20headers%20alr
eady%20sent%20by%20(output%20started%20at%20/home/clearpoi/public_html/beta/
contact.php:19)%20in%20<b

Here is code from the Feedback form:

<div id="right_menu_feedback">
<form method="POST" action=
"<?
if ( empty($_POST['message']) || empty($_POST['email_address']) )
{
}
else
{
include "send_mail.php";
}
?>"
style="font-family: Arial, Helvetica, sans-serif; font-size:12px">
Email address: <input name="email_address" type="text" /><br />
Message:<br />
<textarea name="message" rows="12" cols="25"></textarea><br />
<input type="submit" value="Send" style="font-family: Arial, Helvetica,
sans-serif">
</form>
</div>

Here is the entire send_mail.php file:

<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail( "my*******@mydomain.com", "CSI Feedback Form", $message, "From:
$email_address" );
header( "Location: http://www.mydomain.com/thankyou.html" );
?>

Perhaps I shouldn't have a separate script to send the message - can I merge
send_mail.php into the form code on contact.php? Not sure this would solve
the problem... which I'm sure is something elementary...

Thanks again for your help.
Jul 17 '05 #15
I noticed that Message-ID:
<Mf*******************@newssvr29.news.prodigy.co m> from deko contained
the following:
Perhaps I shouldn't have a separate script to send the message - can I merge
send_mail.php into the form code on contact.php? Not sure this would solve
the problem... which I'm sure is something elementary...


It is.

The action part of the form should be the location of the page the
results should be sent to. If you leave it blank it will simply refresh
the page. Your script is including the script in the action rather than
the location of the script.

Try:

<form method="POST" action=
"<?
if ( empty($_POST['message']) || empty($_POST['email_address']) )
{
}
else
{
echo "send_mail.php";
}
?>"
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #16
> The action part of the form should be the location of the page the
results should be sent to. If you leave it blank it will simply refresh
the page. Your script is including the script in the action rather than
the location of the script.


Thanks - the below code is working.

I merged send_mail.php into the form code, and commented out the "header..."
line. But I don't know how to move to thankyou.html when the input is
accepted.

<form method="POST" action=
"<?
if ( empty($_POST['message']) || empty($_POST['email_address']) )
{
}
else
{
$email = $_REQUEST['email_address'];
$message = $_REQUEST['message'];
mail( "me@mydomain.com, "CSI Feedback Form", $message, "From:
$email_address" );
//header( "Location: http://www.mydomain.com/thankyou.html" );
//How to move to above page?
}
?>"
style="font-family: Arial, Helvetica, sans-serif; font-size:12px">
Email address: <input name="email_address" type="text" /><br />
Message:<br />
<textarea name="message" rows="12" cols="25"></textarea><br />
<input type="submit" value="Send" style="font-family: Arial, Helvetica,
sans-serif">
</form>
Jul 17 '05 #17
I noticed that Message-ID:
<XV*******************@newssvr29.news.prodigy.co m> from deko contained
the following:

I merged send_mail.php into the form code, and commented out the "header..."
line. But I don't know how to move to thankyou.html when the input is
accepted.


Try doing what I suggested instead.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #18

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

Similar topics

1
by: Sean | last post by:
I can connect to a machine remotely with no problems but I'm having trouble trying to create a process remotely. Initially this was a perl and VB script which I'm converting to python. Its entire...
4
by: John | last post by:
I am trying to spawn a seperate process from my asp page so when a user clicks the link or button a desktop program is launched. This will be on an intranet and the program will exist on the...
2
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4....
1
by: Bartek | last post by:
Hello This is my problem: It consider xml 2 xml conversion. source document had unknown structure (xhtml), xslt must process every node, attribute, text, comments etc. from source and write in...
77
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the...
10
by: Kathy Burke | last post by:
HI. in asp.net app, I have an xmlDocument that I transform to the client html. Using xsl I create a few textboxes to capture user input. Each of these are related to <data> elements in the xmlDoc....
5
by: Paul Bergson | last post by:
I have been trying to get a process to start up and run with arguments passed to it. I have gotten close (Thanks to help from this board) but I there is a failure while I'm running this because...
2
by: Carl Gilbert | last post by:
Hi I am trying to get an online gallery (www.ngallery.org - open source) to upload image to a folder. At the moment I am using localhost but plan to move to some web space when I get it all...
5
by: mouac01 | last post by:
I'm new to PHP/Javascript. I have a simple form I want to validate the fields with javascript and then run the PHP script. All the scripts are in one page. I want PHP to control where the next...
32
by: John Wright | last post by:
I have a long process I run that needs to be complete before the user can continue. I can change the cursor to an hourglass, but I want to update the Status Strip on the bottom during the process. ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.