2

I'm editing Dotmailer's signup form code as some of my users won't have email addresses. I want to set the form so that if the user does not enter a value for their email address, for it to default to say test@test.com

The field must be filled for it to successfully upload for the Dotmailer DB so I can't just remove it as a required field.

Below is the script at the start of the form which seems to be causing the issues (from my limited knowledge)

    <script language="javascript">// <![CDATA[
function validate_signup(frm) {
    var emailAddress = frm.Email.value;
    var errorString = '';
    if (emailAddress == '' || emailAddress.indexOf('@') == -1) {
        errorString = 'Please enter your email address';
    }



    var isError = false;
    if (errorString.length > 0)
        isError = true;

    if (isError)
        alert(errorString);
    return !isError;
}

// ]]></script>

Ty in advance for any assistance you can provide.

Dinoshaw
  • 33
  • 2
  • Can you add in the HTML that is after the javascript as well? You should be able to replace the _value_ of the email input field with an email if the field is blank. – Syfer Jul 20 '17 at 23:48

1 Answers1

1

You just need to change

if (emailAddress == '' || emailAddress.indexOf('@') == -1) { errorString = 'Please enter your email address'; }

to

if (emailAddress == '' || emailAddress.indexOf('@') == -1) { var input = document.getElementById('#myInput'); input.value = "test@test.com";
}

where #myInput is the id of the email field.

  • I wish it were as easy as that! Unfortunately this results in www.website.com/thanks?reason=invalidemail&result=error – Dinoshaw Nov 06 '15 at 11:34
  • Edited now, if the field is empty it adds a value to it. – Adam Brocklehurst Nov 06 '15 at 11:57
  • Thanks again Adam, unfortunately this doesn't work either and results in the same destination URL. As does using a placeholder, I've even tried to add a radio button with the value of "test@test.com" however the only way this form is playing ball is when a valid email is entered manually. I hope your answer can help some others, I'll see if Dotmailer support can suggest a solution. – Dinoshaw Nov 06 '15 at 14:03