24

I have this piece of code:

<div>
   <form name='profileForm' id='profileForm' action='' method='get'>
      <input type='submit' name='ProfileBtn' id='ProfileBtn' class='buttonC' value='My Profile' />
   </form>
<br />
   <form name='logoutForm' id='logoutForm' action='' method='get'>
      <input type='submit' name='LogOutBtn' id='LogOutBtn' class='buttonC' value='Logout' />
   </form>
</div>

When I render the above the "profileForm" does not appear (although the profileBtn DOES appear). the seconed form has no problems, which is weird because they are both similar.

It's probably an easy question but I have no idea what's the problem.

simonc
  • 41,632
  • 12
  • 85
  • 103
Noam Gal
  • 1,114
  • 2
  • 11
  • 20
  • what do you mean "the profile form doesn't appear but the button does"? A form element is merely a container, like a div, and if it has no CSS attached to it, it won't show on the page. If you want to make it visible, attach a border or background with CSS to the form element – Matanya Dec 08 '12 at 11:29
  • You need to demonstrate this problem, because there's no obvious problem with your posted html. – David Thomas Dec 08 '12 at 11:30
  • well, it's weird [link](http://jsfiddle.net/33G5N/), here it works fine but when i run my website and check the developer console, profileBtn is not surrounded by any form @Matanya i meant in the developer console. – Noam Gal Dec 08 '12 at 11:52
  • @DavidThomas ..? anyone..? – Noam Gal Dec 08 '12 at 12:16
  • if it IS showing when you view source as received from the server, but not showing in the console, it might be due to a JS script removing it after page load – Matanya Dec 08 '12 at 12:28

6 Answers6

46

This just happened to me using Chrome -- it was because I had a form within a form. It looks like Chrome just stripped out the <form> open and close tag because my form was within another form. When I moved one form outside of the other, then both <form> tags were rendered in the html as intended.
Crackermann was getting at this in his answer too.

It's hard to give a direct solution without seeing your full html, but I'm guessing this is your problem - you need to make sure your form is not within another form. Really simple example to illustrate this:

Form within another form, notice if you run this code in Chrome and inspect <form id="form2"> is not rendered:

<html>
<head></head>
<body>
 <form id="form1">
  <div>form within a form</div>
  <form id="form2">
   <input type="text" placeholder="name" /><br/>
   <input type="text" placeholder="title" />
  </form>
 </form>
</body>
</html>

If you move form2 outside of form1, run the code in Chrome and inspect, then <form id="form2"> is rendered:

<html>
<head></head>
<body>
 <form id="form1">
  <div>form2 moved outside of form1</div>
 </form>
 
 <form id="form2">
  <input type="text" placeholder="name" /><br/>
  <input type="text" placeholder="title" />
 </form>
</body>
</html>
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Michael Stalcup
  • 566
  • 6
  • 6
10

well then somehow there was a weird problem with the forms, the button didn't show up because when i ran the website the the 'profileForm' just disappeared somehow (and didn't show up in the console). what i did was adding a third Form before 'profileForm' which somehow solved this.

Noam Gal
  • 1,114
  • 2
  • 11
  • 20
  • This happened to me too, for no adequately explained reason and this "fix" worked. I was heavily using pyramid and mako templates in addition to css/javascript. Ugh. Perhaps it's a bug in the browser? – NuclearPeon Sep 29 '15 at 01:48
  • THat is really weird. That was my solution as well. Worked like a charm... don't know why. – foxtangocharlie Feb 21 '17 at 21:17
9

Just put a empty form on top of your form. Then all forms will be appear with form id

<form></form>

<form name='profileForm' id='profileForm' action='' method='get'>
      <input type='submit' name='ProfileBtn' id='ProfileBtn' class='buttonC' value='My Profile' />
</form>

<form name='logoutForm' id='logoutForm' action='' method='get'>
      <input type='submit' name='LogOutBtn' id='LogOutBtn' class='buttonC' value='Logout' />
</form>
Rajiv Sharma
  • 6,746
  • 1
  • 52
  • 54
8

There is an unclosed HTML TAG like < form > in your code before these lines ,

Find and close that form

OR

just put </form> before your code.

captain_a
  • 3,328
  • 1
  • 14
  • 23
1

Check that you don't an unclosed form element before your next form open.

If you do, browsers will generate the source without displaying the subsequent form open and form close pair.

Crackermann
  • 65
  • 1
  • 5
0

Try viewing your Page Source

For Mac users Option + Command + U

For Windows users Ctrl + U

Then check for any unclosed <form> tag above your specified <form> tag and close it.

It works for me, hope it works for you too