开发者

Display Code as Code and Not as executable script

开发者 https://www.devze.com 2023-03-11 16:59 出处:网络
I have c开发者_如何学Created a form maker somewhat like Formtorch for codeigniter. The form consists of 6 text boxes that when submitted go to a php file for execution via ajax. Everything works excep

I have c开发者_如何学Created a form maker somewhat like Formtorch for codeigniter. The form consists of 6 text boxes that when submitted go to a php file for execution via ajax. Everything works except for my display. This is what I want to display as code and not as executable script. The idea is to simply copy and paste this to quickly make a form.

<p>
   <label for="<?php $v1;?>"><?php echo $v1;?></label>       
   <input type="text" name="<?php $v1;?>" id="<?php $v1;?>" />       
   <label class="error" id="<?php $v1;?>">This field is required</label>
</p>

As you might expect, when this is returned to the Ajax success script it comes out as labels and input boxes. My ajax display is like this:

 success: function(msg){
             if(msg){
                $('#display').html(msg).show();
             }else{
                $('#display').text("nothing came back");
             }
        }       

As stated above the ajax submit and display work perfectly except for the format. I have tried < code >, < pre >. If I switch the html in success to text I get an unformated jumble of text. Any ideas? This is on localhost so I cant show you the page

Formtorch http://formtorch.geekhut.org/

Thank you


You have to replace all the < and > characters with &lt; and &gt;


Everything between < and > is interpreted as a HTML tag, you need to escape it to &lt; and &gt; respectively, for example using $().text();.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号