07-06-10, 01:19 PM
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
And the PHP I am trying to execute:
PHP Code:
$color = $_POST [ 'color' ];
$black = imagecolorallocate ( $bg , 0 , 0 , 0 );
$white = imagecolorallocate ( $bg , 255 , 255 , 255 );
$grey = imagecolorallocate ( $bg , 128 , 128 , 128 );
$limegreen = imagecolorallocate ( $bg , 194 , 247 , 0 );
imagettftext ( $bg , $fontsize , 0 , $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.
07-07-10, 05:51 PM
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.
PHP Code:
switch( $_POST [ 'color' ]) { case 'white' : $color = imagecolorallocate ( $bg , 255 , 255 , 255 ); break; case 'grey' : $color = imagecolorallocate ( $bg , 128 , 128 , 128 ); break; case 'limegreen' : $color = imagecolorallocate ( $bg , 194 , 247 , 0 ); break; default: $color = imagecolorallocate ( $bg , 0 , 0 , 0 ); } imagettftext ( $bg , $fontsize , 0 , $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.
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off