0

My code displays this:

image

but I am not sure if I implemented the div and input form mixing properly.

Could you please comment if I am doing this in the correct way?

CSS:

.newstuff
{
    width: 80%;
    height: 100px;  
}

.newstuff.left 
{
    float: left;
    padding-left: 5px;
    text-align: right;
    width: 15%;
    vertical-align: middle;   
    background: red;
}

.newstuff.center 
{
    float: left;
    padding-left: 5px;
    text-align: left;
    width: 35%;
    vertical-align: middle;   
    background: green;
}

.newstuff.right 
{
    float: left;
    padding-left: 5px;
    text-align: left;
    width: 35%;
    vertical-align: middle;
    background: yellow;
}

.buttontest
{
    float: left;    
    width: 35%;
}

PHP:

<?php

echo "<head>";
echo '    <link rel="stylesheet" href="test.css">';
echo "</head>";
echo '<body>';
echo '<div class="newstuff">';
echo '  <form action="'.htmlspecialchars($_SERVER["PHP_SELF"]).'" method="post" name="auth_form">';
echo '<div class="newstuff left">';
echo '    <input type="text" name="data1" placeholder="This is left">';
echo '</div>';
echo '<div class="newstuff center">';
echo '<textarea name="centertext" rows="5" cols="50" maxlength="255" placeholder="This is center"></textarea>';
echo '</div>';
echo '<div class="newstuff right">';
echo '    <input type="text" name="data3" placeholder="This is right">';
echo '</div>';
echo '</div>';
echo '<div class="buttontest">';
echo '    <input type="submit" name="test" value="Testing">';
echo "  </form>";
echo '</div>';
echo "</body>";
?>
Adam Michalik
  • 9,678
  • 13
  • 71
  • 102
Tass Mark
  • 337
  • 1
  • 2
  • 14
  • 2
    Don't use echos like this. Try separating php from html/views. Check out Twig extension or any other similar templating solution for php, you will love it. – Muhammed Mar 04 '16 at 13:03
  • 2
    This is just perfect, that is what php was designed for ! – Mathijs Segers Mar 04 '16 at 13:10
  • Haha, @MathijsSegers, +1, you made my day! – Farside Mar 04 '16 at 13:12
  • 2
    While this question is highly opinionated there are several things that can be improved. Questions like this are what [codereview.se] was made for. – Gerald Schneider Mar 04 '16 at 13:15
  • 1
    Tass, the simplest thing you can do - to get rid of `echo`es, and to put everything you had outside of PHP tag, so interpreter simply will output everything to stdout. – Farside Mar 04 '16 at 13:19
  • I know about the echos, but what about the way I use div and input form together ? How is it done correctly if I am allowed to use only PHP built in functions ? – Tass Mark Mar 04 '16 at 13:27

1 Answers1

3

It's definitely not the proper way of mixing.

Try using template engines for PHP, here are the possible options for you to start:

  1. Twig
  2. Smarty
  3. Others

As the compromise, which I'd not recommend to use in long run, is to use Alternative syntax for control structures in PHP and short tags, which I found useful exactly for the trivial templates, when there's need to involve template engines.

Community
  • 1
  • 1
Farside
  • 9,923
  • 4
  • 47
  • 60
  • Farside: thank you. Unfortunately for this project I can only php built in functions, no external modul can be used. – Tass Mark Mar 04 '16 at 13:24
  • I'd propose to change the project or the workplace :) I can't imagine any serious reasons why you can't use other classes within PHP from libraries. It's waste to make output via echo-es like that. – Farside Mar 04 '16 at 13:26
  • @TassMark, find out my updated answer, regarding short tags, but I'd not recommend, as it's just the compromise for your case. – Farside Mar 04 '16 at 13:34