7

Resolved

Contact form does not submit when "Enable attachments" is unchecked

description

BlogEngine.Net 1.4.5

In the Contact Form settings, if you uncheck the "Enable attachments" setting, the contact form will not submit. There is a javascript error:

Error: $("ctl00_cphBody_txtAttachment") is null
Source File: http://john.rummell.info/blog/contact.aspx
Line: 110

I believe the problem lies in this function:
function beginSendMessage()
{
  if ($('ctl00_cphBody_txtAttachment').value.length > 0)
    return true;

  if(!Page_ClientValidate('contact'))
    return false;

  var name = $('ctl00_cphBody_txtName').value;
  var email = $('ctl00_cphBody_txtEmail').value;
  var subject = $('ctl00_cphBody_txtSubject').value;
  var message = $('ctl00_cphBody_txtMessage').value;
  var sep = '-||-';
  var arg = name + sep + email + sep + subject + sep + message;
  WebForm_DoCallback('__Page', arg, endSendMessage, 'contact', null, false) 

  $('ctl00_cphBody_btnSend').disabled = true;

  return false;
}
The txtAttachment length check should be removed if attachments are disabled.

comments

aloker wrote Sep 3, 2008 at 4:45 PM

Indeed, it should be

if ($('').value.length > 0)
return true;

Even if it does not cause a javascript error it will cause btnSend_Click to be executed which is the wrong event handler.

Elsa wrote Nov 16, 2008 at 8:07 PM

thanks for the fix - works now :)