html text fields

Access Denied

It was like that when I got here...
Joined
Jun 14, 2006
Messages
2,552
So I'm learning html and php from the very basics and I have a question for the brain trust. I've made a very simple html form with four text boxes and a submit button. The submit button opens a new tab and links to a results page where the answers you give will be printed out with php $_POST functions.
At the moment the name of each box is to the left of it.

I.E
Name: *Box *
Age: *box*

How do I make is so that the name of the box is IN the box and when you click into the box it blanks and you put your name in there; while also making it so that clicking the submit button doesn't just print the names of the boxes in the new tab?

Ta.
 

Overdriven

Dumpster Fire of The South
Joined
Jan 23, 2004
Messages
12,757
I'm lazy by default so I'd not look at handling this in PHP directly. Look at bootstrap (Other frameworks available) and look at input groups and text placeholders.

The placeholder attribute will accomplish what you want. It puts fake text there which doesn't move across pages.

Regarding null/blank checks, that will need to be a set of checks using JavaScript of some sort.

 

Bob007

Prince Among Men
Joined
Dec 22, 2003
Messages
585
HTML:
<form action="/action_page.php">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname"><br><br>
  <input type="submit" value="Submit">
</form>

<form action="/action_page.php">
   <input type="text" id="fname" name="fname" placeholder="First Name"><br><br>
  <input type="text" id="lname" name="lname" placeholder="Last Name"><br><br>
  <input type="submit" value="Submit">
</form>

That what you are looking for?

Box.png
 

Access Denied

It was like that when I got here...
Joined
Jun 14, 2006
Messages
2,552
HTML:
<form action="/action_page.php">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname"><br><br>
  <input type="submit" value="Submit">
</form>

<form action="/action_page.php">
   <input type="text" id="fname" name="fname" placeholder="First Name"><br><br>
  <input type="text" id="lname" name="lname" placeholder="Last Name"><br><br>
  <input type="submit" value="Submit">
</form>

That what you are looking for?

View attachment 45194

Yep. I've since solved it though. placeholder! Thank you though!
 

Bob007

Prince Among Men
Joined
Dec 22, 2003
Messages
585
No worries.

Can also use value="Something" to set a default value.
 

Ormorof

FH is my second home
Joined
Dec 22, 2003
Messages
9,887
Why not? I'll probably learn Java as well at some point.

Personally I feel PHP translates least to other common web languages. If goal is to build full stack sites then something like JS plus node.js will take you quite far.
 

Overdriven

Dumpster Fire of The South
Joined
Jan 23, 2004
Messages
12,757
Personally I feel PHP translates least to other common web languages. If goal is to build full stack sites then something like JS plus node.js will take you quite far.

RE: PHP - You'd be surprised. The amount of money you can make as a WordPress Developer (Actual developer) is silly money. Most people start with PHP and then move on anyway.
RE: JS - Below

Why not? I'll probably learn Java as well at some point.

If you're wanting to go into the web world (Actual jobs) we mostly look for web devs who know various JS frameworks; React/Angular/Vue (etc) and how they work with Node.JS/NPM. That with CSS/HTML/Classic JS/Various other JS frameworks helps. If you can understand how web services (SoA/Micro architectures) work then you're in a better place too especially if you can work with them/create them in Java.

My team are all C#/JS devs because of the tie-in with Microsoft. Java devs get paid more.. But if I had to start again? Probably Java.
 

Ormorof

FH is my second home
Joined
Dec 22, 2003
Messages
9,887
Java is a gateway drug to other JVM languages, work mostly in Kotlin these days (even for backend), but theres also groovy, clojure, haskell, scala...

I have a friend who is a PHP consultant but he complains his biggest gigs are usually cleaning up after cowboys have made a mess :)
 

Users who are viewing this thread

Top Bottom