2179 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Has been a member for 5-6 years
  • Won a Competition
+10 more
mpc Volunteer moderator 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
  • United States
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Bought between 1 and 9 items
  • Referred between 500 and 999 users
  • Has been a member for 2-3 years
DesignerThemes says

Try changing the:

$(this).attr('action')

To:

$('form#commentform').attr('action')
2024 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Envato Studio (Microlancer) Beta Tester
+3 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;
});
2179 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Has been a member for 5-6 years
  • Won a Competition
+10 more
mpc Volunteer moderator says

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

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

 var $this = $(this); 
2024 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Envato Studio (Microlancer) Beta Tester
+3 more
revaxarts says
Do you get a valid URL with
alert(_this.attr('action'));
2179 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Has been a member for 5-6 years
  • Won a Competition
+10 more
mpc Volunteer moderator says

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

Yeap I do get a valid URL ;/

2179 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Has been a member for 5-6 years
  • Won a Competition
+10 more
mpc Volunteer moderator says

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

2179 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Has been a member for 5-6 years
  • Won a Competition
+10 more
mpc Volunteer moderator 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