dt1000
dt1000

Reputation: 3732

hidden variable in html

I am working in Ruby Sinatra. In Ruby, I create a nokogiri object (@xml) that the erb page has access to. In the post, I need to have access to that same object, so I create a hidden variable like so:

    <input type="hidden" name="xml" value= '<%= @xml %>' >

However, in some cases, the page displays a bunch of text from the @xml object that I don't want displayed. As a workaround, I moved it offscreen, like this:

<div style="position:absolute; left:5000px; top:200px;">
    <input type="hidden" name="xml" value= '<%= @xml %>' >
</div>

but there must be a better way. Suggestions? Thanks.

Upvotes: 0

Views: 3158

Answers (1)

Petr Peller
Petr Peller

Reputation: 8826

The problem could be in content of the @xml object. You should encode the special characters before printing the variable into value attribute.

If the @xml object contains a single quote, browser will interpret it like the end of value attribute.

Take a look at HTMLentities library for Ruby.

Upvotes: 1

Related Questions