2268 posts
  • Elite Author
  • Author Level 10
  • Exclusive Author
  • Winner
+16 more
mpc
says

Hi, guys I am using the same contact form module in all of my themes, while developing my latest theme I run into a problem:

$.post($(this).attr('action'), formInput, function(data) {                                $('form#commentform').before('<p><?php echo esc_attr($thanks); ?></p>');
});

This bit of code returns a URL not found (404 error) I am not really sure why because the URL is ok and is pointing to the right page. Any ideas?

19 posts
  • Weekly Top Seller
  • Elite Author
  • Featured Author
  • Exclusive Author
+5 more
DesignerThemes
says

Try changing the:

$(this).attr('action')

To:

$('form#commentform').attr('action')
2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 more
revaxarts
says
First
$('#commentform')
is faster than
$('form#commentform')
:) To submit a form with ajax I often do:
$('#commentform').on('submit', function(){
   var _this = $(this);
    $.post(_this.attr('action'), _this.serialize(), function(data){
          _this.before('<p><?php echo esc_attr($thanks); ?></p>');
    });

  return false //prevent native submit;
});
2268 posts
  • Elite Author
  • Author Level 10
  • Exclusive Author
  • Winner
+16 more
mpc
says

Didn’t help, the same problem occurs, any other ideas?

P.S Instead of using _this I use $this :)

 var $this = $(this); 
2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 more
revaxarts
says
Do you get a valid URL with
alert(_this.attr('action'));
2268 posts
  • Elite Author
  • Author Level 10
  • Exclusive Author
  • Winner
+16 more
mpc
says

Do you get a valid URL with
alert(_this.attr('action'));

Yeap I do get a valid URL ;/

2268 posts
  • Elite Author
  • Author Level 10
  • Exclusive Author
  • Winner
+16 more
mpc
says

I am still having this issue, any help would be appreciated …

2268 posts
  • Elite Author
  • Author Level 10
  • Exclusive Author
  • Winner
+16 more
mpc
says

Hi, I found this on the stackexchange.com and it helped:

I could be wrong, but I vaguely remember that: name, email get hijacked by WordPress to do post comments, if you renamed the form elements to be contact-name and contact-email, do you get the same issue?

I had a name conflict :)

by
by
by
by
by
by