SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 31

Thread: Syntax Errors?

  1. #1
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question Syntax Errors?

    PHP Code:
    Code:
     /*This is the scripting section for the e-mail collection box.*/
    	  class CollectEmail
    	  {
    		$email = " ";
    		$connection = new PDO('mysql:host=worldreviewgroupcom.*****mysql.com;dbname=emailcollection' , "worldreviewgroup" , "*******");
    		if (!$connection){
    			die('Could not connect: ' . mysql_error());
    	   }
    		
    		function showWindowAndValidate()
    		{
    			echo'	<p>Join the Mailing List!</p>
    					<div id="activeemailbox">
    					<form name="form1" method="post" action="">
    					  <label for="confirmemail">Confirm Your E-mail:<span style="color:red">*</span></label>          
    					  <input type="text" name="confirmemail" value="" maxlength="60"/><br />
    					  <label for="name">Enter Your Name:</label>
    					  <input type="text" name="name" value="" maxlength="60" /><br />
    					  <label for="age">Enter Your Age:</label>
    					  <input type="text" name="age" value="" maxlength="3" /><br />
    					  <label for="country">Select Your Country:
    					  <select name="country">
    						 <option selected="selected">United States</option>
    						 <option>United Kingdom</option>
    						 <option>Canada</option>
    						 <option>Australia</option>
    						 <option>Russia</option>
    						 <option>Brazil</option>
    						 <option>Somewhere Else</option>
    					  </select><br />
    						  <input type="submit" value="Sign Me Up!" onclick="" />
    					</form>
    					</div>';
    			writeUserToDatabase($email, $name, $age, $country, $category);
    		}
    		
    		if (isset($_POST["go"]){
    			$email = $_POST["go"];
    			if (isItAValidEmail($email)){
    				showWindowAndValidate();
    			} else {
    				invalidEntry();
    		} else {
    			invalidEntry();
    			}
    		
    		/*test the e-mail address submission for valid entry */
    		function Boolean isItAValidEmail($email){
    			if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    			  return false;
    			} else {
    			  return true;
    			}
    		}
    		
    		function invalidEntry()
    		{
    			return echo'<div id="activeemailbox"><p id="error">You didn\'t enter a valid email, silly!</p><input type="submit" value="Go Back" 		  onclick="goBack()"></div>';
    		}
    		
    		function generateRandom()
    		{
    		
    		}
    		
    		function goBack()
    		{
    			header();
    		}
    		
    		function writeUserToDatabase($email, $name, $age, $country, $category)
    		{
    			$statement = $connection -> prepare("INSERT INTO emailcollection (email, name, age, country, category) VALUES (:email, :name, :age, :country, :category)");
    			$statement -> bindParam(':email', $email)
    			$statement -> bindParam(':name', $name);
    			$statement -> bindParam(':age', $age);
    			$statement -> bindParam(':country', $country);
    			$statement -> bindParam(':category', $category);
    			$statement -> execute();
    		}
    		
    		$connection = null;
    	}
    	//end e-mail box scripting section
    ?>
    There is apparently a problem with the $email variable, it doesn't like the braces in many spots. What have I done incorrectly thus far?

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    I'm... my brain hurts a little bit trying to follow the bouncing code, tbh.

    Which line is it thats throwing the error?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,223
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    First thing that popped up to me was this
    PHP Code:
            function invalidEntry()
            {
                return echo
    '<div id="activeemailbox"><p id="error">You didn\'t enter a valid email, silly!</p><input type="submit" value="Go Back"           onclick="goBack()"></div>';
            } 
    You can't return an echo statement... Or at least you shouldn't be able to! Figure out what you really want to do, do you want to return a value, or echo a string when this function is called. From your code, I think you just want to echo your string, so remove the return statement and leave the rest.

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    I... believe it's still valid syntax (cant test atm). Pointless syntax, but valid. It would return the return of echo, which is void, so you'd get Null ( I think).
    You should still not do this. Either echo straight out, or return the string and echo the return value.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,313
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    I suspect it's because of all the code that's inside the class but not inside a function.

    PHP Code:
            $email " ";
            
    $connection = new PDO('mysql:host=worldreviewgroupcom.*****mysql.com;dbname=emailcollection' "worldreviewgroup" "*******");
            if (!
    $connection){
                die(
    'Could not connect: ' mysql_error());
           } 
    This code is inside the class but not inside the constructor or any other method/function block. Then a little farther down, there's more...

    PHP Code:
            if (isset($_POST["go"]){
                
    $email $_POST["go"];
                if (
    isItAValidEmail($email)){
                    
    showWindowAndValidate();
                } else {
                    
    invalidEntry();
            } else {
                
    invalidEntry();
                } 
    All that inside the class but not inside a function. And there may be still more yet, so keep looking.

    P.S. to the OP: Many more people could have helped you a lot quicker and a lot easier if you had supplied that actual error message. Help us to help you. Also, make sure you keep your code well formatted, especially when you suspected that a stray brace was the problem. Look at your original post and look at the first closing brace. It's lined up with the class brace, but actually it's the closing "if" brace.
    "First make it work. Then make it better."

  6. #6
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yeah, well, I'm trying really hard to learn this stuff. Thanks for all the replies.

    I figured out the return echo hiccup in there, so I just got rid of the return statement because that function is for displaying markup or going back to the previous page after it's done.

    There's a problem with the first line with the $email class variable.

    Parse error: syntax error, unexpected '$email' (T_VARIABLE), expecting function (T_FUNCTION) in C:\xampp\htdocs\index.php on line 392

    , & I also forgot to put in the parentheses in an if statement, but the spot below- it doesn't like the else statement here:

    Code:
    		if (isset($_POST["go"])){
    			$email = $_POST["go"];
    			if (isItAValidEmail($email)){
    				showWindowAndValidate();
    			} else {
    				invalidEntry();
    		} else {
    			invalidEntry();
    		}
    It says there's an error at that bottom else.



    The other spot located is:
    Code:
    $statement -> bindParam(':name', $name);
    It's unfinished as well because I need to create a function that cycles through some random letters and numbers in image files I made to catch spam. I haven't done all that I want to do in the PDO section as well.

  7. #7
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    New code:

    Code:
    <?php
    	  /*This is the scripting section for the e-mail collection box.*/
    	  class CollectEmail
    	  {
    		$email = " ";
    		
    		function showWindowAndValidate()
    		{
    			echo'	<p>Join the Mailing List!</p>
    					<div id="activeemailbox">
    					<form name="form1" method="post" action="">
    					  <label for="confirmemail">Confirm Your E-mail:<span style="color:red">*</span></label>          
    					  <input type="text" name="confirmemail" value="" maxlength="60"/><br />
    					  <label for="name">Enter Your Name:</label>
    					  <input type="text" name="name" value="" maxlength="60" /><br />
    					  <label for="age">Enter Your Age:</label>
    					  <input type="text" name="age" value="" maxlength="3" /><br />
    					  <label for="country">Select Your Country:
    					  <select name="country">
    						 <option selected="selected">United States</option>
    						 <option>United Kingdom</option>
    						 <option>Canada</option>
    						 <option>Australia</option>
    						 <option>Russia</option>
    						 <option>Brazil</option>
    						 <option>Somewhere Else</option>
    					  </select><br />
    						  <input type="submit" value="Sign Me Up!" onclick="" />
    					</form>
    					</div>';
    			writeUserToDatabase($email, $name, $age, $country, $category);
    			
    			/*test the e-mail address submission for valid entry */
    			function isItAValidEmail($email){
    				if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    				  return false;
    				} else {
    				  return true;
    				}
    			}
    		}
    		
    		if (isset($_POST["go"])){
    			$email = $_POST["go"];
    			if (isItAValidEmail($email)){
    				showWindowAndValidate();
    			} else {
    				invalidEntry();
    			}
    		} else {
    			invalidEntry();
    		}
    		
    
    		
    		function invalidEntry()
    		{
    			$markup = '<div id="activeemailbox"><p id="error">You didn\'t enter a valid email, silly!</p><input type="submit" value="Go Back" 		  onclick="goBack()"></div>';
    			echo $markup;
    		}
    		
    		function generateRandom()
    		{
    		
    		}
    		
    		function goBack()
    		{
    			header();
    		}
    		
    		function writeUserToDatabase($email, $name, $age, $country, $category)
    		{
    			$connection = new PDO(
    'mysql:host=worldreviewgroupcom.fatcowmysql.com;dbname=emailcollection' , "worldreviewgroup" , "monkey88");
    		if (!$connection){
    			die('Could not connect.');
    	   }
    			$statement = $connection -> prepare("INSERT INTO emailcollection (email, name, age, country, category) VALUES (:email, :name, :age, :country, :category)");
    			$statement -> bindParam(':email', $email)
    			$statement -> bindParam(':name', $name);
    			$statement -> bindParam(':age', $age);
    			$statement -> bindParam(':country', $country);
    			$statement -> bindParam(':category', $category);
    			$statement -> execute();
    			$connection = null;
    		}
    		
    		
    	}
    	//end e-mail box scripting section
    ?>
    //and it actually still doesn't like the if and else statement, but it's fine with the nested ones.

  8. #8
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,223
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    As Jeff pointed out previously
    PHP Code:
            if (isset($_POST["go"])){
                
    $email $_POST["go"];
                if (
    isItAValidEmail($email)){
                    
    showWindowAndValidate();
                } else {
                    
    invalidEntry();
                }
            } else {
                
    invalidEntry();
            } 
    Is still not within a function. You need to figure out which function, that block of code should be a part of.

    I would also remove this block
    PHP Code:
                /*test the e-mail address submission for valid entry */
                
    function isItAValidEmail($email){
                    if(!
    filter_var($emailFILTER_VALIDATE_EMAIL)) {
                      return 
    false;
                    } else {
                      return 
    true;
                    }
                } 
    Outside of the function showWindowAndValidate()

  9. #9
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes, this helped greatly.

    Now I'm only down to one error, the second bindParam statement for my PDO function in writeUserToDatabase(). Any idea?

    New code
    Code:
    <?php
    	  /*This is the scripting section for the e-mail collection box.*/
    	  class CollectEmail
    	  {
    		
    		function showWindow()
    		{
    			$email = " ";
    			if (isset($_POST["go"])){
    				$email = $_POST["go"];
    				if (isItAValidEmail($email)){
    			} else {
    				invalidEntry();
    			}
    				echo'	<p>Join the Mailing List!</p>
    						<div id="activeemailbox">
    						<form name="form1" method="post" action="">
    						  <label for="confirmemail">Confirm Your E-mail:<span style="color:red">*</span></label>          
    						  <input type="text" name="confirmemail" value="" maxlength="60"/><br />
    						  <label for="name">Enter Your Name:</label>
    						  <input type="text" name="name" value="" maxlength="60" /><br />
    						  <label for="age">Enter Your Age:</label>
    						  <input type="text" name="age" value="" maxlength="3" /><br />
    						  <label for="country">Select Your Country:
    						  <select name="country">
    							 <option selected="selected">United States</option>
    							 <option>United Kingdom</option>
    							 <option>Canada</option>
    							 <option>Australia</option>
    							 <option>Russia</option>
    							 <option>Brazil</option>
    							 <option>Somewhere Else</option>
    						  </select><br />
    							  <input type="submit" value="Sign Me Up!" onclick="writeUserToDatabase()" />
    						</form>
    						</div>';
    				
    				/*test the e-mail address submission for valid entry */
    			} else {
    				invalidEntry();
    			}
    			
    			function isItAValidEmail($email){
    				if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {					  				return false;
    				} else {
    				  return true;
    				}
    			}
    		}
    		
    
    		
    		function invalidEntry()
    		{
    			$markup = '<div id="activeemailbox"><p id="error">You didn\'t enter a valid email, silly!</p><input type="submit" value="Go Back" 		  onclick="goBack()"></div>';
    			echo $markup;
    		}
    		
    		function generateRandom()
    		{
    		
    		}
    		
    		function goBack()
    		{
    			header();
    		}
    		
    		function writeUserToDatabase($email, $name, $age, $country, $category)
    		{
    			$connection = new PDO(
    'mysql:host=w*********.********.com;dbname=emailcollection' , "world********up" , "******");
    		if (!$connection){
    			die('Could not connect.');
    	   }
    			$statement = $connection -> prepare("INSERT INTO emailcollection (email, name, age, country, category) VALUES (:email, :name, :age, :country, :category)");
    			$statement -> bindParam(':email', $email)
    			$statement -> bindParam(':name', $name);
    			$statement -> bindParam(':age', $age);
    			$statement -> bindParam(':country', $country);
    			$statement -> bindParam(':category', $category);
    			$statement -> execute();
    			
    			/* send welcome e-mail and notification to me */
    			function sendEmails();
    			{
    					
    			}
    			$connection = null;
    		}
    		
    		
    	}
    	//end e-mail box scripting section
    ?>

  10. #10
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,223
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    missing a semi-colon on
    PHP Code:
    $statement -> bindParam(':email'$email

  11. #11
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes, thank you! No more syntax errors.

    Now this is the error I'm getting after putting the site files to my local testing server and testing the site. It looks okay visually, but when I try to use the e-mail box form at the bottom, I get this error message:

    Parse error: syntax error, unexpected '$email' (T_VARIABLE) in C:\xampp\htdocs\Scripts\email.php on line 12

    This is the current code
    Code:
    <?php
    	  /*This is the scripting section for the e-mail collection box.*/
    	  class CollectEmail
    	  {
    		
    		function showWindow()
    		{
    			$email = " ";
    			if (isset($_POST["go"])){
    				$email = $_POST["go"];
    				if (isItAValidEmail($email)){
    			} else {
    				invalidEntry();
    			}
    				echo'	<p>Join the Mailing List!</p>
    						<div id="activeemailbox">
    						<form name="form1" method="post" action="">
    						  <label for="confirmemail">Confirm Your E-mail:<span style="color:red">*</span></label>          
    						  <input type="text" name="confirmemail" value="" maxlength="60"/><br />
    						  <label for="name">Enter Your Name:</label>
    						  <input type="text" name="name" value="" maxlength="60" /><br />
    						  <label for="age">Enter Your Age:</label>
    						  <input type="text" name="age" value="" maxlength="3" /><br />
    						  <label for="country">Select Your Country:
    						  <select name="country">
    							 <option selected="selected">United States</option>
    							 <option>United Kingdom</option>
    							 <option>Canada</option>
    							 <option>Australia</option>
    							 <option>Russia</option>
    							 <option>Brazil</option>
    							 <option>Somewhere Else</option>
    						  </select><br />
    							  <input type="submit" value="Sign Me Up!" onclick="writeUserToDatabase()" />
    						</form>
    						</div>';
    				
    				/*test the e-mail address submission for valid entry */
    			} else {
    				invalidEntry();
    			}
    			
    			function isItAValidEmail($email){
    				if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {					  				return false;
    				} else {
    				  return true;
    				}
    			}
    		}
    		
    
    		
    		function invalidEntry()
    		{
    			$markup = '<div id="activeemailbox"><p id="error">You didn\'t enter a valid email, silly!</p><input type="submit" value="Go Back" 		  onclick="goBack()"></div>';
    			echo $markup;
    		}
    		
    		function generateRandom()
    		{
    		
    		}
    		
    		function goBack()
    		{
    			header();
    		}
    		
    		function writeUserToDatabase($email, $name, $age, $country, $category)
    		{
    			$connection = new PDO(
    'mysql:host=blank;dbname=blank' , "username" , "password");
    		if (!$connection){
    			die('Could not connect.');
    	   }
    			$statement = $connection -> prepare("INSERT INTO emailcollection (email, name, age, country, category) VALUES (:email, :name, :age, :country, :category)");
    			$statement -> bindParam(':email', $email);
    			$statement -> bindParam(':name', $name);
    			$statement -> bindParam(':age', $age);
    			$statement -> bindParam(':country', $country);
    			$statement -> bindParam(':category', $category);
    			$statement -> execute();
    			
    			$connection = NULL;
    		}
    		
    		
    	}
    	//end e-mail box scripting section
    ?>

  12. #12
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question

    Actually, in that form's markup there, it had an action attribute of "Scripts/email.php" that was causing it to crash. No error!

    Now it just does nothing after you enter an e-mail address, instead of echoing that small extended form.

    What am I missing for it to make that form come up?

    I'll try adding some CSS styles in for the id of "activeemailbox" that was referenced in that div in that echoed markup.

  13. #13
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,313
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by etidd View Post
    Code:
    			$email = " ";
    			if (isset($_POST["go"])){
    				$email = $_POST["go"];
    				if (isItAValidEmail($email)){
    			} else {
    				invalidEntry();
    			}
    Look at the braces. Make sure they all match up.
    "First make it work. Then make it better."

  14. #14
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question

    Progress so far:

    No syntax errors or errors, but a box sure doesn't at least come up with that echo statement. I'm not telling this to show this 2nd form window right apparently.

    Code PHP:
    Code:
     <?php
    	  /*This is the scripting section for the e-mail collection box.*/
    	  class CollectEmail
    	  {
    		
    		function processEmail()
    		{
    			$email = " ";
    			if (isset($_POST["go"])){
    				$email = $_POST["go"];
    				showWindow();
    			} else {
    				invalidEntry();
    			}
    		}
    	
    		function showWindow()
    		{
    			echo   '<p>Join the Mailing List!</p>
    					<div id="activeemailbox">
    					<form name="form1" method="post" action="">
    					  <label for="confirmemail">Confirm Your E-mail:<span style="color:red">*</span></label>          
    					  <input type="text" name="confirmemail" value="" maxlength="60"/><br />
    					  <label for="name">Enter Your Name:</label>
    					  <input type="text" name="name" value="" maxlength="60" /><br />
    					  <label for="age">Enter Your Age:</label>
    					  <input type="text" name="age" value="" maxlength="3" /><br />
    					  <label for="country">Select Your Country:<span style="color:red">*</span></label>
    					  <select name="country">
    							 <option selected="selected">United States</option>
    							 <option>United Kingdom</option>
    							 <option>Canada</option>
    							 <option>Australia</option>
    							 <option>Russia</option>
    							 <option>Brazil</option>
    							 <option>Somewhere Else</option>
    					   </select><br />
    					   <input type="submit" value="Sign Me Up!" />
    					</form>
    					</div>';
    					
    				$confirmedEmail = $_POST["confirmemail"];
    				$name = $_POST["name"];
    				$age = $_POST["age"];
    				$country = $_POST["country"];
    				$category = getCategory();
    					
    				if (isset($confirmedEmail) && $email == $confirmedEmail){
    					writeUserToDatabase($confirmedEmail, $name, $age, $country, $category);
    				}
    			}
    		}
    			
    		/*test the e-mail address submission for valid entry */
    		function isItAValidEmail($email){
    			if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {					  			return false;
    			} else {
    			  return true;
    			}
    		}
    		
    		function getCategory()
    		{
    			$currentURL= $_SERVER['PHP_SELF'];
    			if (preg_match($currentURL, "index"))
    				return "Home Page";
    			elseif (preg_match($currentURL, "health"))
    				return "Health";
    			elseif (preg_match($currentURL, "insurance"))
    				return "Insurance";
    			elseif (preg_match($currentURL, "general"))
    				return "General";
    			elseif (preg_match($currentURL, "dating"))
    				return "Dating";
    			elseif (preg_match($currentURL, "education"))
    				return "Education";
    			elseif (preg_match($currentURL, "legal"))
    				return "Legal";
    			elseif (preg_match($currentURL, "startyour"))
    				return "Business Opportunities";
    			elseif (preg_match($currentURL, "business"))
    				return "Business Services";
    		}
    		
    		function invalidEntry()
    		{
    			$markup = '<div id="activeemailbox"><p id="error">You didn\'t enter a valid email, silly!</p><input type="submit" value="Go Back" 		  onclick="goBack()"></div>';
    			echo $markup;
    		}
    		
    		function generateRandom()
    		{
    		
    		}
    		
    		function writeUserToDatabase($email, $name, $age, $country, $category)
    		{
    			$connection = new PDO(
    'mysql:host=worldreviewgroupcom.fatcowmysql.com;dbname=emailcollection' , "worldreviewgroup" , "monkey88");
    		if (!$connection){
    			die('Could not connect.');
    	   }
    			$statement = $connection -> prepare("INSERT INTO emailcollection (email, name, age, country, category) VALUES (:email, :name, :age, :country, :category)");
    			$statement -> bindParam(':email', $email);
    			$statement -> bindParam(':name', $name);
    			$statement -> bindParam(':age', $age);
    			$statement -> bindParam(':country', $country);
    			$statement -> bindParam(':category', $category);
    			$statement -> execute();
    			
    			$connection = NULL;
    			goBack();
    		function goBack()
    		{
    			header();
    		}
    		}
    		
    		
    	//end e-mail box scripting section
    ?>
    Maybe this has to do with the form onclick attributes that I'm trying to use. Maybe the echoed form's submit input needs an onclick value.

    Markup:
    Code:
          <form id="emailbox" name="form1" method="post">
            <div>
              <input type="text" name="go" id="go" value="your e-mail" onclick="input_focus(this)"  onblur="input_reset(this)" maxlength="60"/>
              <input type="submit" value="Join" onclick="showWindow()" />
            </div>
          </form>

  15. #15
    Non-Member
    Join Date
    Oct 2007
    Posts
    363
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    You shouldn't be echoing any html at all out of your functions. You're just making your code very hard to change in the future.

    Also, this isn't object oriented code by the way. It's just a bunch of functions wrapped in an object, which is not what OOP is all about...

  16. #16
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,223
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aaarrrggh View Post
    You shouldn't be echoing any html at all out of your functions. You're just making your code very hard to change in the future.

    Also, this isn't object oriented code by the way. It's just a bunch of functions wrapped in an object, which is not what OOP is all about...
    Thank you for saying what I was thinking earlier and didn't have time to post

    @etidd ; One of your fatal flaws in your current code is the fact that you have your presentation (your e-mail form) inside a PHP echo statement, or really, inside PHP period. There are many good reasons to keep your presentation and your business logic (your validation, processing the form submission, etc) separate.

    The biggest is, your presentation is static content. You can have a basic HTML page with that form in it and you will then ALWAYS get the output you expect when you pull up that page. By simply doing that step alone, you are making things much easier for yourself, as now you can ALWAYS get to the form you expect to see.

    The action of the form would still point to your script. Which will then process the form submission, validate it, and then send the email accordingly. Thus now you have two files with two distinct purposes. The first is solely to show the form to the user, the latter is to actually process the form submission.

  17. #17
    Non-Member
    Join Date
    Oct 2007
    Posts
    363
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Thank you for saying what I was thinking earlier and didn't have time to post

    @etidd ; One of your fatal flaws in your current code is the fact that you have your presentation (your e-mail form) inside a PHP echo statement, or really, inside PHP period. There are many good reasons to keep your presentation and your business logic (your validation, processing the form submission, etc) separate.

    The biggest is, your presentation is static content. You can have a basic HTML page with that form in it and you will then ALWAYS get the output you expect when you pull up that page. By simply doing that step alone, you are making things much easier for yourself, as now you can ALWAYS get to the form you expect to see.

    The action of the form would still point to your script. Which will then process the form submission, validate it, and then send the email accordingly. Thus now you have two files with two distinct purposes. The first is solely to show the form to the user, the latter is to actually process the form submission.
    Yeah. I MAY have a go at re-writing some of this to show him what we're on about later. I can't promise this though as I'm really busy and don't have much time.

    The general idea though is to keep the presentation and business logic separate. Your functions should only be interested in logic and should contain no html or anything like that.

    Also - when it comes to OOP, don't be too disheartened. I started off writing similar code, in that I thought objects were just places to stick a bunch of functions together. I coded like that for some time. It wasn't until I started reading about design patterns and found out about stuff like polymorphism until I realised I'd been doing it wrong.

    I can't promise I'll rewrite stuff to show you as I really don't have much time, but perhaps, depending on how I'm doing later :-)

  18. #18
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Okay, I see what you're saying. I should create an object and initialize the- methods (Java)- functions with that object.

    I also see what you're saying about the cohesion of my class file, and they should be in two different files that serve their described purposes. This class seems to be very jumbled, and it's also static because no object is initializing functions. I will attempt to look up how to create an object suitable for running said functions, but if you may provide a guiding light there, I will go ahead and take this on to clean up this code.

  19. #19
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,313
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by aaarrrggh View Post
    You shouldn't be echoing any html at all out of your functions. You're just making your code very hard to change in the future.

    Also, this isn't object oriented code by the way. It's just a bunch of functions wrapped in an object, which is not what OOP is all about...
    Although I wholeheartedly agree, I feel like we should get the OP through these basic syntax errors before we delve into software architecture.

    @OP

    I hate to sound like a broken record, but you really, really, really need to make sure your braces line up correctly. Look at the last brace in this code below. It looks like you're closing the function, but actually you're closing the class.

    PHP Code:
    <?php
          
    /*This is the scripting section for the e-mail collection box.*/
          
    class CollectEmail
          
    {
            
            function 
    processEmail()
            {
                
    $email " ";
                if (isset(
    $_POST["go"])){
                    
    $email $_POST["go"];
                    
    showWindow();
                } else {
                    
    invalidEntry();
                }
            }
        
            function 
    showWindow()
            {
                echo   
    '<p>Join the Mailing List!</p>
                        <div id="activeemailbox">
                        <form name="form1" method="post" action="">
                          <label for="confirmemail">Confirm Your E-mail:<span style="color:red">*</span></label>          
                          <input type="text" name="confirmemail" value="" maxlength="60"/><br />
                          <label for="name">Enter Your Name:</label>
                          <input type="text" name="name" value="" maxlength="60" /><br />
                          <label for="age">Enter Your Age:</label>
                          <input type="text" name="age" value="" maxlength="3" /><br />
                          <label for="country">Select Your Country:<span style="color:red">*</span></label>
                          <select name="country">
                                 <option selected="selected">United States</option>
                                 <option>United Kingdom</option>
                                 <option>Canada</option>
                                 <option>Australia</option>
                                 <option>Russia</option>
                                 <option>Brazil</option>
                                 <option>Somewhere Else</option>
                           </select><br />
                           <input type="submit" value="Sign Me Up!" />
                        </form>
                        </div>'
    ;
                        
                    
    $confirmedEmail $_POST["confirmemail"];
                    
    $name $_POST["name"];
                    
    $age $_POST["age"];
                    
    $country $_POST["country"];
                    
    $category getCategory();
                        
                    if (isset(
    $confirmedEmail) && $email == $confirmedEmail){
                        
    writeUserToDatabase($confirmedEmail$name$age$country$category);
                    }
                }
            }
    Second thing: Based on your code, I suspect you come from a Java background. In Java, you could call methods like you would normal functions (e.g., showWindow()). But the same isn't true in PHP. From inside your class, if you call a static method, it has to be written self::showWindow(), and if you call an instance method, it has to be written $this->showWindow(). And the same is true of class fields: self::$email for static, and $this->email for instance.
    "First make it work. Then make it better."

  20. #20
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hello everyone,

    I have broken this code out into 6 different php files, all with designated class names. I added an HTML file called showwindow.html containing the original index page plus the 2nd form with name,age,country,category, linked to a new style sheet that I've created named emailsubmit.css with the new form. This will take a second, but I'll lay out what I have.

    I'd like to make the rest of the page be gray except for the form2 html.

    I'm trying to debug the HTML markup because it's not validating and the entire style sheet is not being applied.

    index.php
    Code:
          <?php
    	  //this section is for the e-mail box scripting to begin
    	  class PassEmail
    	  {
    		  function postEmail()
    		  {
    			  include 'Scripts/emailsubmission.php';
    			  $emailPasser = new ProcessEmail;
    			  include 'Scripts/finalactions.php';
    			  $error = new FinalActions;
    		
    			  if (isset($_POST["go"])){
    			  	$email = $_POST["go"];
    				$emailPasser -> getEmail($email);
    			  } else {
    				$error -> invalidEntry();
    			  }
    		  }
    	  }
    	  //end e-mail box scripting section
    	  ?>
    emailsubmission.php
    Code:
    <?php
    	class ProcessEmail
    	{
    		function gatherEmail()
    		{
    			$categoryFinder = new CategoryFinder;
    			include 'categoryfinder.php';
    			$databaseWriter = new DatabaseWriter;
    			include 'databasewriter.php';
    			$emailSender = new EmailSender;
    			include 'emailsender.php';
    			$spamCatcher = new SpamCatcher;
    			include 'spamcatcher.php';
    			$showForm = new ShowWindow;
    			include 'showwindow.php';
    
    			$showForm -> showWindow();
    				
    				if (isset($confirmedEmail) && $email == $confirmedEmail){
    					writeUserToDatabase($confirmedEmail, $name, $age, $country, $category);
    				} else {
    					invalidEntry();
    				}
    			}
    			
    			public function getEmail($email)
    			{
    				$enteredEmail = $email;
    			}
    		}
    ?>
    emailtester.php
    Code:
    <?php
    	class EmailTester
    	{
    		public function isItAValidEmail($email)
    		{
    			if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {					  			
    			return false;
    			} else {
    			  return true;
    			}
    		}
    	}
    ?>
    emailsender.php
    Code:
    <?php
    	class EmailSender{
    		function sendWelcomeEmail()
    		{
    			
    		}
    	}
    ?>
    databasewriter.php
    Code:
    <?php
    	class DatabaseWriter
    	{
    		public function writeUserToDatabase($email , $name , $age , $country , $category)
    		{
    			$connection = new PDO(
    'mysql:host=hostname;dbname=emailcollection' , "user" , "password");
    		if (!$connection){
    			die('Could not connect.');
    	   }
    			$statement = $connection -> prepare("INSERT INTO emailcollection (email, name, age, country, category) VALUES (:email, :name, :age, :country, :category)");
    			$statement -> bindParam(':email', $email);
    			$statement -> bindParam(':name', $name);
    			$statement -> bindParam(':age', $age);
    			$statement -> bindParam(':country', $country);
    			$statement -> bindParam(':category', $category);
    			$statement -> execute();
    			
    			$connection = NULL;
    		}
    	}
    ?>
    categoryfinder.php
    Code:
    <?php
    	class CategoryFinder
    	{
    		public function getCategory()
    		{
    			$currentURL= $_SERVER['PHP_SELF'];
    			if (preg_match($currentURL, "index"))
    				return "Home Page";
    			elseif (preg_match($currentURL, "health"))
    				return "Health";
    			elseif (preg_match($currentURL, "insurance"))
    				return "Insurance";
    			elseif (preg_match($currentURL, "general"))
    				return "General";
    			elseif (preg_match($currentURL, "dating"))
    				return "Dating";
    			elseif (preg_match($currentURL, "education"))
    				return "Education";
    			elseif (preg_match($currentURL, "legal"))
    				return "Legal";
    			elseif (preg_match($currentURL, "startyour"))
    				return "Business Opportunities";
    			elseif (preg_match($currentURL, "business"))
    				return "Business Services";
    		}
    	}
    ?>
    finalactions.php
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    	<body>
        <div id="active"><p id="error">You didn&apos;t enter a valid email, silly!</p><input type="submit" value="Go Back" 	onclick="goBack()"></div>
        <?php
    		class FinalActions
    		{
    			public function invalidEntry()
    			{
    			
    			}
    			private function goBack()
    			{
    				header();
    			}
    		}
    	?>
    	</body>
    </html>
    spamcatcher.php
    Code:
    <?php
    	class SpamCatcher
    	{
    		public function generateCapture()
    		{
    			
    		}
    	}
    ?>
    I'll be working on validation of the markup. Hopefully this will end the styles not being applied.

    I probably have a CSS-based question with trying to make the area outside the email submit have a semi-transparent gray mask. See div with id graybox.

    showwindow.html
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       	<link href="style/main.css" type="text/css" media="screen, projection, tv" />
        <link href="style/emailsubmit.css" type="text/css" media="screen, projection, tv" />
        <link href="style/dropdownmenus.css" type="text/css" media="screen, projection, tv" />
        <title>Join the Mailing List at World Review Group!</title>
    </head>
    	<body>
        <!-- begin container -->
    <div id="graymask">
    <div id="container">
    <!-- begin middle div -->
      <div id="middle">
      <!--header with image -->
        <h1>World Review Group<span></span></h1>
        <div id="body">
          <p id="welcomestatement">Hello everyone, <br />
            This site is dedicated to consumer reviews on current products in many different markets. This site is here to promote the good ones and expose the bad ones. Thank you for visiting!</p>
          <div id="wrapper">
            <!-- begin Personal navigation menu -->
            <ul id="pMenu">
              <li><a href="health.html" title="Health Page">health</a>
                <!-- begin health -->
                <div id="health">
                  <!-- weight loss -->
                  <h2>weight loss &amp; wellness</h2>
                  	  <!-- fitness -->
                      <h3><span>fitness</span></h3>
                      <ul>
                        <li><a href="health/fitness/weiderpowerbell1.html">Weider PowerBell</a></li>
                        <li><a href="health/fitness/brazilbuttlift1.html">Brazil Butt Lift</a></li>
                        <li><a href="health/fitness/georgesstpierre1.html">MMA Training with Georges St. Pierre</a></li>
                        <li><a href="health/fitness/turbofire1.html">TurboFire Fitness</a></li>
                      </ul>
                      <!-- dieting -->
                      <h3><span>dieting</span></h3>
                      <ul>
                        <li><a href="health/dieting/healthetrimdiet1.html">Health&eacute; Trim Diet</a></li>
                        <li><a href="health/dieting/southbeach1.html">South Beach Diet</a></li>
                      </ul>
                      <!-- supplements -->
                      <h2>supplements</h2>
                      <ul>
                        <li><a href="health/Rx/nutrilitevitamins1.html">Nutrilite Multivitamins</a></li>
                        <li><a href="health/Rx/dochangover1.html">Doc Hangover Cure</a></li>
                        <li><a href="health/Rx/libigrow1.html">Libigrow</a></li>
                        <li><a href="health/Rx/smokedeter1.html">Smoke Deter</a></li>
                        <li><a href="health/Rx/prorexin1.html">Prorexin</a></li>
                      </ul>
                <!-- skin care -->
                <h2>skin care</h2>
                  <ul>
                    <li><a href="health/skincare/shivaacne1.html">Shiva23 Acne Cream</a></li>
                    <li><a href="health/skincare/deadseamineral1.html">Dead Sea Mineral Cellulite Treatment</a></li>
                  </ul>
                </div>
                <!-- end health -->
              </li>
              <li><a href="insurance.html" title="Insurance Page">insurance</a>
                <!-- begin insurance -->
                <div id="insurance">
                  <!-- property insurance -->
                  <h2><a href="insurance/propertyinsurance1.html">home&frasl;property insurance</a></h2>
                  <ul>
                    <li><a href="insurance/usinsurancepropertyreview1.html">USInsuranceOnline.com &ndash; Property</a></li>
                  </ul>
                  <!-- auto insurance -->
                  <h2><a href="insurance/autoinsurance1.html">auto insurance</a></h2>
                  <ul>
                    <li><a href="insurance/bestquotesautoreview1.html">BestQuotes.com</a></li>
                    <li><a href="insurance/insuremycar4lessreview1.html">InsureMyCar4Less</a></li>
                    <li><a href="insurance/lowermycarinsuranceratereview1.html">Lower My Car Insurance Rate</a></li>
                    <li><a href="insurance/atlascarinsurancereview1.html">Atlas Car Insurance</a></li>
                    <li><a href="insurance/insurancecomparisonreview1.html">Insurance Comparison</a></li>
                  </ul>
                  <!-- health insurance -->
                  <h2><a href="insurance/healthinsurance1.html">health insurance</a></h2>
                  <ul>
                    <li><a href="insurance/betterhealthquotereview1.html">Better Health Quote</a></li>
                    <li><a href="insurance/healthinsurancesourcesreview1.html">Health Insurance Sources</a></li>
                    <li><a href="insurance/americanhealthcarecenterreview1.html">American Health Care Center Review</a></li>
                    <li><a href="insurance/bestquoteshealthreview1.html">BestQuotes.com &ndash; Health</a></li>
                  </ul>
                  <!-- life insurance -->
                  <h2><a href="insurance/lifeinsurance1.html">life insurance</a></h2>
                  <ul>
                    <li><a href="insurance/americaninsurancereview1.html">American Insurance</a></li>
                    <li><a href="insurance/usinsurancelife1.html">USInsuranceOnline.com &ndash; Life</a></li>
                  </ul>
                </div>
                <!-- end insurance -->
              </li>
              <li><a href="general.html" title="General Page">general</a>
              	<!-- begin general -->
                <div id="general">
                  <!-- electronics -->
                  <h2>electronics</h2>
                      <!-- gaming -->
                      <h3><span>gaming</span></h3>
                      <ul>
                        <li><a href="gaming/haltgamereview1.html">Halt Game</a></li>
                        <li><a href="gaming/battlestargalactica1.html">Battlestar Galactica</a></li>
                        <li><a href="gaming/gsn1.html">GSN Gaming</a></li>
                      </ul>
                      <!-- electronic gadgets -->
                      <h3><span>electronic gadgets</span></h3>
                      <ul>
                        <li><a href="electronics/kindle1.html">Kindle e&ndash;Reader</a></li>
                        <li><a href="electronics/ecig1.html">Electronic Cigarettes</a></li>
                      </ul>
                  <!-- style and fashion -->
                  <h2>style &amp; fashion</h2>
                  	  <!-- makeup -->
                      <h3><span>makeup</span></h3>
                      <ul>
                        <li><a href="makeup/dinair1.html">Dinair Airbrush Makeup</a></li>
                        <li><a href="makeup/simplykaren1.html">Simply Karen</a></li>
                      </ul>
                  <!-- food/dining -->
                  <h2>food&frasl;dining</h2>
                  	  <!-- net grocers -->
                      <h3><span>net grocers</span></h3>
                      <ul>
                        <li><a href="food/efooddepot1.html">eFood Depot</a></li>
                        <li><a href="food/peapod1.html">Peapod</a></li>
                      </ul>
                      <!-- coupons -->
                      <h3><span>coupons</span></h3>
                      <ul>
                        <li><a href="coupons/brandcaster1.html">Brandcaster Coupons</a></li>
                      </ul>
                  <!-- cars/auto -->
                  <h2>cars&frasl;auto</h2>
                  <ul>
                    <li><a href="auto/carfax1.html">Carfax Vehicle History Reports</a></li>
                    <li><a href="auto/carprices1.html">CarPrices.com</a></li>
                  </ul>
                  <!-- security -->
                  <h2>security</h2>
                  <ul>
                    <li><a href="security/adtalarm1.html">ADT Alarm System</a></li>
                  </ul>
                  <!-- hobby -->
                  <h2>hobby</h2>
                  	  <!-- music -->
                      <h3><span>music</span></h3>
                      <ul>
                        <li><a href="music/guitartricksreview1.html">GuitarTricks</a></li>
                        <li><a href="music/jamoramareview1.html">Jamorama&ndash; Learn Guitar</a></li>
                      </ul>
                </div>
                <!-- end general -->
              </li>
              <li><a href="dating.html" title="Dating Page">dating</a>
                <!-- begin dating -->
                <div id="dating">
                <!-- dating sites -->
                <h2>dating sites</h2>
                  <ul>
                    <li><a href="dating/realmaturesingles1.html">RealMatureSingles</a></li>
                    <li><a href="dating/seniorpeoplemeet1.html">SeniorPeopleMeet</a></li>
                    <li><a href="dating/adultfriendfinder1.html">Adult Friend Finder</a></li>
                    <li><a href="dating/benaughty1.html">BeNaughty.com</a></li>
                    <li><a href="dating/untrue1.html">Untrue.com</a></li>
                    <li><a href="dating/elitemate1.html">EliteMate</a></li>
                    <li><a href="dating/pridedating1.html">Pride Dating (gay)</a></li>
                    <li><a href="dating/speeddate1.html">SpeedDate.com</a></li>
                  </ul>
                 <!-- books and advice -->
                 <h2>books &amp; advice</h2>
                   <ul>
                   	 <li><a href="dating/askapril1.html">Ask April</a></li>
                     <li><a href="dating/bounceback1.html">Bounce Back to Dating Formula</a></li>
                     <li><a href="dating/datingsecrets1.html">Dating Secrets</a></li>
                   </ul>
                </div>
                <!-- end dating -->
              </li>
              <li><a href="education.html" title="Education Page">education</a>
                <!-- begin education -->
                <div id="education">
                  <ul>
                    <li><a href="education/scholzone1.html">Scholarship Zone</a></li>
                    <li><a href="education/speedstudytechniques1.html">Speed Study Techniques</a></li>
                    <li><a href="education/stimulusgrants1.html">Stimulus Grants</a></li>
                    <li><a href="education/teachmetoday1.html">Teach Me Today</a></li>
                    <li><a href="education/winningsurveys1.html">Winning Surveys</a></li>
                    <li><a href="education/basicskillsassessments1.html">Basic Skills Assessments</a></li>
                  </ul>
                </div>
                <!-- end education -->
              </li>
              <li><a href="legal.html" title="Legal Page">legal</a>
                <!-- begin personal legal -->
                <div id="pLegal">
                <ul>
                  <li><a href="debt/urgenthomerelief1.html">Urgent Home Relief</a></li>
                </ul>
                <!-- mortgage -->
                <h2>mortgage</h2>
                <ul>
                  <li><a href="mortgage/foreclosurefighter1.html">Home Foreclosure Fighter</a></li>
                  <li><a href="mortgage/fastcash4homes1.html">Fast Cash 4 Homes</a></li>
                </ul>
                <!-- debt -->
                <h2>debt</h2>
                	<!-- bankruptcy -->
                    <h3><span><a href="legal/bankruptcy1.html">bankruptcy</a></span></h3>
                    <ul>
                      <li><a href="debt/evalbankruptcy1.html">Bankruptcy Lawyer Finder</a></li>
                      <li><a href="legal/bankruptcy1.html">Bankruptcy Attorney Finder</a></li>
                    </ul>
                    <!-- credit debt -->
                    <h3><span><a href="legal/creditdebt1.html">credit debt</a></span></h3>
                <ul>
                  <li><a href="debt/debtnegotiator1.html">Debt Negotiator</a></li>
                </ul>
                <!-- divorce -->
                <h2>divorce</h2>
                <ul>
                  <li><a href="legal/divorcedocuments1.html">Divorce Documents</a></li>
                </ul>
                <!-- defense attorney -->
                <h2>defense attorney</h2>
                <ul>
                  <li><a href="legal/DUIattorney1.html">DUI Attorney</a></li>
                </ul>
                <!-- will creation -->
                <h2>will creation</h2>
                <ul>
                  <li><a href="legal/willcreation1.html">Create My Will</a></li>
                </ul>
                </div>
                <!-- end personal legal -->
              </li>
            </ul>
    </li>
            <!-- end Personal navigation menu-->
            <!-- begin Business navigation menu-->
            <ul id="bMenu">
              <li><a href="startyourownbusiness.html" title="Business Opportunities Page">business opportunities</a>
                <!-- business opportunities -->
                <div id="bizopps">
                  <ul>
                    <li><a href="bizopps/mobilemassmoney1.html">Mobile Mass Money</a></li>
                    <li><a href="bizopps/autopilothomeprofits.html">Autopilot Home Profits</a></li>
                    <li><a href="bizopps/anthonymorrison1.html">Anthony Morrison&apos;s Big Profits Secret</a></li>
                  </ul>
                  <!-- home business scams -->
                  <h2>home business scams</h2>
                  <ul>
                  	<li><a href="bizopps/medicalbillinghomebusiness1.html">The Medical Billing Home Business Bible</a></li>
                  </ul>
                  <!-- medical -->
                  <h2>medical</h2>
                  <ul>
                    <li><a href="bizopps/freesitesignup1.html">Cash&ndash;Pulling Affiliate Marketing Websites</a></li>
                    <li><a href="bizopps/biggerbloggingprofitsreview1.html">Bigger Blogging Profits</a></li>
                  </ul>
                  <!-- affiliate marketing -->
                  <h2>affiliate marketing</h2>
                  <ul>
                    <li><a href="bizopps/milliondollarpips1.html">Pips Forex Trading Robot</a></li>
                    <li><a href="bizopps/pennystockprophet1.html">The Penny Stock Prophet</a></li>
                  </ul>
                  <!-- trading/investing -->
                  <h2>trading&frasl;investing</h2>
                  <ul>
                    <li><a href="bizopps/swagbucks1.html">Swag Bucks</a></li>
                  	<li><a href="bizopps/corsentialsurvey1.html">Corsential</a></li>
                  </ul>
                  <h2><a href="bizopps/makemoneywithsurveys1.html">surveys</a></h2>
                  <ul>
                  	<li><a href="bizopps/thepeoplesprogram1.html">The People&apos;s Program</a></li>
                  </ul>
                </div>
                <!-- end business opportunities -->
              </li>
              <li><a href="businessservices.html" title="Business Services Page">business services</a></li>
              	<!-- business services -->
                <div id="bizservices">
                  <ul>
                  	<li><a href="bizopps/lessthantruckloadshipping1.html">Top Flight Concepts</a></li>
                  </ul>
                  <!-- shipping solutions -->
                  <h2>shipping solutions</h2>
                  <ul>
                    <li><a href="telecommasterquoteagency1.html">Telecom Master Quote Agency</a></li>
                  </ul>
                  <!-- technology solutions -->
                  <h2>technology solutions</h2>
                  <ul>
                    <li><a href="bizservices/projmgmttemplates1.html">Project Management Templates</a></li>
                  </ul>
                  <!-- project management -->
                  <h2>project management</h2>
                </div>
                <!-- end business services -->
              </li>
              <li><a href="legal.html" title="Legal Services Page">legal services</a>
                <!-- begin business legal -->
                <div id="bLegal">
                    <ul>
                      <li><a href="legal/willcreation1.html">Create My Will</a></li>
                    </ul>
                <!-- will creation -->
                <h2>will creation</h2>
                    <ul>
                      <li><a href="legal/DUIattorney1.html">DUI Attorney</a></li>
                    </ul>
                <!-- defense attorney -->
                <h2>defense attorney</h2>
                    <ul>
                      <li><a href="legal/divorcedocuments1.html">Divorce Documents</a></li>
                    </ul>
                <!-- divorce -->
                <h2>divorce</h2>
                    <ul>
                      <li><a href="debt/debtnegotiator1.html">Debt Negotiator</a></li>
                    </ul>
                    <!-- credit debt -->
                    <h3><span><a href="legal/creditdebt1.html">credit debt</a></span></h3>
                        <ul>
                          <li><a href="debt/evalbankruptcy1.html">Bankruptcy Lawyer Finder</a></li>
                          <li><a href="legal/bankruptcy1.html">Bankruptcy Attorney Finder</a></li>
                        </ul>
                    <!-- bankruptcy -->
                    <h3><span><a href="legal/bankruptcy1.html">bankruptcy</a></span></h3>
                <!-- debt -->
                <h2>debt</h2>
                    <ul>
                      <li><a href="mortgage/foreclosurefighter1.html">Home Foreclosure Fighter</a></li>
                      <li><a href="mortgage/fastcash4homes1.html">Fast Cash 4 Homes</a></li>
                    </ul>
                <!-- mortgage -->
                <h2>mortgage</h2>
                    <ul>
                      <li><a href="debt/urgenthomerelief1.html">Urgent Home Relief</a></li>
                    </ul>
                </div>
                <!-- end business legal -->
              </li>
            </ul>
            <!-- end Business navigation menu-->
          </div>
          <!-- end wrapping div -->
        </div>
        <!-- end body div -->
        <div id="footer">&nbsp;</div>
        <!-- end footer div -->
        <h3 id="copytagatbottom">&copy;WorldReviewGroup.com<br />
          Updated Dec 14, 2012</h3>
      </div>
      <!-- end middle div -->
    
    	<!-- begin side windows -->
      <div id="leftside">
        <div id="leftsideend">&nbsp;</div>
        <div id="leftsidebody">
          <h2 class="sideWindowHeaderText">Most Popular</h2>
          <ul class="sideWindowLinks">
            <li><a href="food/peapod1.html">Peapod</a></li>
            <li><a href="health/dieting/southbeach1.html">South Beach Diet</a></li>
            <li><a href="coupons/brandcaster1.html">Brandcaster Coupons</a></li>
          </ul>
        </div>
        <div id="leftsidestart">&nbsp;</div>
      </div><!-- end leftside div -->
      <div id="rightside"><!-- begin rightside div -->
        <div id="rightsidestart">&nbsp;</div>
        <div id="rightsidebody">
          <h2 class="sideWindowHeaderText">Not Recommended</h2>
          <ul class="sideWindowLinks">
            <li><a href="#">Anthony Morrison&apos;s Big Profits Secret</a></li>
            <li><a href="#">Mobile Mass Media</a></li>
            <li><a href="#">Prorexin</a></li>
          </ul>
          <form id="emailbox" name="form1" method="post" action="showwindow.html">
            <div>
              <input type="text" name="go" id="go" value="your e-mail" onclick="input_focus(this)"  onblur="input_reset(this)" maxlength="60"/>
              <input type="submit" value="Join" onclick="postEmail()" />
            </div>
          </form>
          </div>
          <div id="rightsideend">&nbsp;</div>
      </div>
      <!-- end side windows -->
    					<form name="form2" id="form2" method="post">
    					  <label for="confirmemail">Confirm Your E-mail:<span>*</span></label>          
    					  <input type="text" name="confirmemail" value="" maxlength="60"/><br />
    					  <label for="name">Enter Your Name:</label>
    					  <input type="text" name="name" value="" maxlength="60" /><br />
    					  <label for="age">Select Your Age Range:</label>
                          <select name="age">
                          	<option selected="selected">18&ndash;35</option>
                            <option>36&ndash;55</option>
                            <option>55+</option>
                            <option>17 or Younger</option>
                          </select>
    					  <input type="text" name="age" value="" maxlength="3" /><br />
    					  <label for="country">Select Your Country:<span>*</span></label>
    					  <select name="country">
    							 <option selected="selected">United States</option>
    							 <option>United Kingdom</option>
    							 <option>Canada</option>
    							 <option>Australia</option>
    							 <option>Russia</option>
    							 <option>Brazil</option>
    							 <option>Somewhere Else</option>
    					   </select><br />
    					   <input type="submit" value="Sign Me Up!" />
    					</form>
    			</div>
            </div><!-- end container -->
            </div><!-- end gray mask -->
    	</body>
    </html>
    emailsubmit.css
    Code:
    @charset "utf-8";
    /* CSS Document for the E-mail Submission Form */
    #graymask{
    	height:1000px;
    	width:1360px;
    	background:#999;
    	opacity:40;
    	filter:alpha(opacity=50);
    	z-index:99;
    }
    
    #form2{
    	background:url("emailsubmission.gif") no-repeat scroll 50% 0 transparent;
    	width:360px;
    	height:300px;
    	margin-left:0;
    	text-align:center;
    	opacity:100;
    	filter:alpha(opacity=100);
    	z-index:999;
    }
    #form2 span{
    	color:red;
    }

  21. #21
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I'm late to this party, but some thoughts on this:

    PHP Code:
    <?php
        
    class CategoryFinder
        
    {
            public function 
    getCategory()
            {
                
    $currentURL$_SERVER['PHP_SELF'];
                if (
    preg_match($currentURL"index"))
                    return 
    "Home Page";
                elseif (
    preg_match($currentURL"health"))
                    return 
    "Health";
                elseif (
    preg_match($currentURL"insurance"))
                    return 
    "Insurance";
                elseif (
    preg_match($currentURL"general"))
                    return 
    "General";
                elseif (
    preg_match($currentURL"dating"))
                    return 
    "Dating";
                elseif (
    preg_match($currentURL"education"))
                    return 
    "Education";
                elseif (
    preg_match($currentURL"legal"))
                    return 
    "Legal";
                elseif (
    preg_match($currentURL"startyour"))
                    return 
    "Business Opportunities";
                elseif (
    preg_match($currentURL"business"))
                    return 
    "Business Services";
            }
        }
    ?>
    This avoids the hidden dependency on SERVER vars, you can send in the SERVER var as an argument, or use it in other places now.

    PHP Code:
    function getCategory($currentURL 'index'){  // optionally set a default here in case it gets called with no args

    // maintain an array of services, easier to read and add/delete entries
    // you are less likely to make a typing error
    // avoids using regexes in a loop too
    // this could be imported from somewhere else also

    $lookup = array(
    'business' =>'Business Services',
    'dating' =>'Dating',
    'education' =>'Education',
    'general' =>'General',
    'health' =>'Health',
    'index' =>'Home page',
    'insurance' =>'Insurance',
    'legal' =>'Legal',
    'startyour' =>'Business Opportunities',
    );

      if(
    array_key_exists($currentURL$lookup) ) {
        return 
    $lookup[$currentURL];
      }else{
        return 
    'Home Page';  // or something else
      
    }

    }

    echo 
    getCategory("education");
    echo 
    getCategory("some old crap");
    echo 
    getCategory(); 
    Gives:

    Education
    Home Page
    Home Page

    When you are clear about how you want to handle failure, that code could be tidied up more.

    Might be better called categoryLookup(), though that is more a trivial personal POV.

  22. #22
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I see what you're saying. I guess SERVER variables, or any global variables, are not desirable in one's code and should be avoided- for some reason I'm unclear on.

    As far as error handling goes, the code may continue on uninhibited regardless of success or failure. It's just a little something extra for me to know about a new user.

    There is no room for human input error. There is no section for typing in the category. It is automatically computed, and the user does not know their "category" has been filed.


    Anyway:
    I specified the action attribute for the original form submit to direct the browser from index.php to showwindow.html, which is the original index page plus the form markup for the name, age, etc. I'm sure some of you understand how it's been set up so far. Maybe this isn't set up correctly for just simply graying out the rest of the page and displaying the 2nd form after the user originally input their e-mail address on index.php at worldreviewgroup.com. Is there a better way to do this than currently? I've seen this same effect on many websites.

    As far as the styles go for showwindow.html, I made a post in the CSS section to find out why I'm not seeing any styles applied to showwindow.html. If you can be of assistance there, the thread is located here

  23. #23
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,223
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by etidd View Post
    I see what you're saying. I guess SERVER variables, or any global variables, are not desirable in one's code and should be avoided- for some reason I'm unclear on.
    The reason for this specifically is re-usability. If your class depends on the SERVER variable, you can't reuse the class unless that SERVER variable is populated or available. By passing in the SERVER variable value either through your constructor or method as a parameter, you have just increased your re-usability by 10 fold. You can now call that class from anywhere without any dependency to the SERVER variable (you can pass in the value you want it to use) so it performs the task you expect.

  24. #24
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that explanation. I learned more about web development.

    However- as my general strategy: I'm still looking to confirm that I'm on the right track.

    -when user inputs the e-mail address originally, I am attempting to open another html file with the same markup plus an extra form.
    -The background except the new form is wrapped in a div with an id of #graymask. That would make a gray, opaque box around all the other content, rendering it inactive, and leave the 2nd confirmation form open.

    Thanks for your help.

  25. #25
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Oh, well. It looks like everyone has left the party.

    Can't really ask for too much when the responses are provided free of charge.

    Gonna go try to find some good examples of PHP forms that do something similar to what I'm trying to do.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •