-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.

user3071284
  • 6,955
  • 6
  • 43
  • 57
Bbeni
  • 75
  • 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 '15 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)](http://stackoverflow.com/questions/528445/is-there-any-way-to-return-html-in-a-php-function-without-building-the-return) – johnny Oct 26 '15 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? – devlin carnate Oct 26 '15 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. – devlin carnate Oct 26 '15 at 18:48
  • @devlincarnate Won't that question I mentioned show him how to do that? – johnny Oct 26 '15 at 18:49
  • @johnny - OP is already returning HTML from PHP. OP is getting results from two different functions that return HTML. i believe only one result (one set of HTML) is desired. – devlin carnate Oct 26 '15 at 18:56
  • Just make different pages. This approach will just get bloated and ridiculous over time. – developerwjk Oct 26 '15 at 19:00
  • I think you should use a MVC approach if you want to serve separate views by calling different methods. I think your company's requirement might prefer that. – Sajib Acharya Oct 26 '15 at 19:19

1 Answers1

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>';
   }
   .....
   .....
}
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • 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 '15 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 '15 at 14:28