Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pug (Jade) HTML form

Tags:

html

pug

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?

like image 625
Anton K Avatar asked Mar 29 '17 10:03

Anton K


2 Answers

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.

like image 78
Quentin Avatar answered Sep 20 '22 13:09

Quentin


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')
like image 42
Sergi Nadal Avatar answered Sep 20 '22 13:09

Sergi Nadal