I'm trying to create the following simple form with Pug:
<body>
<form action="/add_movie" method="POST">
<p>
title: <input type="text" name="title" value=""/>
year: <input type="text" name="year" value=""/>
imdb: <input type="text" name="imdb" value=""/>
</p>
<input type="submit" value="Submit"/>
</form>
</body>
But I can't make the form work with only one p
tag. Here is what I came up with instead:
body
h1= "Add a movie!"
form(action="/new_movie" method="POST")
p Title:
input(type="text" name="title" placeholder="")
p Year:
input(type="text" name="year" placeholder="")
p imdb:
input(type="text" name="imdb" placeholder="")
input(type="submit")
Is there a way, to re-create the original HTML form in Pug within one p
tag?
Use piped text to mark content as text within an existing block.
body
form(action='/add_movie', method='POST')
p
| title:
input(type='text', name='title', value='')
| year:
input(type='text', name='year', value='')
| imdb:
input(type='text', name='imdb', value='')
input(type='submit', value='Submit')
… but you should only use paragraphs when you actually have a paragraph and you should learn to love labels.
I use this website https://html2jade.org/ to pass from HTML to Pug, it is very usefull.
The solution provided for your HTML is this (same as the answer from @Quentin)
html
head
body
form(action='/add_movie', method='POST')
p
| title:
input(name='title', value='', type='text')
| year:
input(name='year', value='', type='text')
| imdb:
input(name='imdb', value='', type='text')
input(value='Submit', type='submit')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With