-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. Commented Oct 26, 2015 at 18:43
  • Possible duplicate of Is there any way to return HTML in a PHP function? (without building the return value as a string) Commented Oct 26, 2015 at 18:44
  • 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? Commented 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. Commented Oct 26, 2015 at 18:48
  • @devlincarnate Won't that question I mentioned show him how to do that? Commented 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>';
   }
   .....
   .....
}
Sign up to request clarification or add additional context in comments.

2 Comments

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 remove all the HTML and make straight up echo 'test'; and see what happens. Do you get both? Where are you calling them from?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.