Using PHP to display an image

1 view
Skip to first unread message

Alec

unread,
Aug 22, 2006, 10:42:02 PM8/22/06
to Professional PHP Developers
I am pretty much an absolute beginner at PHP, although I am very good
with (X)HTML, CSS, and basic Javascript. I am creating a website and am
using Particletree's method of "Degradable Ajax Form Validation." I
love the script, however instead of "Thank you!" I want it to display a
small gif (thumbs up, or the like).

I have changed the message to echo '<img src="accept.gif">'; and it
displays just that - "<img src="accept.gif">". How do I get it to
display the image and not the text?

Much thanks,
Alec

flamer die.spam@hotmail.com

unread,
Aug 22, 2006, 11:35:58 PM8/22/06
to Professional PHP Developers
I need to see more code than that to tell you, however one option is
this:

echo " ?> <img src="accept.gif"> <?php";

but will most probably produce the same result.

Flamer.

webm...@hpiracing.com

unread,
Aug 23, 2006, 3:20:36 AM8/23/06
to Professional PHP Developers
Method 1:
<?PHP

echo "<img src=\"accept.gif\" />";

?>

Method 2:
<?PHP
#Heredoc version
echo <<<_text_
<img src="accept.gif" />
_text;
?>

Anne

unread,
Aug 23, 2006, 4:40:54 AM8/23/06
to Professional PHP Developers
Try this one
<?php

echo "<img src=\"accept.gif\"/>";
?>
for more on php
http://asitkatiyar.wordpress.com/

Alec

unread,
Aug 23, 2006, 8:01:52 PM8/23/06
to Professional PHP Developers
Thanks for the responses! However, none of them worked. I guess you
need more information than that, as Flamer suggested. The php script is
below, and the whole package (3 files) is available over at
http://particletree.com/features/degradable-ajax-form-validation/

<?php
//By Chris Campbell
//www.particletree.com
// Created April 27, 2005
//Modified June 27, 2005


//After the form is submitted or onblur, request the validation type
$validationtype = $_GET["validationtype"]; //validationtype is ajax or
php
$continueSubmit = true ; //global var if the form is valid. used only
for php validationtype.

switch ($validationtype)
{
case 'ajax':
ProcessAjax(); //if validationtype is ajax go to processajax function
break;
case 'php':
processPHP();//if it is php call processphp runction
break;
}

function ProcessAjax()
{
$required = $_GET["sRequired"];//$required holds if the field is
required. will be "required" or "notrequired"
$typecheck = $_GET["sTypeCheck"];//$typecheck holds additional
requirements like email or phone
$val = $_GET["val"];

//validateRequired checks if it is required and then sends back
feedback
validateRequired($required,$val,$typecheck);

/*check to see which typecheck (eg. email, date, etc.) was entered as
the second variable in the validateMe() function
check the different cases passed in from the validateMe function.
Send back the appropriate information*/
switch ($typecheck)
{
case 'date':
validateDate($val);
break;
case 'email':
validateEmail($val);
break;
}
}

//If the url string value for validationtype was PHP, you will be
validating through this server side function
function processPHP()
{
//request the forms variables
$user = $_POST["user"];
$email= $_POST["email"];
global $continueSubmit;

//check to see if the different form fields are valid
echo "Username: ";
validateRequired("required", $user, "none");//validate user
echo "<br />";

echo "Email: ";
validateEmail($email) ;//validate email

//if continue is not 0 then continue with the form submission
if ($continueSubmit)
{
//submit your form
}

}

//--------------------------VALIDATION FUNCTIONS -----------------

//Function to validate if the field is required. It just checks to see
if the field is empty.
function validateRequired($required,$val,$typecheck)
{

// if it is required check to see if it validates
if ($required == "required")
{
if ($val == "")
{
// if val is blank then then the field is invalid
echo "Required";
exit(); //we do not need to check for anything else so exit the
validation
}

if ($val !== "" && $typecheck == "none")
{
// if val is not blank and there are no further validation checks
("none") respond with a thank you for feedback
echo "Thank You";
}
}
// if it is not required or typecheck is not none, the script will
continue to validate
}


function validateEmail($val)
{
global $continueSubmit ;
// check the email address with a regex function
//regular expression is from http://regexlib.com/.
//To learn more about them,
http://www.silverstones.com/thebat/Regex.html#intro has a pretty good
tutorial
if (ereg
("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$",
$val, $regs))
{
echo "Thank You";
}
else
{
$continueSubmit = false;
echo "Invalid Email Address";
}
}


Thanks for your help!

webm...@hpiracing.com

unread,
Aug 23, 2006, 8:08:12 PM8/23/06
to Professional PHP Developers
Hello,

Please post a link to a working example of what you're seeing or do a
"View Source" and paste the HTML source here as well. I'd like to see
exactly how the HTML on that image tag is being rendered.

Thanks!

flamer die.spam@hotmail.com

unread,
Aug 24, 2006, 12:31:56 AM8/24/06
to Professional PHP Developers
Hi can you post the part with the image.. generally php issues can be
solved by looking at the line above it.

Flamer.

xml development

unread,
Aug 24, 2006, 2:48:05 AM8/24/06
to Professi...@googlegroups.com
I guess this is the piece of code you are trying to modify:

if (ereg
("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$",
$val, $regs))
{
echo "Thank You";
}

did you try replacing the echo "Thank You";
with
echo "<img src=\"image.gif\">";

?
If yes, could you check what was the HTML code generated, and post it here ?

Regards,
Dragos
http://www.xmldev.ro

Alec

unread,
Aug 26, 2006, 12:36:50 PM8/26/06
to Professional PHP Developers
I really appreciate your help, but it still does not work!

Here is the relevant HTML code generated (I will be removing the table
formatting once I get this working and make it CSS based):

<td><input style="background-color: rgb(255, 255, 160);"
autofillsupport="true" name="email" tabindex="2" id="email"
class="validate required email emailmsg" type="text"></td>

<td id="emailmsg" class="rules">&lt;img src="accept.png"&gt;</td>

After I saw that it generated the character code, I changed the < and >
to &lt; and &gt; repectively in the php code, but that was unsuccessful
also.

My testing page for this is located at http://imageprovement.com/php/
for those who would like to see that.

Thanks for your help!

flamer die.spam@hotmail.com

unread,
Aug 28, 2006, 12:33:57 AM8/28/06
to Professional PHP Developers
your script has a regexp in it which is replacing tags with html safe
char entities, basically so users cant put html code into forms ect.

you can either.. find the expression that it is calling and rewriting
it, or stop the function from running.. either way its a job for an
advanced coder.

Flamer.

webm...@hpiracing.com

unread,
Aug 28, 2006, 4:25:59 AM8/28/06
to Professional PHP Developers

It's not the PHP that's doing it, it's the Javascript... The line that
sends the HTML results back to the tag is in this function inside
validate.js:

function handleHttpResponse() {
//if the process is completed, decide to do with the returned data
if (http.readyState == 4)
{

sResults = http.responseText.split(","); //results is now whatever
the feedback from the asp page was
//whatever the variable glo_show's (usermsg for example) innerHTML
holds, is now whatever was returned by the asp page.
document.getElementById(gShow).innerHTML = "";
//sdocument.write(sResults[0]);
document.getElementById(gShow).appendChild(document.createTextNode(sResults[0]));
}
}


This line:
document.getElementById(gShow).appendChild(document.createTextNode(sResults[0]));

can be rewritten as follows:
document.getElementById(gShow).innerHTML = sResults[0];

That should keep it from converting special characters.

Alec

unread,
Aug 28, 2006, 9:17:59 PM8/28/06
to Professional PHP Developers
Thank you so much!

Reply all
Reply to author
Forward
0 new messages