HELP!!! - "Please Enter Valid Email Address", is what it's saying...

But why? Can you help me? I purposely hid my domain name with (*****). Here is my code:

___________________HEADER SCRIPT____________________________
<script>
    $(function()
    {
        $(":submit").click(function() {   
           
            // First, disable the form from submitting
            $('form').submit(function() { return false; });
           
            // Grab form action
            formAction = $("form").attr("action");
           
            // Hack together id for email field
            emailId = formAction.replace("http://carteraun.createsend.com/t/r/s/jyyuik/", "");
            emailId = emailId.replace("/", "");
            emailId = emailId + "-" + emailId;
           
            // Validate email address with regex
            if (!checkEmail(emailId))
            {
                alert("Please enter a valid email address");
                return;
            }
           
            // Serialize form values to be submitted with POST
            var str = $("form").serialize();
           
            // Add form action to end of serialized data
            final = str + "&action=" + formAction;
           
            // Submit the form via ajax
            $.ajax({
                url: "http://www.*****.com/tnwk/proxy.php",
                type: "POST",
                data: final,
                success: function(html){
                    $("#theForm").hide(); // If successfully submitted hides the form
                    $("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
                }
            });
        });
    });
    function checkEmail(email)
    {   
        var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        var emailVal = $("#" + email).val();
        return pattern.test(emailVal);
    }
</script>

____________________FORM_____________________________
<form action="http://carteraun.createsend.com/t/r/s/jyyuik/" method="post">

<div class="label"><label for="firstname">First Name:</label></div>
        <input class="field" style="margin-right:50px;" type="text" name="cm-f-xdkkt" id="firstname"/>
<div class="label"><label for="lastname">Last Name:</label></div>
        <input class="field"" type="text" name="cm-f-xdkki" id="lastname" />
<br style="clear:both;margin-bottom:30px;" />
<div class="label"><label for="phonenumber">Phone Number:</label></div>
        <input class="field"  style="margin-right:50px; type="text" name="cm-f-xdkkd" id="phonenumber"/>
<div class="label"><label for="jyyuik-jyyuik">Email Address:</label></div>
        <input class="field" type="text" name="cm-jyyuik-jyyuik" id="jyyuik-jyyuik"  />
<br style="clear:both;" />
        <button name="submit" type="submit" class="button"><img border="0" src="http://www.*****.com/tnwk/images/btn.jpg" /></button>

</form>

___________________PROXY______________________


<?php
header('Content-type: text/javascript');

// Extract form action and assign to variable

    $action = $_POST['action'];

// Assign form array to single variable

    $arr = $_POST;

// Remove "action" key from array

    unset($arr['action']);

// Loop through and add keys and values to a single variable

    foreach ($arr as $key => $value) {
        $formVars .= $key."=".$value."&";
    }

// Remove last "&"

    $formVars = substr($formVars,0,-1);

// Add the action URL back in the mix
   
    $url = $action.'?'.$formVars;

// Get the response

    $handle = fopen($url, "r");

// If there is something, read and return

    if ($handle) {
        while (!feof($handle)) {
            $buffer = fgets($handle, 4096);
            echo $buffer;
        }
        fclose($handle);
    }
?>

Mathew Mathew, 7 years ago

You need to edit this bit:

emailId = formAction.replace("http://carteraun.createsend.com/t/r/s/jyyuik/"

to be just

emailId = formAction.replace("http://carteraun.createsend.com/t/r/s/"

and it should work ok.


Get in touch with us on Twitter: http://twitter.com/campaignmonitor
We're also on Facebook: http://facebook.com/campaignmonitor
carteraun carteraun, 7 years ago

Thanks. ok, the error "Please enter a valid email" is gone; however, the form still won't submit. I click the submit button and nothing happens.


love it!
Mathew Mathew, 7 years ago

It isn't showing you the confirmation message at all? Do you have this on a server we can see somewhere?


Get in touch with us on Twitter: http://twitter.com/campaignmonitor
We're also on Facebook: http://facebook.com/campaignmonitor
carteraun carteraun, 7 years ago

yes,  add an actual - instead of [hyphen]; and replace [slash] with /

.potpourri[hyphen]soup.com/tnwk[slash]inquire.html


love it!
carteraun carteraun, 7 years ago

any help would be appreciated


love it!
Mathew Mathew, 7 years ago

The problem is that you've removed a couple of the divs that the script is using to show and hide the form ( the  theForm and confirmation divs)

However, to make it work you would change this:

$.ajax({
   url: "http://www.potpourri-soup.com/php_uploads/proxy.php",
   type: "POST",
   data: final,
   success: function(html){
       $("#theForm").hide(); // If successfully submitted hides the form
       $("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
   }
});

to this

$.ajax({
   url: "http://www.potpourri-soup.com/php_uploads/proxy.php",
   type: "POST",
   data: final,
   success: function(html){
       $("#registration").hide(); // If successfully submitted hides the form
   }
});

Get in touch with us on Twitter: http://twitter.com/campaignmonitor
We're also on Facebook: http://facebook.com/campaignmonitor
carteraun carteraun, 7 years ago
Mathew :

The problem is that you've removed a couple of the divs that the script is using to show and hide the form ( the  theForm and confirmation divs)

However, to make it work you would change this:

$.ajax({
   url: "http://www.potpourri-soup.com/php_uploads/proxy.php",
   type: "POST",
   data: final,
   success: function(html){
       $("#theForm").hide(); // If successfully submitted hides the form
       $("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
   }
});

to this

$.ajax({
   url: "http://www.potpourri-soup.com/php_uploads/proxy.php",
   type: "POST",
   data: final,
   success: function(html){
       $("#registration").hide(); // If successfully submitted hides the form
   }
});

Thanks. I made this change and it still won't submit. I compared the form code with the template code  I copied and pasted from the CM control panel, and I don't see where I'm missing any crucial DIV tags.

Is it because of where I put the proxy.php file?


love it!
Mathew Mathew, 7 years ago

Yes, you would also need to make sure the proxy php is in the right place to be referenced by the script.


Get in touch with us on Twitter: http://twitter.com/campaignmonitor
We're also on Facebook: http://facebook.com/campaignmonitor
carteraun carteraun, 7 years ago
Mathew :

Yes, you would also need to make sure the proxy php is in the right place to be referenced by the script.

But where? I know that the url directs the php_uploads folder, which were the proxy.php file resides; however, I also have an exact duplicate of the file in the same folder/level as the form html file. When I upload the file to my hosting server, the php file, should I do it a certain way?


love it!
carteraun carteraun, 7 years ago

Thanks for your time Mathew, any help is appreciated.


love it!
Mathew Mathew, 7 years ago

Hi,

If you can contact support with details about where we can see the form in action, we can take a look and get back to you.


Get in touch with us on Twitter: http://twitter.com/campaignmonitor
We're also on Facebook: http://facebook.com/campaignmonitor

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098