Are you trying to change the HTML in an HTML form? If so, you probably want to edit the html
property of the form (example below).
DANGER, WILL ROBINSON
Editing HTML from code is a dangerous activity - it’s why Anvil tries to make it unnecessary. If you don’t carefully filter what goes into HTML code, someone can inject malicious code into your app and compromise its security. (This is called Cross-Site Scripting, or XSS, and it is the most common way websites get hacked.) If there is a way to avoid editing HTML in code, do it that way instead. And always make sure you restrict what characters someone can inject into your HTML.
In this case, you’ll be substituting in a URL. So you can use anvil.http.encode_uri_component
, something like so (copied inexpertly from the Facebook docs):
self.html = """
<blah blah Facebook HTML here...>
<div class="fb-share-button"
data-href="https://yourapp.anvilapp.net/#?search=%s"
data-layout="button_count">
</div>""" % anvil.http.encode_uri_component(my_search_parameter)
The encode_uri_component()
call will remove any dangerous characters that could be used to inject HTML into your page, so this code is safe.
Hope that helps!