displaying html code using the echo command?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doug (dtism)

    displaying html code using the echo command?

    Hello **newbie alert** <-- that's me btw, but you might have guessed
    that by my topic title.

    I have an html page that submits a name and email address by a form to
    a page called preview.php

    I'd like to do some basic validation on the credentials subbitted via
    the form, and if they pass then send the credentials via email and
    display the rest of the page (which will have links to download some
    promotional tunes from my friends record label)

    If the validation fails I'd like to display an alternative version of
    the page telling the user to go back and fill in the form properly.

    Can I do this by simply enclosing some html code in an echo statement?

    for example

    echo "<div id="success">Th anks, here are the links you are looking
    for....</div>";

    I'm guessing I might have to escape the extra quotation marks, because
    it wouldn't parse the line when I just tried it.

    Anyway.. Am I barking up the wrong tree completely?

    Thanks in advance

    Doug.

  • Darko

    #2
    Re: displaying html code using the echo command?

    On Apr 3, 1:22 pm, "Doug (dtism)" <d...@dtism.co. ukwrote:
    Hello **newbie alert** <-- that's me btw, but you might have guessed
    that by my topic title.
    >
    I have an html page that submits a name and email address by a form to
    a page called preview.php
    >
    I'd like to do some basic validation on the credentials subbitted via
    the form, and if they pass then send the credentials via email and
    display the rest of the page (which will have links to download some
    promotional tunes from my friends record label)
    >
    If the validation fails I'd like to display an alternative version of
    the page telling the user to go back and fill in the form properly.
    >
    Can I do this by simply enclosing some html code in an echo statement?
    >
    for example
    >
    echo "<div id="success">Th anks, here are the links you are looking
    for....</div>";
    >
    I'm guessing I might have to escape the extra quotation marks, because
    it wouldn't parse the line when I just tried it.
    >
    Anyway.. Am I barking up the wrong tree completely?
    >
    Thanks in advance
    >
    Doug.
    Not really completely, but avoid echoing as much as possible. You
    might try doing it this way:
    <?php
    if ( ... ) {
    ?>
    <div id="success">
    Thanks, here are the links you are looking for...
    </div>
    <?php
    }
    ?>

    Better yet, you could use smarty or some other templating system, so
    you don't at all mix your php and html, but maybe you better practice
    like this for now, until you learn more.

    Cheers,
    Darko

    Comment

    • Erwin Moller

      #3
      Re: displaying html code using the echo command?

      Doug (dtism) wrote:
      Hello **newbie alert** <-- that's me btw, but you might have guessed
      that by my topic title.
      >
      I have an html page that submits a name and email address by a form to
      a page called preview.php
      >
      I'd like to do some basic validation on the credentials subbitted via
      the form, and if they pass then send the credentials via email and
      display the rest of the page (which will have links to download some
      promotional tunes from my friends record label)
      >
      If the validation fails I'd like to display an alternative version of
      the page telling the user to go back and fill in the form properly.
      >
      Can I do this by simply enclosing some html code in an echo statement?
      Yes, can be done, but doesn't it make more sense to send the visitor back to
      the original form?
      $succes = ...your test goes here...
      if (!$succes) {
      // send back to page with loginform
      header("Locatio n: loginform.php?r esult=".urlenco de('bad login.'));
      exit;
      }

      // just continue here with page with samples


      You can easily get the 'result' in your loginpage to display like this:
      <?php
      if (isset($_GET["result"])){
      echo $_GET["result"];
      }
      ?>


      That way your visitor understands what is going on.
      >
      for example
      >
      echo "<div id="success">Th anks, here are the links you are looking
      for....</div>";
      >
      I'm guessing I might have to escape the extra quotation marks, because
      it wouldn't parse the line when I just tried it.
      excactly.
      Also, consider less usage of echo. It makes your life unneeded hard since
      PHP can easily jump in and out of the output like this:
      <?php
      if ($sometest){
      ?>

      massive amount of plain HTML

      <?php
      } else {
      ?>

      massive amount of plain HTML


      <?php
      }
      ?>


      It saves you a lot of extra work to simple 'jump back to html'.
      >
      Anyway.. Am I barking up the wrong tree completely?
      No, good tree. :-)
      >
      Thanks in advance
      >
      Doug.
      Regards,
      Erwin Moller

      Comment

      • shakes082@gmail.com

        #4
        Re: displaying html code using the echo command?

        echo "<div id='success'>Th anks, here are the links you are looking
        for....</div>";

        Comment

        Working...