1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Comment form issues

Discussion in 'PHP' started by jperezmt, Apr 10, 2008.

  1. #1
    I'm going a little nuts over this and was working on it practically all day yesterday.

    I'm creating a form for people to enter comments. There are 3 required fields, name, comment, and a question so bots don't post. If I fill out 2 of the three, the form says please fill out whatever is missing but it removes what was previously entered in the other 2 fields.

    I looked up sticky forms and I finally got it to stick when the form is submitted, but after all 3 fields are submitted, the information still stays. Is there any way to reset the form after all of the information has been submitted without having it reset to fill in the required fields??

    if (isset($_POST['submit']) || isset($_POST['submit_x'])) { 
    
        if($code != 4) {  
            $badform = 1; 
        } 
        if (trim($nickname) == '') { 
            $badform = 1; 
        } 
        if (trim($comment) == '') { 
            $badform = 1; 
        } 
    
        if (!get_magic_quotes_gpc())  
            { 
            $nickname = addslashes($_POST['nickname']); 
            $comment = addslashes($_POST['comment']); 
            $code = addslashes($_POST['code']); 
            }  
             
        if ($badform != 1) { 
            $query = "this is the query"; /* Quotes are important in this lines statment */ 
            $result = mysql_query($query) or die("sorry something went wrong");  
             
        } 
    } 
        <form action="<?php echo "blog.php?id=$id" ?>" method=post> 
    <?php  
                if(isset($_POST['submit']) || isset($_POST['submit_x']))  { 
                    if (trim($nickname) == '') { 
                    echo "<p class=\"error\">What do people call you?</p>"; 
                    }  
                } 
            ?> 
              <input class="textinput" name="nickname" type="text" maxlength="12" value="<?php if (isset($_POST['nickname'])) echo $_POST['nickname']; ?>"  /> 
             <?php  
                if(isset($_POST['submit']) || isset($_POST['submit_x']))  { 
                    if (trim($comment) == '') { 
                    echo "<p class=\"error\">At least say something!</p>"; 
                    } 
                } 
            ?> 
              <textarea class="texta" rows="5" name="comment"><?php if (isset($_POST['comment'])) echo $_POST['comment']; ?></textarea> 
            <?php 
                    if(isset($_POST['submit']) || isset($_POST['submit_x']))   
                    { 
                        if ($code != 4) { 
                        echo "<p class=\"error\">Not everyone can figure this out...think about it.</p>"; 
                        } 
                    } 
            ?> 
              <input class="textinput" name="code" type="text" maxlength="1" /> 
                <input type="hidden" name="blogid" value="<?php echo "$id" ?>" /> 
                <input src="/images/addComment.gif" type="image" name="submit" value="Add Comment" alt="Add Comment" /> 
    </form> 
    PHP:
     
    jperezmt, Apr 10, 2008 IP
  2. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #2
    After all 3 are submitted and verified I would probably show a different page.
    However you could just do $_POST = ""; to wipe the post variables.
     
    m0nkeymafia, Apr 10, 2008 IP
    jperezmt likes this.
  3. jperezmt

    jperezmt Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    :eek:Wow, obviously you can tell im a n00b at this php stuff. I went crazy yesterday and all I had to do was freakin add that one little line to clear the post variable. Do you know all the crazy crap I was reading on all these damn sites and not one mentioned anything like that!!! :eek:

    Anyway, thank you very much, i really really appreciate it, I'm gonna add a green rep to your name cuz out of all the people who read this post, your the only one who answered. :)
     
    jperezmt, Apr 10, 2008 IP
  4. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #4
    Haha, no worries dude, glad I could help :)
     
    m0nkeymafia, Apr 11, 2008 IP
  5. DartPHP

    DartPHP Banned

    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Just to let you know, I really recommend that you use mysql_real_escape_string() in place of addslashes()
     
    DartPHP, Apr 11, 2008 IP