Say I am building a blogging platform, and I want to allow users to be able to add an avatar without leaving the page, when they''re writing a post. I need the avatar information to be included in the form for the post. So for example, after a user adds a new avatar while writing a new blog post, it would be available to be selected as the avatar to be used for that post. What is the best way to go about this? As I understand it, W3C standards don''t allow forms within forms. So I have to find some way of adding the avatar without using a form within the form I''m using for the blog posting. But then, I need the avatar information to be within the post form. I could do the avatar information using AJAX and a hyperlink, but if I use GET, then I am violating the principle that GET operations shouldn''t modify anything, and even if I specify :post => true for the link_to function, this will still fail if the user''s browser doesn''t support JavaScript. So it seems like I can either create the form upon user action and destroy it before the submit the blog post form... or I can create the avatar form outside of the blog post form and have it modify a set of form elements within the blog post form. These last two options seem pretty messy... esp. the second because I''d still want the avatar form to appear to be within the blog post form. Am I missing something? I feel like I''m having a lot of trouble with a seemingly trivial task here. Thanks. -- Posted via http://www.ruby-forum.com/.
I''m a little confused as to the actual workflow/event logic you''re trying to define, but from a pure HTML perspective, you can still POST all the form values (blog_title, blog_body, avatar_name, avatar_homepage, whatever) but just populate the form values when you print out your response after processing the avatar creation. Or, in quick-and-dirty PHP (I''m a RoR luddite, give me time :D): myForm.php: ------------------- if(isset($_POST[''create_avatar''])) ... insert new avatar record... else ... display form again; the form values will contain whatever was in them before the user clicked the create avatar <form method="post" action="myForm.php"> <input type="text" name="blog_title" value="<? echo $_POST[''blog_title''] ?>" /> ... blog form elements ... <input type="text" name="avatar_nickname" value="<? echo $_POST[''avatar_nickname''] ?>" /> ... avatar form elements ... <input type="submit" name="create_avatar" value="Create Avatar!"> <input type="submit" name="post_blog" value="Post your Blog!"> </form> HTH, gravyface On 3/30/06, Gogo Ruby <ud98-5hnm@spamex.com> wrote:> Say I am building a blogging platform, and I want to allow users to be > able to add an avatar without leaving the page, when they''re writing a > post. I need the avatar information to be included in the form for the > post. So for example, after a user adds a new avatar while writing a > new blog post, it would be available to be selected as the avatar to be > used for that post. What is the best way to go about this? > > As I understand it, W3C standards don''t allow forms within forms. So I > have to find some way of adding the avatar without using a form within > the form I''m using for the blog posting. But then, I need the avatar > information to be within the post form. > > I could do the avatar information using AJAX and a hyperlink, but if I > use GET, then I am violating the principle that GET operations shouldn''t > modify anything, and even if I specify :post => true for the link_to > function, this will still fail if the user''s browser doesn''t support > JavaScript. > > So it seems like I can either create the form upon user action and > destroy it before the submit the blog post form... or I can create the > avatar form outside of the blog post form and have it modify a set of > form elements within the blog post form. > > These last two options seem pretty messy... esp. the second because I''d > still want the avatar form to appear to be within the blog post form. > Am I missing something? I feel like I''m having a lot of trouble with a > seemingly trivial task here. > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Ahh sorry, I guess I forgot a key requirement... I wanted it to be AJAX''ed so that there would be no refresh from adding a new avatar. Sorry about that! gravy face wrote:> I''m a little confused as to the actual workflow/event logic you''re > trying to define, but from a pure HTML perspective, you can still POST > all the form values (blog_title, blog_body, avatar_name, > avatar_homepage, whatever) but just populate the form values when you > print out your response after processing the avatar creation. Or, in > quick-and-dirty PHP (I''m a RoR luddite, give me time :D):-- Posted via http://www.ruby-forum.com/.
Seeing as you seem to be fairly new to Web development, you might want to get it working using "Web 1.0" methods first and then see if an AJAX solution/pattern is truly what you want because AJAX (and in particular javascript debugging) can be tricky, especially if you''re still grasping Web fundamentals. If you''re just trolling for someone to write code for you, I''d suggest posting this to an AJAX mailing list -- you might be lucky or someone can point you in the right direction. If you want to learn how to write AJAX, start by reading these excellent articles from IBM Developerworks to get a handle on how AJAX works and then you can decide whether you want to do that or not: http://www-128.ibm.com/developerworks/views/web/libraryview.jsp?search_by=Mastering+Ajax On 3/30/06, Gogo Ruby <ud98-5hnm@spamex.com> wrote:> Ahh sorry, I guess I forgot a key requirement... I wanted it to be > AJAX''ed so that there would be no refresh from adding a new avatar. > Sorry about that! > > gravy face wrote: > > I''m a little confused as to the actual workflow/event logic you''re > > trying to define, but from a pure HTML perspective, you can still POST > > all the form values (blog_title, blog_body, avatar_name, > > avatar_homepage, whatever) but just populate the form values when you > > print out your response after processing the avatar creation. Or, in > > quick-and-dirty PHP (I''m a RoR luddite, give me time :D): > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Sorry if I''ve given the wrong impression... I''m not new to web development. I know how to implement this without AJAX. I''m not asking for someone to write code for me. I''m just wondering if my thoughts on this are correct or whether there is a simpler way that I am just missing. gravy face wrote:> Seeing as you seem to be fairly new to Web development, you might want > to get it working using "Web 1.0" methods first and then see if an > AJAX solution/pattern is truly what you want because AJAX (and in > particular javascript debugging) can be tricky, especially if you''re > still grasping Web fundamentals. > > If you''re just trolling for someone to write code for you, I''d suggest > posting this to an AJAX mailing list -- you might be lucky or someone > can point you in the right direction. > If you want to learn how to write AJAX, start by reading these > excellent articles from IBM Developerworks to get a handle on how AJAX > works and then you can decide whether you want to do that or not: > > http://www-128.ibm.com/developerworks/views/web/libraryview.jsp?search_by=Mastering+Ajax-- Posted via http://www.ruby-forum.com/.