Page 1 of 1

Functions being show at the top of the page.

Posted: Thu Feb 03, 2011 1:43 pm
by Domsore
So this is the code I have:

Code: Select all

<?php
/**
 * Description of registerClass
 *
 * @author Dominic Sore
 */
class registerClass {

    public function getPlatform(){
	$result = mysql_query('SELECT * FROM sys_platform') OR die(mysql_error());
	$template = mysql_fetch_array($result) OR die(mysql_error());
    }

    public function incCountries(){
	include_once(TPATH_BASE.DS.'components'.DS.'componentControllers'.DS.'register'.DS.'registerCountries.php');
    }

    public function dobFunc(){
	$Tyear = date(Y);
	$year = $Tyear - 18;

	echo '<select id="user_dob" name="user_dob">';

	for($i=0; $i<=80; $i++){
	    echo '<option value="'.$year.'">'.$year.'</option>';
	    $year = $year - 1;
	}

	echo '</select>';

    }

    public function startForm(){
	echo '<form action="<?php echo $_SERVER[\'PHP_SELF\']; ?>" method="post" enctype="multipart/form-data" name="register">';
    }

    public function endForm(){
	echo '</form>';
    }

    public function createPersonal(){
	echo '<div id="inner_box">
<div id="inner_header">Personal Info</div>
<div id="inner_content">
<table width="300" border="0">
  <tr>
    <td width="121">First Name:</td>
    <td width="195">
      <input type="text" name="user_fname" id="user_fname" />
   	</td>
  </tr>
  <tr>
    <td>Last Name:</td>
    <td><input type="text" name="user_lname" id="user_lname" /></td>
  </tr>
  <tr>
    <td>Email:</td>
    <td><input type="text" name="user_email" id="user_email" /></td>
  </tr>
  <tr>
    <td>Confirm Email:</td>
    <td><input type="text" name="user_cemail" id="user_cemail" /></td>
  </tr>
  <tr>
    <td>Gender:</td>
    <td>
      <select name="user_gender" id="user_gender">
        <option value="male">Male</option>
        <option value="female">Female</option>
      </select>
 	</td>
  </tr>
  <tr>
    <td>Birth Year:</td>
    <td>'.$this->dobFunc().'</td>
  </tr>
  <tr>
    <td>Street Address:</td>
    <td><input type="text" name="user_street" id="user_street" /></td>
  </tr>
  <tr>
    <td>City:</td>
    <td><input type="text" name="user_city" id="user_city" /></td>
  </tr>
  <tr>
    <td>Country:</td>
    <td>'.$this->incCountries().'</td>
  </tr>
  <tr>
    <td>Post Code:</td>
    <td><input type="text" name="user_pcode" id="user_pcode" /></td>
  </tr>
</table>

</div>
</div>';
    }
}
?>
But this is what is happening?
Image

Re: Functions being show at the top of the page.

Posted: Thu Feb 03, 2011 2:09 pm
by anantha

Code: Select all

<td>'.$this->dobFunc().'</td>
change to

Code: Select all

<td>';echo $this->dobFunc(); echo '</td>

Re: Functions being show at the top of the page.

Posted: Thu Feb 03, 2011 2:58 pm
by John Cartwright
That won't work, because it's being output already.

What you want to do is change your dobFunc() to return the values, instead of echo'ing it.

Code: Select all

public function dobFunc(){
        $Tyear = date(Y);
        $year = $Tyear - 18;
        
        $html = '<select id="user_dob" name="user_dob">';

        for($i=0; $i<=80; $i++){
            $html .= '<option value="'.$year.'">'.$year.'</option>' . PHP_EOL;
            $year = $year - 1;
        }

        $html .= '</select>';
        
        return $html;
    }

Re: Functions being show at the top of the page.

Posted: Thu Feb 03, 2011 3:26 pm
by Domsore
John... you know so much. This worked great. Praise John :)

Cheers again.

Re: Functions being show at the top of the page.

Posted: Thu Feb 03, 2011 3:44 pm
by John Cartwright
Domsore wrote:Praise John
Some things you just can't hear enough of :D Joking aside, no praise necessary. Just use what you've learned today for good and not evil.

Re: Functions being show at the top of the page.

Posted: Thu Feb 03, 2011 5:19 pm
by anantha
if u remove the echo for the $this->dobFunc() it should work....

like this

Code: Select all

<td>';$this->dobFunc(); echo '</td>

it should work..i should have not put echo there....instead of changing all your echo to return...u can just do this...

Re: Functions being show at the top of the page.

Posted: Fri Feb 04, 2011 4:26 am
by Domsore
Thanks for you reply, however I have already changed it to return and it worked perfectly.

Cheers though,

Dom