Jump to content

Bad value for action attribute


vipsa

Recommended Posts

Hi 

 

I have very little php experience and I battle to understand how it works so I really need explaining how certain things work. Like I have the following code:

 

The line <form action="echo htmlentities($_SERVER['PHP_SELF']); ?>" method="GET"> says bad value and double white space in path which I cannot find as there are not white spaces in the path. Please help me understand this

<?php
if (isset($_GET['message'])) {
// load font and image, calculate width of text
$font = "times";
$size = 12;
$image = imagecreatefrompng("button.png");
$tsize = imagettfbbox($size, 0, $font, $_GET['message']);
// center
$dx = abs($tsize[2] - $tsize[0]);
$dy = abs($tsize[5] - $tsize[3]);
$x = (imagesx($image) - $dx) / 2;
$y = (imagesy($image) - $dy) / 2 + $dy;
// draw text
$black = imagecolorallocate($im,0,0,0);
imagettftext($image, $size, 0, $x, $y, $black, $font, $_GET['message']);
// return image
header("Content-type: image/png");
imagepng($image);
exit;
} ?>
<html>
<head>
<title>Button Form</title>
</head>
<body>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="GET">
Enter message to appear on button:
<input type="text" name="message" /><br />
<input type="submit" value="Create Button" />
</form>
</body>
</html>
Edited by vipsa
Link to comment
Share on other sites

I just tested this and worked fine, a few minor changes, you should add the ttf extension your font filename

<?php
if (isset($_GET['message']) && trim($_GET['message']) !='') {
$message = trim($_GET['message']);
// load font and image, calculate width of text
$font = "times.ttf"; // does this font file exist same folder ?
$size = 12;
$image = imagecreatefrompng("button.png");
$tsize = imagettfbbox($size, 0, $font, $message);
// center
$dx = abs($tsize[2] - $tsize[0]);
$dy = abs($tsize[5] - $tsize[3]);
$x = (imagesx($image) - $dx) / 2;
$y = (imagesy($image) - $dy) / 2 + $dy;
// draw text
$black = imagecolorallocate($image,0,0,0);
imagettftext($image, $size, 0, $x, $y, $black, $font, $message);
// return image
header("Content-type: image/png");
imagepng($image);
//frees image from memory
imagedestroy($image);
exit;
}
?>
<html>
<head>
<title>Button Form</title>
</head>
<body>
<form action="" method="GET">
Enter message to appear on button:
<input type="text" name="message" /><br />
<input type="submit" value="Create Button" />
</form>
</body>
</html>
Edited by QuickOldCar
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.