-4

I made a register login system in object-oriented PHP. I need the HTML code to be callable from a PHP method.

Here is the View.php class:

<?php
class View{

public function createLoginUI(){
    ?>
    <html>
    <title></title>
    <head></head>
    <body>
    <form>
        Email:<input type="text" name="mail">
        Pass:<input type="text" name="pass">
        <input type="submit" name="login" value="Login"><br>
        <a href="?regist" >Regist</a>

    </form>
    </body>
    </html>
    <?php
}

public function createRegistUI()
{
    ?>
    <html>
    <title></title>
    <head></head>
    <body>
    <form>
        Name:<input type="text" name="name">
        Email:<input type="text" name="email">
        Pass:<input type="text" name="pw">
        <input type="submit" name="send" value="Send">
    </form>
    </body>
    </html>
    <?php

 }

}

And the index.php:

<?php
require_once "model/Autoload.php";

$view = new View();
$view->createLoginUI();

In the createLoginUI has a link. The link function is load the registry UI. I made this:

public function newSite($view) {

    if(isset($_GET['regist'])) {

    $view->createRegist();

    }

}

I call this method in index.php. If I click the "regist" button, it displays both views. I'd like to see only "regist" view. I tried the header(), but I don't know how can I call a method in header and not sure that it will work.

8
  • 1
    then don't call createLoginUI() on the registration page. you're getting both because you're TELLING php to output both.
    – Marc B
    Oct 26, 2015 at 18:43
  • i'm not entirely clear what you're asking, but why aren't you creating a new view before calling createRegist() ? shouldn't $view = new View(); occur before that line? Oct 26, 2015 at 18:45
  • @johnny - i'm not seeing the similarity between the two questions. OP isn't asking how to return html from PHP. OP is getting more returned than desired, from my understanding. Oct 26, 2015 at 18:48
  • @devlincarnate Won't that question I mentioned show him how to do that?
    – johnny
    Oct 26, 2015 at 18:49

1 Answer 1

1

try this way

<?php
  class View{


   public function createLoginUI(){
    echo '<html>
          <title></title>
          <head></head>
          <body>
          <form>
              Email:<input type="text" name="mail">
              Pass:<input type="text" name="pass">
              <input type="submit" name="login" value="Login"><br>
              <a href="?regist" >Regist</a>

          </form>
          </body>
          </html>';
   }
   .....
   .....
}
2
  • I tried it , but always show both view. I tried lot of thing what you wrote here since yesterday , but none of them work fine. I begin give up that.
    – Bbeni
    Oct 27, 2015 at 12:01
  • @Bbeni remove all the HTML and make straight up echo 'test'; and see what happens. Do you get both? Where are you calling them from?
    – johnny
    Oct 27, 2015 at 14:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.