SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Help with Prototype! Form not processing correctly :(

    I am processing a form with name="comment" via the POST method. This code will not work and I don't know what I am doing wrong. I don't want to use the GET method. Please help and tell me how to process it correctly:

    Code:
          function comment()
          {
            var url = '/comments/comment';
            new Ajax.Request(url, {method: 'post', postBody: Form.serialize('comment'), onSuccess: function(transport) {
              var notice = $('message');
              if (transport.responseText == '0')
              {
                notice.update('Form Error');
              }
              if (transport.responseText == '1')
              {
                notice.update('comment_success');
                Form.reset('comment');
              }
              if (transport.responseText == '2')
              {
                notice.update('name_and_comment_required');
              }
              if (transport.responseText == '3')
              {
                notice.update('User Authentication Failed');
              }
              if (transport.responseText == '4')
              {
                notice.update('You Have Been Banned From This Application');
    
              }
              if (transport.responseText == '5')
              {
                notice.update('You Must Wait 30 Seconds');
    
              }
            }
    Have a good day.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your code is missing some closing braces/parentheses.

    Also, try using parameters instead of postBody:
    Code:
    function comment()
          {
            var url = '/comments/comment';
            new Ajax.Request(url, {method: 'post', parameters: Form.serialize('comment'), onSuccess: function(transport) {
              var notice = $('message');
              if (transport.responseText == '0')
              {
                notice.update('Form Error');
              }
              if (transport.responseText == '1')
              {
                notice.update('comment_success');
                Form.reset('comment');
              }
              if (transport.responseText == '2')
              {
                notice.update('name_and_comment_required');
              }
              if (transport.responseText == '3')
              {
                notice.update('User Authentication Failed');
              }
              if (transport.responseText == '4')
              {
                notice.update('You Have Been Banned From This Application');
    
              }
              if (transport.responseText == '5')
              {
                notice.update('You Must Wait 30 Seconds');
    
              }
            }});
          }
    Also, I'm not sure that Form.serialize/Form.reset will work....you might have to provide a reference to the actual form:
    ...parameters: document.forms["myform"].serialize
    ...document.forms["myform"].reset

    Could be wrong on that last part, never tried it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •