Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    7
    Member #
    23657
    Hey all,

    I've messed with this part of my website for a couple of days now and I think it's a good idea to call in the calvary (Yes you.)

    Before I get to the issue, I'll tell you what I've been doing. First of all, I have created 2 pages, a contact.php page and a submit.php page. The usual contact form is on both pages but first one must enter info into the fields on the contact page then it gets submitted to the submit page to either display a "message has been sent" splash or the contact form is redisplayed with warnings "please enter bla bla" but the right info does not have to be re-entered. Then, once clicked again, is resubmitted through the same verification process and eventually all makes it to the splash message.

    This is all happening during a php session.

    Okay, now my issue is when I test my script on localhost all is fine but when I upload to the server and test, I'll get the warnings but all fields have to be re-entered before success.

    As the title says, this has to do with cookies. I used javascript for my cookies not php - the php is for other back-end stuff. I must note my cookie name is PREF which is stored in the same path as PREFSESSID (no problem with my script on localhost). But when on the server there are many other cookies with "_utm*". This is a bit of an issue because I thought I could cheat and set a cookie name on my getCookie() action.

    Apparently, I have to be more specific in my .js script and not try a work-around like that. Any clues?

    here is my stuff:

    contact.php form
    PHP Code:
    <form id="contactForm" name="contactForm" method="post" action="submit.php">
                    <
    fieldset>
                        <
    legendContact Info</legend>
                        <
    div>
                            <
    label for="contact_name">Name:</label>
                            <
    input id="contact_name" name="contact_name" type="text" class="field" size="32" />
                        </
    div>
                        <
    div>
                            <
    label for="contact_email">Email:</label>
                            <
    input id="contact_email" name="contact_email" type="text" class="field" size="32" />
                        </
    div>
                        <
    div>
                            <
    label for="comment">Comment:</label>
                            <
    textarea id="comment" name="comment" type="text" class="area" cols="20" rows="7"></textarea>
                        </
    div>
                        <
    div>
                            <
    img src="captcha.php" alt="captcha"/>
                            <
    input type="text" name="vercode" class="field" size="20"></input>
                            <
    label for="vercode">*Please enter code.*</label>
                        </
    div>
                        <
    div class="submit">
                            <
    button name="submit" value="Send Now" onclick="setCookie()">Send Now</button>
                        </
    div>
                    </
    fieldset>
                </
    form
    submit.php form
    PHP Code:
    <body id="contact" onload="getCookie('PREF')"><!--cheat-->
    <form id="contactForm" name="contactForm" method="post" action="submit.php">
                        <fieldset>
                            <legend> Contact Info</legend>
                            <div>
                                <label for="contact_name">Name:</label>
                                <input id="contact_name" name="contact_name" type="text" class="field" size="32" />
                                <label class="errortext"><?php echo $name_error?></label>
                            </div>
                            <div>
                                <label for="contact_email">Email:</label>
                                <input id="contact_email" name="contact_email" type="text" class="field" size="32" />
                                <label class="errortext"><?php echo $email_error?></label>
                            </div>
                            <div>
                                <label for="comment">Comment:</label>
                                <textarea id="comment" name="comment" type="text" class="area" cols="20" rows="7"></textarea>
                                <label class="errortext"><?php echo $comment_error?></label>
                            </div>
                            <div>
                                <img src="captcha.php" alt="captcha"/>
                                <input type="text" name="vercode" class="field" size="20"></input>
                                <label class="errortext"><?php echo $urcode_error?></label>
                                <label for="vercode">*Please enter code.*</label>
                            </div>
                            <div class="submit">
                                <button name="submit" value="Send Now" onclick="setCookie()">Send Now</button>
                            </div>
                        </fieldset>
                    </form>
    </body>
    Yes I have some php validation (it works! =P)

    And now for the Javascript:

    Code:
    function setCookie()
    {
        var setName = document.contactForm.contact_name.value;
        var setEmail = document.contactForm.contact_email.value;
    
        document.cookie = "PREF=name:"+setName+"|email:"+setEmail+";";
    }
    
    //-----------------------------------------------------------------------------
    
    function getCookie()
    {
        //cookies are strings so grab the cookie string
        var cookie = document.cookie;//loads cookies from path
        var cutter = cookie.split(";")//seperates cookies from each other.
    
    
        //PREF=name:Jim Dandy|email:joe@blow.com
        var pref = cutter[0].split("=");//name from value
        var contact_info = pref[1].split("|");//splits each value
        var name_pair = contact_info[0];//grabs first value
        var email_pair = contact_info[1];//grabs second value
        var name = name_pair.split(":");//grabs first value data
        var email = email_pair.split(":");//grabs second value data
        var yourName = name[1];//assigns variable name to first value data
        var yourEmail = email[1];//assigns variable name to second value data
    
        //populates form with value data
        document.contactForm.contact_name.value = yourName;
        document.contactForm.contact_email.value = yourEmail;
    }//end function
    The setCookie function works as it should but as I said, I need to clarify the cookie better using this script. Anyone know of a better way to specify a cookie(name)?

    I've tried other scripts and tutorials but none seem to sit well with me so I made this up.

    I apologize for this thread being so long and appreciate all help and criticism my way.

    Thanks so much all.:-/

  2.  


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:28 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com