Page 1 of 1

problem with echo for image

Posted: Wed Nov 25, 2009 7:30 pm
by dimebag
hi i have some strange problem
when i want to echo a image all i got in out put is my html tags instead of the image itself
do not know whats wrong
see part of my code

Code: Select all

function user($val) {
if (is_numeric($val)) {echo '<img src="mypic" />' ;} }
the output i get is this <img src="mypic" />

the html tags ouptputs instead of echoing the image
how to solve ?
regards

Re: problem with echo for image

Posted: Wed Nov 25, 2009 7:46 pm
by jojonage
did you forgot the extension of your pic?

try change

Code: Select all

 
function user($val) {
     if (is_numeric($val)) {
           echo '<img src="mypic.jpg" />' ;
     }
}
 

Re: problem with echo for image

Posted: Wed Nov 25, 2009 8:51 pm
by daedalus__
i don't think an invalid extension would cause it to render text rather than an empty block level element.

could you post more code?

Re: problem with echo for image

Posted: Thu Nov 26, 2009 2:27 am
by dimebag
no i do not think thats because of extension
i do not know why its rendered as a text instead of real tag
this some more part of my code

Code: Select all

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 user($val) {
if (is_numeric($val)) {echo '<img src="mypic" />' ;} }
 
function validateEmail($val)
{
global $continueSubmit ;
 
    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";
    }   
}

is it possible that cause i do not have <html> and <body> ----</body> </html> in my page this happens ?

and something else i m getting the response back through ajax and innerhtml can it be the reason ?

thanks

Re: problem with echo for image

Posted: Thu Nov 26, 2009 2:58 am
by papa
What's the extension of your page file? Maybe it's not being parsed through PHP.

Nice nickname btw. :)

Re: problem with echo for image

Posted: Thu Nov 26, 2009 3:05 am
by dimebag
thanks for nickname :drunk:

the extension is php its parsed correctly
the only thing comes to my mind is cause response is going back through ajax it parses only as simple text and not the image it self
can it be the case and if yes how should i solve it ?

Re: problem with echo for image

Posted: Thu Nov 26, 2009 1:22 pm
by daedalus__
could you post the code that outputs the img tag?

Re: problem with echo for image

Posted: Fri Nov 27, 2009 6:28 am
by dimebag
yes sure
this is the whole java codes for ajax usage which capture the form inputs and send to my php script and get the response back

Code: Select all

 
 
 
window.onload = attachFormHandlers;
 
var gShow; //variable holding the id where feedback will be sent to.
var sUrl = "formvalidation.php?validationtype=ajax&val=";//url is the page which will be processing all of the information.  it is important to make sure validationtype is ajax
var gErrors = 0; //number of errors is set to none to begin with
var http = getHTTPObject();
 
 
 
function attachFormHandlers()
{
    var form = document.getElementById('form1') 
 
    if (document.getElementsByTagName)//make sure were on a newer browser
    {
        var objInput = document.getElementsByTagName('input');
        for (var iCounter=0; iCounter<objInput.length; iCounter++)
        objInput[iCounter].onblur = function(){return validateMe(this);} //attach the onchange to each input field
    }
    form.onsubmit = function(){return validate();} //attach validate() to the form
}
 
 
 
 
/*validateMe is the function called with onblur each time the user leaves the input box
passed into it is the value entered, the rules (which you could create your own), and the id of the area the results will show in*/
function validateMe(objInput) {
 
    sVal = objInput.value; //get value inside of input field
    
    sRules = objInput.className.split(' '); // get all the rules from the input box classname
    sRequired = sRules[1]; // determines if field is required or not
    sTypeCheck = sRules[2]; //typecheck are additional validation rules (ie. email, phone, date)
    gShow = sRules[3]; //gShow is the td id where feedback is sent to.
 
    //sends the rules and value to the asp page to be validated
    http.open("GET", sUrl + (sVal) + "&sRequired=" + (sRequired) + "&sTypeCheck=" + sTypeCheck, true);
  
    http.onreadystatechange = handleHttpResponse;   // handle what to do with the feedback 
    http.send(null);  
}
 
 
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 php page was
        //whatever the variable glo_show's (usermsg for example) innerHTML holds, is now whatever  was returned by the php  page. 
        document.getElementById(gShow).innerHTML = "";
        document.getElementById(gShow).appendChild(document.createTextNode(sResults[0]));
    }
}
 
 
function validate()
{
var tables; 
 
tables = document.getElementsByTagName('td')
 
    for (i=0; i<tables.length; i++)//loop through all the <td> elements 
    {
        // if the class name of that td element is rules check to see if there are error warnings
        if (tables[i].className == "rules")
        {
            //if there is a thank you or its blank then it passes
            if (tables[i].innerHTML == 'Thank You' || tables[i].innerHTML == '' )
            {
                tables[i].style.color = '#000000';//the color is changed to black or stays black
            }
            else
            {
                gErrors = gErrors + 1; //the error count increases by 1
                tables[i].style.color = '#ff0000';//error messages are changed to red
            }
        }
    }
        
    if (gErrors > 0)
    {
        //if there are any errors give a message
        alert ("Please make sure all fields are properly completed.  Errors are marked in red!");
        gErrors = 0;// reset errors to 0
        return false;
    }
    else return true;
 
}
 
 
function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try 
        {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
        xmlhttp = false;
        }
    }
    return xmlhttp;
}

Re: problem with echo for image

Posted: Fri Nov 27, 2009 6:40 am
by daedalus__
cool im sure the problem is in there. by the way thats ecmascript not java. im about to go to sleep so ill dig through it tomorrow but in the mean time maybe check out jquery or something

Re: problem with echo for image

Posted: Fri Nov 27, 2009 6:51 pm
by dimebag
thanks thats nice of you
for jquery or mootools i did not find the thing that i want
i want the field to be checked onblur if its accepted and correct data has inputed and
show the error pic or ok pic according to server response not showing the text

Re: problem with echo for image

Posted: Fri Nov 27, 2009 8:12 pm
by daedalus__
okay open the php page in your browser. what does it output?

is this on a local server or can i see it? :|