Current location: Hot Scripts Forums » Programming Languages » PHP » Collecting a value from a form


Collecting a value from a form

Reply
  #1 (permalink)  
Old 11-13-04, 09:44 AM
DJ Steffo DJ Steffo is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Collecting a value from a form

Hi!
I have a fairly advance PHP page with a script that uses the value 'a' to match with values in an array. The easy problem is that:....

The 'a' has been given so far but now I would like the webuser to input the value 'a' when he is visiting the PHP page.

What should the FORM look like to send the value to the script?
How do I set the value a=100 as the default value in the form?

I have seen examples where info is sent to a new PHP page but I am already standing in mine. Maybe it causes a conflict?

Code:
<form method=???? action="????">
What is your desired value? 
<input type=integer name="value" size=6 maxlength=6>
<input type="submit" value="SUBMIT!">
</form>
Thank you for your time.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-13-04, 09:57 AM
Y3000's Avatar
Y3000 Y3000 is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Cool

If I understood correctly the variable you are trying to send is called a!

Code:
<form action="script.php" method="POST">
<input type="text" name="a" value="100" size="6" maxlength="6">
<input type="submit" value="Submit">
</form>
Where script.php is the name of your script file.

...however...

If you are within PHP <? ?> you will need to echo this... and remove the "s eg.


Code:
echo "<form action=script.php method=POST>
<input type=text name=a value=100 size=6 maxlength=6>
<input type=submit value=Submit>
</form>";
...however...

You will probably only want to show the form if a has not been set...

Put this at the top of the script within <? and ?>


Code:
if (!$a) {
echo "<form action=script.php method=POST>
<input type=text name=a value=100 size=6 maxlength=6>
<input type=submit value=Submit>
</form>";
exit;
}
The exit; will stop the rest of the script from running, remove this if this is not what you want. Like this they will need to complete the form before the script will run!

Hope that helps.
__________________
Adam

Last edited by Y3000; 11-13-04 at 10:10 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-13-04, 02:46 PM
DJ Steffo DJ Steffo is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Getting closer

Thanks for the examples it made me come closer to my goal. Unfortunately there are conflicts.

I have today the following code on the page: "script.php"
Code:
<?php
...
$a=30;
$sql = "SELECT	*,
CASE 
	WHEN ".$a." > ......
'a' must have a starting value for the page to be able to display the table. Therefor it has above been given 30.

I believe this is why nothing happens when I follow your recommendation
Code:
<form action=script.php method=POST>
<input type=text name=a value=100 size=6 maxlength=6>
<input type=submit value=Submit>
</form>
Which I have written in the body of "script.php".
Since all javascripts and fetching is done in the <head> and my <form>
is written further down in the <body> it creates a conflict?

I would like the table to be displayed from the start with a given value for 'a'.
Then the user could use the form to show a new table for their chosen value.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-14-04, 05:34 AM
Y3000's Avatar
Y3000 Y3000 is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Hiya,

Okay - The form is setting the variable a.
But... the line $a=30; is then resetting the variable to 30 regardless of what the user submitted.


Put the following at the top of your page and remove the old line $a=30;

PHP Code:

<?PHP

if (!$a) { $a=30; }
echo 
"<form action=$PHP_SELF method=POST>
<input type=text name=a value=100 size=6 maxlength=6>
<input type=submit value=Submit>
</form>"
;
?>
Give it a go and let us know!
__________________
Adam

Last edited by Y3000; 11-14-04 at 05:42 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-14-04, 01:48 PM
DJ Steffo DJ Steffo is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up It's alive!

My sincerest and warmest thank you's! It works very fine now.
Thank you very much for your help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 11-14-04, 04:39 PM
Y3000's Avatar
Y3000 Y3000 is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
No Problem!

Can I see it in action?
__________________
Adam

Last edited by Y3000; 11-14-04 at 04:54 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 11-15-04, 03:14 PM
DJ Steffo DJ Steffo is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

Of course! I will send you an invitation when it is all in all presentable!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
formmail problem gscraper Perl 12 08-27-04 04:06 AM
Limit the form submission according to time bionicsamir PHP 7 05-10-04 12:10 AM
make form box TEXT? lylesback2 JavaScript 2 04-05-04 07:58 PM
Collecting html form data and sending it to a sql table crobinson ASP 3 01-04-04 10:16 PM
SQL database registration form help vinhkhuong PHP 3 10-10-03 04:49 AM


All times are GMT -5. The time now is 12:23 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.