Current location: Hot Scripts Forums » Programming Languages » PHP » Help with forms and php


Help with forms and php

Reply
  #1 (permalink)  
Old 07-06-10, 01:19 PM
sac0o01 sac0o01 is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Help with forms and php

I am trying to set a variable value through a form. A user selects a color and the form sets the value of the variable.

Maybe I am way off on how to set it up. Here is what I have tried:

Form
PHP Code:

<h4>Choose Color</h4>

<select name="color">
<option value="<?php $black ?>">Black</option>
<option value="<?php $white ?>">White</option>
<option value="<?php $grey ?>">Gray</option>
<option value="<?php $limegreen ?>">Limegreen</option>
</select>
And the PHP I am trying to execute:
PHP Code:

$color  $_POST['color'];


$black imagecolorallocate($bg000);
$white imagecolorallocate($bg255255255);
$grey imagecolorallocate($bg128128128);
$limegreen imagecolorallocate($bg1942470);

imagettftext($bg$fontsize0$x$y$color$font$text ); 
I am just trying to set the "$color" variable I have all the others working. I still have much to learn so I may be totally out on my approach.
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 07-07-10, 05:51 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
You need to send the colors "black", "white", "grey", etc, through the form, and then process the imagecolorallocate once the form post back to the page.

Code:
<h4>Choose Color</h4>
<select name="color">
<option value="black">Black</option>
<option value="white">White</option>
<option value="grey">Gray</option>
<option value="limegreen">Limegreen</option>
</select>
PHP Code:

switch($_POST['color']) {
 case 
'white':
       
$color  imagecolorallocate($bg255255255);
       break;
 case 
'grey':
       
$color  imagecolorallocate($bg128128128);
       break;
 case 
'limegreen':
      
$color  imagecolorallocate($bg1942470);
      break;
 default:
      
$color  imagecolorallocate($bg000);
}
imagettftext($bg$fontsize0$x$y$color$font$text ); 
Of course, you can specify all of your colors, and then use a variable variable. I wouldn't trust the input from a post variable for that though.
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
How to create forms - Mysql n PHP mrzuna PHP 1 11-19-07 01:17 AM
need help with saving two forms in php trinity PHP 4 09-21-06 08:21 AM
PHP to calculate HTML forms jamesian PHP 1 10-25-04 08:45 AM
Need a PHP Programmer to make forms. LiQuid2o Job Offers & Assistance 10 08-13-04 01:49 AM
Forms and php? move3rd PHP 2 04-01-04 07:38 PM


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