How to hide a field after it's been submitted?

Discussion in 'PHP' started by Matt Ridge, Feb 14, 2012.

  1. #1
    I am writing this code as a email verification system, it has a long way to go, so please bare with how it's written. I am looking to set up something in where after submitted the email field disappears. I thought this was the way to do it, I guess not... Can anyone point me in the right direction?

    <?php
    //This script was created so for two purposes.
    // 1. The pratice of writing code.
    // 2. To stop 90% of all false postings in a blog script I am writing. 
            $output_form = 'yes';
    
    
     if (isset($_POST['submit'])) {
        $email = $_POST['email'];
        $suffix = end(explode('@',$email));
        $ip = gethostbyname($suffix);
        $ipv = '/^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$/';
        
        if (preg_match($ipv, $ip)) {
            $output_form = 'no';
            echo "The " .$ip. " is valid";
    }
    }
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        <label for="email">E-Mail:</label>
        <input type="text" id="email" name="email" /><br />
        <input type="submit" value="Submit Email" name="submit" />
    </form>
    
    Code (markup):
     
    Matt Ridge, Feb 14, 2012 IP
  2. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Hey, try this:
    <?php
    //This script was created so for two purposes.
    // 1. The pratice of writing code.
    // 2. To stop 90% of all false postings in a blog script I am writing. 
            $output_form = 'yes';
    
    
    if (isset($_POST['submit'])) 
    {
        $email = $_POST['email'];
        $suffix = end(explode('@',$email));
        $ip = gethostbyname($suffix);
        $ipv = '/^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$/';
        
        if (preg_match($ipv, $ip)) 
        {
            $output_form = 'no';
            echo "The " .$ip. " is valid";
    	}
    }
    else { ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        <label for="email">E-Mail:</label>
        <input type="text" id="email" name="email" /><br />
        <input type="submit" value="Submit Email" name="submit" />
    </form>
    <?php } ?>
    Code (markup):
     
    ker, Feb 14, 2012 IP
  3. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #3
    I'm not really understanding what you're asking for, but based on my limited understanding, I'll do something like this:

    
    <?php
    
    /* This script was created so for two purposes.
     * 1. The pratice of writing code.
     * 2. To stop 90% of all false postings in a blog script I am writing. */
            
    
    $output = 1;
    
    if (isset($_POST['submit'])) {
    	$email = $_POST['email'];
    	$suffix = end(explode('@',$email));
    	$ip = gethostbyname($suffix);
    	$ipv = '/^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$/';
        
    	if (preg_match($ipv, $ip)) {
    		$output = 2;
    	}else{
    		$output = 3;
    	}
    }
    
    switch ($output){
    case 1: $output = '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
    	<label for="email">E-Mail:</label>
    	<input type="text" id="email" name="email" /><br />
    	<input type="submit" value="Submit Email" name="submit" />
    	</form>';
    	break;
    
    case 2: $output = 'The IP: "'.$ip.'" is valid';
    	break;
    
    case 3: $output = 'The IP: "'.$ip.'" is NOT valid<br/><br/>
    	<form action="'.$_SERVER['PHP_SELF'].'" method="post">
    	<label for="email">E-Mail:</label>
    	<input type="text" id="email" name="email" /><br />
    	<input type="submit" value="Submit Email" name="submit" />
    	</form>';
    	break;
    }
    
    echo $output;
    ?>
    
    PHP:
     
    Andre91, Feb 14, 2012 IP
  4. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #4
    What I'm looking for is this: http://www.kaboomlabs.com/testbed/spamblocker.php

    When you enter the email address, you press Submit email, after you press the button the field to enter the email address disappears, and a response is outputted.

    Does this make sense now?
     
    Matt Ridge, Feb 15, 2012 IP
  5. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #5
    I already told you, what's your problem?!?!?
    <?php
    //This script was created so for two purposes.
    // 1. The pratice of writing code.
    // 2. To stop 90% of all false postings in a blog script I am writing. 
            $output_form = 'yes';
    
    
    if (isset($_POST['submit'])) 
    {
        $email = $_POST['email'];
        $suffix = end(explode('@',$email));
        $ip = gethostbyname($suffix);
        $ipv = '/^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$/';
        
        if (preg_match($ipv, $ip)) 
        {
            $output_form = 'no';
            echo "The " .$ip. " is valid";
    	}
    }
    else { ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        <label for="email">E-Mail:</label>
        <input type="text" id="email" name="email" /><br />
        <input type="submit" value="Submit Email" name="submit" />
    </form>
    <?php } ?>
    PHP:
     
    ker, Feb 15, 2012 IP
  6. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Because a quick glance your code looked exactly like mine, so I didn't see any variance. Also, you just posted the code without saying what you did differently to it, so I didn't think it needed a response... sorry. I would suggest that if you post code say what you did that is different for the future, because honestly, what I did was a simple mistake.

    Thanks though.
     
    Matt Ridge, Feb 15, 2012 IP
  7. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Andre91, Feb 16, 2012 IP
  8. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #8
    I never said it didn't, I asked a question you never responded. So I took another person's idea which looked cleaner and simpler to upkeep... sorry.
     
    Matt Ridge, Feb 16, 2012 IP
  9. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #9
    bleh..... once your program is working I'm happy :)
     
    Andre91, Feb 16, 2012 IP
  10. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #10
    Me too, thanks for the help either way, it was appreciated.
     
    Matt Ridge, Feb 16, 2012 IP