

Creating widgets - amrithk

Hi everyone, 
This might be a silly question but how are widges actually created/deployed?<p>I am interested in creating a tool that would allow people to create and embed a widgeton their webpage. The widget will basically collect responses from individuals and store them in our database. The widget will also show all responses that have already been entered in the database. You could say its something like the widgets created by PollDaddy.<p>I understand the HTML part necessary to display the widget. However, how do I get the dynamic part (mainly interacting with our database) working without making it too complicated for the widget user to embed.<p>Any suggestions will be helpful. Thanks!
======
dpapathanasiou
One simple way is to use javascript.

Have your users add a single <script> tag in their html page, which points to
a javascript file on _your_ server.

That javascript file on your server is just a single statement:

    
    
      document.write(" ... [ widget content goes here ] ... ");
    

which gets executed every time someone visits your user's site.

Just generate the javascript file on your server as often as necessary (and,
obviously, you can have multiple javascript files customized for each of your
users).

~~~
amrithk
Thanks for the suggestion. So the javascript file would basically write the
html markup for the widget? How would it handle interaction with the database?
Can I use it to write php code as well?

~~~
dpapathanasiou
_So the javascript file would basically write the html markup for the widget?_

Yes.

The text passed to the document.write statement (also note that document.write
is not the only thing you could use here) is the html markup you want to
display.

Just make sure you take care of character entity references
([http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_...](http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references))
in that markup text.

 _How would it handle interaction with the database?_

You just need to have some process running on your server which can connect to
the db, make whatever queries it needs, and generate the javascript file in
your web server's htodcs folder (or wherever you set the output target).

 _Can I use it to write php code as well?_

Just a guess (I really don't know much about php other than a high-level
understanding) but you'll probably run into security issues b/c your user's
server will have a different domain from your server.

I.e., any web client visiting the user's page will (probably) disallow
references to executing code on your server.

I could be wrong on that last point, though, so you may want to do some more
research or just try a few experiments.

