Jump to content

Div - Forms - Parsing - Help?


joecool308

Recommended Posts

What I'm trying to do is send a form via $_POST within div tags. I needed to physically space my <input type> tags in a certain way, so I used <div> tags to space them how I liked. When I send the form I get a parsing error. I know it's because I'm making the form incorrectly - I referenced the same form name twice in two actual separate forms within <div> tags. Confused? Here's the code without all the styling I used - just the basics. Where did I go wrong?:<html><head></head><body><div style="#######"><form action="first.php" method="post"> <input type="text" size="20" name="username"> </form></div> //Note that I end the form here </form><div style="########"><form action="first.php" method="post"> //And then start the form <form> again here <input type="text" size="20" name="password"> </form></div></body></html>(and then page it gets parsed to - again just the basics here:)<?php$username = $_POST['username'];$password = $_POST['password']; echo $password . "<br />";echo $username . "<br />";?>

Link to comment
Share on other sites

you just need one set of form tags around the whole form, you also need an <input type="submit" /> in your form

Link to comment
Share on other sites

Using a div to "space" things is bad style. Use CSS to give your elements margins. If you want elements on different "lines", they can go INSIDE different divs. And all of that can still go inside one set of form tags.But the parse error you mention has nothing to with your HTML or the fact that you have two separate forms. That will generate runtime errors, but that's not what's happening. A parsing error means your PHP is written incorrectly. It could be as simple as a missing semicolon or quotation mark. It should be in or near the line number that gets reported with the error (but not always). If you can't find it, you might want to post ALL the PHP code so someone can look at it. What you showed us so far looks okay, so the problem is somewhere else.

Link to comment
Share on other sites

Cudos to you! Yes you are right it was not a parse error it's an -index reference- error. I understand the CSS part. Normally I wouldn't style in the <div> tag like that. Still working on the fix though!So somebody here said I don't need to close the form? I tried in once already without the </form> break twice. I will try again and let you know what happens. I'm pretty sure it messes up my <div> page alignment though. Will try again. I like cheese!

Link to comment
Share on other sites

Ok so riddle me this. Why doesn't this work? Try it see what it looks like in your browser or html editor:<div> <form action="second.php" method="post"> <p>Input One:<input type="text" name="one" size="20"></p></div> <div> Input Two:<input type="text" name="two" size="20"> <input type="submit" value="send"> </form></div>If you can answer this it will most likely answer my question in a round about way.

Link to comment
Share on other sites

If this form were a piece of paper, then what you've done is tear it in half and put each half in a different room.Put the form tags before the first div tag and after the last div tag. That way, both divs are enclosed within the form. The form itself should probably be enclosed by a larger div, if it isn't already. Something like this:

<div>	<form>		<div>			 stuff . . .		 </div>		  <div>			 stuff . . .		 </div>	  </form> </div>

Link to comment
Share on other sites

Ok so how do I position a form on my page in a certain area, like for instance:Make a form and position it 250px from the left and 100px from the top. I put it in a <div> to place the form over a background image in a specific place. What now batman? The <form> tags are on the outside of the <div> tags and so inherently it wants to position itself under the picture, not layer on top of it. I know, I'm insane, but at least I have 10 fingers and 9 toes.For instance this right here:<html><head></head><body><div><img src="green.jpg"></div><form action="second.php" method="post"><div> <p>Input One:<input type="text" name="one" size="20"></p></div> <div> Input Two:<input type="text" name="two" size="20"> <input type="submit" value="send"> </div></form></body></html>

Link to comment
Share on other sites

I'm not clear on the relationship of the picture to the form. Is to be background only to the form? Are other elements besides the form supposed to be "layered" in front of the picture? Are there any other page elements above the form, like text, or a heading? The following CSS will position the form correctly, but only if it is the first element in the page. If there's more going on (like a picture) you have to let me know, and pretty specifically. The best thing would be if you could post a sketch (even hand-drawn and scanned) so I know what you're up to.

.my_form {	margin-top: 100px;	margin-left: 250px;}

Link to comment
Share on other sites

Thank You -Deirde's Dad - for correcting me with the <form> tag before the <div> tags. Right, it's like I was separating it into two pieces of paper by using the <form> </form> tags twice for the same page. When working with an image, this is what seemed to work best. My biggest problems were in fact styling within the <div> tag itself. When I styled in CSS it worked much better. Way less hassle. It works! Thanks<html><head><style>div.joe{position:absolute;left:248px; top:138px}div.joejoe{position:absolute; left:248px; top:170px}</style></head><form action="first.php" method="post"><div class="joe"><input type="text" size="20" name="username"></div><div class="joejoe"><input type="password" size="20" name="password"><input name="one" type="submit" id="one" value="Log In"></div></form><img src="green.jpg" width="1121" height="365"></body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...