0

I need to create a user login form without a server or server-side code.

To do that, I was just going set a user cookie to the user's IP. I know this isn't the best, but it should be sufficient for collecting corporate internal registration forms for a fun event, right?

I just want the submission form to automatically open an e-mail with data filled in. But I only want that to happen for unique IPs, so I was going to store the unique IP in a cookie for 10 days.

For some reason, log(clientip) shows IP, but I can't set the cookie to the IP. Why? It gives error: Uncaught TypeError: undefined is not a function for setting cookie ($.cookie("client_ip_cookie", clientip, { path: '/', expires : 10,});)

Index.html: collect IP:

<script type="application/javascript">
    var clientip = "";

    function getip(json){
        clientip = json.ip; 
    }

</script>

<script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"> </script>

Submission form:

    <div class="eventForm"> 
        <p>Name: <br> <input type="text" id="name" name="name" value=''></p>
        <p>Email:<br> <input type="text" id="email" name="email" value=''></p>
        <p>Message:<br><textarea id="message" name="message" rows=8 cols=30></textarea></p>
        <button id="submitBtn" value="Submit" name='submit'>Submit</button>
    </div>  

JavaScript:

        $("#submitBtn").click(function (event) {
            log(clientip); //logs IP
            $.cookie("client_ip_cookie", clientip, { path: '/', expires : 10});

            //if (clientip is not on page, then log these credentials)
            var subject = "Registration for Walk-a-thon",
                name = document.getElementById("name").value,
                email = document.getElementById("email").value,
                message = document.getElementById("message").value;

            var link = "mailto:testemail@aol.com"
                     + "?cc=myemail@aol.com"
                     + "&subject=" + escape(subject)
                     + "&body=" + escape(message)
            ;

            window.location.href = link;    
        });
Lukasz Koziara
  • 4,274
  • 5
  • 32
  • 43
user3871
  • 12,432
  • 33
  • 128
  • 268

1 Answers1

0

If your page has not loaded the jquery.cookie plugin, then $.cookie will be undefined.

Include the script

<script src="/path/to/jquery.cookie.js"></script>

after the jQuery library

See also $.cookie is not a function.

Community
  • 1
  • 1
Joel Allison
  • 2,091
  • 1
  • 12
  • 9