Notices

Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

PHP Help: Form variables

Post Reply New Thread Subscribe Search this Thread
 
 
Thread Tools
Old 11-14-08, 09:24 PM Thread Starter   #1
kayson
Member

 
kayson's Avatar 

Join Date: Jan 2005
Location: USA

 
PHP Help: Form variables


What's the best way to work with variables passed by forms? I've been using $_REQUEST, but the problem I keep running into is if the variable is undefined, I get a notice that the index is undefined. It's because I use one page for everything. So I have index.php with a form that posts to index.php. If I have $_REQUEST["name"], for example, from a text box, it will work fine if the form has been submitted, but the first time the page is viewed I get an error. Thanks!

__________________
Project Silver
Intel Core i7-980X (145x29 = 4205MHz @1.352V)
Asus P6X58D Premium
Corsair Dominator 3x2GB DDR3-1600 (1740MHz)
Gigabyte AMD HD 6950 (Unlocked @ 880/1375MHz)
Corsair HX850
OCZ Vertex 3 Max IOPS 120GB
Thermalright Venomous X || 2x 120mm Panaflo || Arctic Silver V
Lian-Li PC-A77FA || Vantec Nexus Fan Controller
(Build Journal)
Heatware
kayson is offline   QUOTE Thanks
Old 11-14-08, 10:34 PM   #2
jdf_warrior
Member



Join Date: Dec 2005
Location: Huntsville, AL

 
The easiest thing to do would be to use the isset() function to determine if the there was a value passed through the form. It is a bool function so just throw it in an if statement and check to determine if there was anything posted through the form. Otherwise, dont do anything.

You could always just submit to somewhere other than index.php too. Submit your form to another script and then dependent upon the result, redirect back to index.php or somewhere else.
jdf_warrior is offline   QUOTE Thanks
Old 11-17-08, 09:16 PM   #3
petteyg359

 
petteyg359's Avatar 

Join Date: Jul 2004
Location: University of Southern Mississippi

 
form.php
Code:
<form action="form.php" method="post">
Name:<input type="text" name="formdotphp_name" />
Favorite Color:<input type="select" name="formdotphp_color">
<option value="red">Red</option>
<option value="blue">Blue</option>
</input>
<input type="submit" name="formdotphp_submit" value="1" />
</form>
<?php
if ($_POST['submit']) {
echo "<br />Form submitted:<br />";
echo $_POST['formdotphp_name']."'s favorite color is ";
echo $_POST['formdotphp_color'].".";
}
?>
Better to use your specific globals rather than $_REQUEST, IMHO.

__________________
MSI 890GXM-G65 - X6 1055T - 16GiB 10700 - 5850 1GiB - 7 Pro x64 / Gentoo amd64 - HX520
Dell XPS 15 L502x - i7 2760QM - 16GiB 12800 - GT 540M 2GiB - 7 Pro x64 / Gentoo amd64 - Agility 4 512GB

[GB ≠ GiB] [MB ≠ MiB] [kB ≠ kiB] [1000 ≠ 1024] [Giga ≠ gram] [Mega ≠ milli] [Kelvin ≠ kilo] [Byte ≠ bit]
"Apparently, Plaintiff believes that he could sue an egg company for fraud for labeling a carton of 12 eggs a “dozen,” because some bakers would view a “dozen” as including 13 items." - Western Digital 2006

Last edited by petteyg359; 11-20-08 at 12:15 AM.
petteyg359 is offline Folding Profile SETI Profile Heatware Profile   QUOTE Thanks

Post Reply New Thread Subscribe


Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Mobile Skin
All times are GMT -5. The time now is 05:22 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
You can add these icons by updating your profile information to include your Heatware ID, Benching Profile ID or your Folding/SETI profile ID. Edit your profile!
X

Welcome to Overclockers.com

Create your username to jump into the discussion!

New members like you have made this the best community on the Internet since 1998!


(4 digit year)

Why Join Us?

  • Share experience
  • Max out your hardware
  • Best forum members anywhere
  • Customized forum experience

Already a member?