I have a simple login form and it is centered in internet explorer but in Chrome and Firefox it is aligned to the left of the page. What do I need to do to have the form centered in the other 2 browsers.
<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="4"><div align="center"><strong>Client Login</strong></div></td>
</tr>
<tr>
<td></td>
<td></td>
<td><input name="myusername" type="text" id="myusername" placeholder="Company Name" size="24"></td>
<td> </td>
</tr>
<tr>
<td></td>
<td></td>
<td><input name="mypassword" type="password" id="mypassword" placeholder="password" size="25"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input name="Submit" type="submit" class="submit_button" value="Login"></td>
<td> </td>
</tr>
</table>
</td>
</form>
Try to change the form width to 100%. This the example
<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>" style="width:100%;">
You should avoid using HTML tables to define the layout of your page. Here's a good overview on why tables should not be used for layout.
You should rely on HTML tag for semantic and CSS to tell the browser how he should display the stuff in the page.
Now consider the following:
<style>
form {
width: 200px;
margin: 0 auto;
}
input {
display: block;
margin: 5px 0;
}
</style>
<form name="form1" method="POST" action="/">
<h1>Client Login</h1>
<input name="myusername" type="text" id="myusername" placeholder="Company Name" size="24">
<input name="mypassword" type="password" id="mypassword" placeholder="password" size="25">
<input name="Submit" type="submit" class="submit_button" value="Login">
</form>
The HTML is stripped down to the bare essential: your title then your form elements. The form here is the main container. With CSS we tell the form to have 200px width and we use the margin property to center it.
We also tell the input element to display like a block element to fill it'S container, this way they each occupy 1 line.
Learning CSS is useful to separate appearance from meaning, here's a great demonstration of the relation between content, container and design.
Would you mind to try this maybe :)
<style>
table {
text-align:center;
margin-left:auto;
margin-right:auto;
}
</style>
<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="4"><div align="center"><strong>Client Login</strong></div></td>
</tr>
<tr>
<td></td>
<td></td>
<td><input name="myusername" type="text" id="myusername" placeholder="Company Name" size="24"></td>
<td> </td>
</tr>
<tr>
<td></td>
<td></td>
<td><input name="mypassword" type="password" id="mypassword" placeholder="password" size="25"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input name="Submit" type="submit" class="submit_button" value="Login"></td>
<td> </td>
</tr>
</table>
</td>
</form>
Related
In HTML I am making a form where there are 2 tables side by side. In one table all the form <label>/Name/E Mail/Password</label> and in another table I am trying to put the form <inputs> text/email/password to make them look nicely visible.
But when I gave the label Message and <textarea name="Message" rows="1" cols="30"></text area> my whole form layout is getting disturbed due to which I am not able keep my initial labels and inputs aligned.
<form class="" action="index.html" method="post">
<table>
<tr>
<td>
<table>
<tr>
<td>
<label>Name</label>
</td>
</tr>
<tr>
<td>
<label>Email</label>
</td>
</tr>
<tr>
<td>
<label>Password</label>
</td>
</tr>
<tr>
<td>
<label>Message</label>
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<input type="text" name="" value="">
</td>
</tr>
<tr>
<td>
<input type="email" name="" value="">
</td>
</tr>
<tr>
<td>
<input type="password" name="" value="">
</td>
</tr>
<tr>
<td>
<textarea name="Message" rows="1" cols="30"></textarea>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
When the labels and inputs are aligned
When the labels and inputs are not aligned
There is no need for the extra table inside of the table, and you are including everything inside of 1 row, which is why its formatted like that.
You shouldn't be using tables for this, not when you have things like CSS Flexbox and CSS Grid. Here is a basic example of using flexbox with a form.
But if you must use a table, try a table format like this ...
<table>
<tr>
<td>label here</td>
<td>form field here</td>
</tr>
<tr>
<td>label here</td>
<td>form field here</td>
</tr>
...
</table>
Here is an example using your code.
<form class="" action="index.html" method="post">
<table>
<tr>
<td>
<label>Name</label>
</td>
<td>
<input type="text" name="" value="">
</td>
</tr>
<tr>
<td>
<label>Email</label>
</td>
<td>
<input type="email" name="" value="">
</td>
</tr>
<tr>
<td>
<label>Password</label>
</td>
<td>
<input type="password" name="" value="">
</td>
</tr>
<tr>
<td>
<label>Message</label>
</td>
<td>
<textarea name="Message" rows="1" cols="30"></textarea>
</td>
</tr>
</table>
</form>
I have following simple HTML form:
<html>
<head>
</head>
<body>
<table border="0" cellpadding="2" cellspacing="0" width="400">
<form name="logon" method="post" id="logon" action="take.php">
<tr>
<td tabindex="0">User ID </td>
<td>
<input name="login" maxlength="12" size="15" value="" title="User ID">
</td>
<td class="loginlabel"> </td>
</tr>
<tr>
<td tabindex="0">Password </td>
<td>
<input type="password" name="password" maxlength="12" size="15" value="">
</td>
<td class="lable"> </td>
</tr>
<tr>
<td colspan="3">
<p class="pushButton"><button type="submit" form="nameform" value="Submit">Submit</button></p>
</td>
</tr>
</form>
</table>
</body>
</html>
When I open this page in any browser and inspect element, I found weird structure of the HTML form. I found <form> tag immediately closed after start,
please find the screen shot of html form inspection,
What is the reason behind this?
In HTML, when you open a tag within another tag, the tag you open (in your case the <form> tag) gets clsoed when its parent gets closed.
Therefore (for example):
<p><form></p>
<p></form></p>
will result in the following:
<p><form></form></p>
<p></p>
This is because, according to the W3C (which sets international standards on HTML among other things), the only context a form element can be used in is where flow content can be expected. Flow content are most elements that are used in the body of documents and applications, for example:
The solution to this is to place the form tags above that of the table, encasing the table in the form as below:
<form>
<table>
</table>
</form>
To clarify:
You need to be sure that the table is inside the form tags. See a complete example as working below:
<html>
<head>
</head>
<body>
<form name="logon" method="post" id="logon" action="take.php">
<table border="0" cellpadding="2" cellspacing="0" width="400">
<tr>
<td tabindex="0">User ID </td>
<td>
<input name="login" maxlength="12" size="15" value="" title="User ID">
</td>
<td class="loginlabel"> </td>
</tr>
<tr>
<td tabindex="0">Password </td>
<td>
<input type="password" name="password" maxlength="12" size="15" value="">
</td>
<td class="lable"> </td>
</tr>
<tr>
<td colspan="3">
<p class="pushButton">
<button type="submit" form="nameform" value="Submit">Submit</button>
</p>
</td>
</tr>
</table>
</form>
</body>
</html>
Using the inspect function in Chrome proves that the output to the browser shows the table nested inside of the form tags:
Feel free to ask any further questions.
Move the table tags inside of the form also:
<form name="logon" method="post" id="logon" action="take.php">
<table border="0" cellpadding="2" cellspacing="0" width="400">
<tr>
<td tabindex="0">User ID </td>
<td>
<input name="login" maxlength="12" size="15" value="" title="User ID">
</td>
<td class="loginlabel"> </td>
</tr>
<tr>
<td tabindex="0">Password </td>
<td>
<input type="password" name="password" maxlength="12" size="15" value="">
</td>
<td class="lable"> </td>
</tr>
<tr>
<td colspan="3">
<p class="pushButton"><button type="submit" form="nameform" value="Submit">Submit</button></p>
</td>
</tr>
</table>
</form>
The reason for this could just be that the form is unsure why there are tr tags without a table tag within it. It seems a strange limitation however maybe somebody else can clarify further.
you have this:
<table border="0" cellpadding="2" cellspacing="0" width="400">
<form name="logon" method="post" id="logon" action="take.php">
You need to declare first the form and then the table
<form name="logon" method="post" id="logon" action="take.php">
<table border="0" cellpadding="2" cellspacing="0" width="400">
<tr>
<td tabindex="0">User ID </td>
<td>
<input name="login" maxlength="12" size="15" value="" title="User ID">
</td>
<td class="loginlabel"> </td>
</tr>
<tr>
<td tabindex="0">Password </td>
<td>
<input type="password" name="password" maxlength="12" size="15" value="">
</td>
<td class="lable"> </td>
</tr>
<tr>
<td colspan="3">
<p class="pushButton"><button type="submit" form="nameform" value="Submit">Submit</button></p>
</td>
</tr>
So I'm trying to build upon the following application, and previously I had this functional <form> tag below.
It's a bit of an eyesore but it's essentially just some inputs in a table for stylistic purposes, wrapped around by a form:
<form method='POST' action='http://localhost:8080/hw4/submission'
form id="form" name="form">
<table>
<tr>
<td>
<b>Claim *</b>
</td>
<td>
<input id="claim" name='claim' class="text" size="35" type="text" placeholder="What's your assertion?">
</td>
</tr>
<tr>
<td>
<b>Argument/Evidence *</b>
</td>
<td>
<textarea id="arg" name='arg' class="text" cols="37" rows="4" placeholder="Go ahead, prove yourself!" style="resize:none; font-family: 'Trebuchet MS', sans-serif; font-size: 13px;"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="font-size:12px; color:#FF0099;x"> ∗ - Required field
</td>
</tr>
</table>
<!-- Form submit -->
<p><input type='button' value='Submit' style='width:100px' onclick='return checkFields();'></p></form>
checkFields() is a Javascript function that just checks for empty input fields, and if they are not all empty, it calls document.getElementById("form").submit();
When inspecting the source code, my browsers (Chrome, Firefox) would say the <form> tag was open, but yet it would still do the POST call without any problems.
I then tried to add an additional input field like so:
<form method='POST' action="http://localhost:8080/hw5/submission"
id="form" name="form">
<table width="550px">
<tr>
<td>
<b>Name</b>
</td>
<td>
<input id="username" class="text" size="45" type="text" placeholder="This will display with your claim">
</td>
</tr>
<tr>
<td>
<b>Claim</b>
</td>
<td>
<input id="claim" class="text" size="45" type="text" placeholder="What's your assertion?">
</td>
</tr>
<tr>
<td>
<b>Argument/Evidence</b>
</td>
<td>
<textarea id="arg" class="text" cols="37" rows="2" placeholder="Go ahead, prove yourself!"></textarea>
</td>
</tr>
</table>
<!-- Form submit -->
<input id="submit" type="button" value="Submit" style="width:100px" onclick="return checkFields();">
</form>
Note all I really changed was I added <input id="username">. When inspecting the code in the browsers, it says the <form> is closed (though eclipse says it's not) and it won't submit.
I tried wrapping each <input> itself with <form id="form"></form>, which appeased eclipse's warnings, but in trying to output any of the request parameters, it'd return NULL.
I'm at my wits end trying to understand what's going on under the hood here.
Don't use the Snippet, use the Plunker
There were some critical typos that brought everything down:
Each <form> was broken into two lines, but it wouldn't matter if that was fixed...
...because each form had an extra word inside the tag: form
A color:#FF0099" was followed by a x; that looks like a piece of px.
Added a few things:
Each <form> has a functioning test server in method and target attribute pointing to...
...a new iframe. It's purpose is to display the data sent by the forms.
Changed all <input type='button'...> to <input type='submit'...>. Now with real submit buttons you don't need any extra JS/jQ to submit a form anymore.
PLUNKER
SNIPPET
<form method='POST' action='http://www.hashemian.com/tools/form-post-tester.php/form1' id="form1" name="form1" target='win1'>
<table>
<tr>
<td>
<b>Claim *</b>
</td>
<td>
<input id="claim1" name='claim1' class="text" size="35" type="text" placeholder="What's your assertion?">
</td>
</tr>
<tr>
<td>
<b>Argument/Evidence *</b>
</td>
<td>
<textarea id="arg1" name='arg1' class="text" cols="37" rows="4" placeholder="Go ahead, prove yourself!" style="resize:none; font-family: 'Trebuchet MS', sans-serif; font-size: 13px;"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="font-size:12px; color:#FF0099"> ∗ - Required field
</td>
</tr>
</table>
<!-- Form submit -->
<p><input type='submit' style='width:100px'></p></form>
<iframe src='about:_blank' id='win1' name='win1' width='200' height='50px'></iframe>
<!--==================================================-->
<form method='POST' action='http://www.hashemian.com/tools/form-post-tester.php/form2' id="form2" name="form2" target='win2'>
<table>
<tr>
<td>
<b>Claim *</b>
</td>
<td>
<input id="claim2" name='claim2' class="text" size="35" type="text" placeholder="What's your assertion?">
</td>
</tr>
<tr>
<td>
<b>Argument/Evidence *</b>
</td>
<td>
<textarea id="arg2" name='arg2' class="text" cols="37" rows="4" placeholder="Go ahead, prove yourself!" style="resize:none; font-family: 'Trebuchet MS', sans-serif; font-size: 13px;"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="font-size:12px; color:#FF0099"> ∗ - Required field
</td>
</tr>
</table>
<!-- Form submit -->
<p><input type='submit' style='width:100px'></p></form>
<iframe src='about:_blank' id='win2' name='win2' width='200' height='50px'></iframe>
<!--===================================================-->
<form method='POST' action="http://www.hashemian.com/tools/form-post-tester.php/form3" id="form3" name="form3" target='win3'>
<table width="550px">
<tr>
<td>
<b>Name</b>
</td>
<td>
<input id="username3" class="text" size="45" type="text" placeholder="This will display with your claim">
</td>
</tr>
<tr>
<td>
<b>Claim</b>
</td>
<td>
<input id="claim3" class="text" size="45" type="text" placeholder="What's your assertion?">
</td>
</tr>
<tr>
<td>
<b>Argument/Evidence</b>
</td>
<td>
<textarea id="arg3" class="text" cols="37" rows="2" placeholder="Go ahead, prove yourself!"></textarea>
</td>
</tr>
</table>
<!-- Form submit -->
<input id="submit3" type="submit" style="width:100px">
</form>
<iframe src='about:_blank' id='win3' name='win3' width='200' height='50px'></iframe>
I think My html code is messed up and I can't fix it.I he been workin on for 2 hours
this is the output
Please can you help me
<?php
if($_POST){
}
else{
echo '
<form action="" method="post">
<table cellspacing="5" cellpadding="5">
<tr>
<td>Ad</td>
<td><input type="text" name="ad"></td>
</tr>
<tr>
<td>Posta</td>
<td><input type="text" name="posta"></td>
</tr>
<tr>
<td>Mesaj</td>
<td><textarea rows="5" cols="30" name="mesaj"</textarea>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Gonder"></td>
</tr>
</table>
</form>
';
}
?>
<form action="" method="post">
<table cellspacing="5" cellpadding="5">
<tr>
<td>Ad</td>
<td>
<input type="text" name="ad">
</td>
</tr>
<tr>
<td>Posta</td>
<td>
<input type="text" name="posta">
</td>
</tr>
<tr>
<td>Mesaj</td>
<td>
<textarea rows="5" cols="30" name="mesaj"> </textarea>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Gonder">
</td>
</tr>
</table>
</form>
You forgot to close the textarea tag and the td its in, also please use some indentation. it hurts my eyes!
<textarea> Missing '>' For End Of Tag (At line 13, column 9)
it should be
<form action="" method="post">
<table cellspacing="5" cellpadding="5">
<tr>
<td>Ad</td>
<td><input type="text" name="ad"></td>
</tr>
<tr>
<td>Posta</td>
<td><input type="text" name="posta"></td>
</tr>
<tr>
<td>Mesaj</td>
<td><textarea rows="5" cols="30" name="mesaj"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Gonder"></td>
</tr>
</table>
</form>
I would like to show a form with submit button, to post the texts fields back to server with:
a text input called title, with border
text called chapter and section no border, and their should be assigned in JavaScript
I want chapter/section not modifiable and short. But Title is a normal input and should be very close to the word Title, like:
Chapter 3 Section 4
_____________
Title |_____________|
I wrote CSS like "input[type="notext"]{border: none} then either both text inputs have border, or none has border. I basically want the two inputs to have different style, or some other kind of field for chapter/section for me to set value is fine too. So how to achieve this? Don't need to be compatible for IE8 and before.
input[type="text"]{
border: none;
font-size: 16px;
}
<form action="#" method="post" id="form" >
<table>
<tr>
<td>Chapter<input type="text" value="3" name="cha_n" readonly/></td>
<td>Section <input type="text" value="4" name="sec" readonly/></td>
</tr>
<tr>
<td>Title </td>
<td><input type="text" style="inputtext" name="title" id="title"/></td>
</tr>
<tr>
<td span='2'><a id="submit" href="javascript: check()">Send</a></td>
</tr>
</table>
</form>
You can define a CSS class for your inputs and just use them.
For inputs with class example:
input.example {
border: none;
font-size: 16px;
}
Use it like this:
<input class="example" type="text" value="3" name="cha_n" readonly/>
Example: http://jsfiddle.net/x762v24a/
A less generic way to achieve this is to use CSS attribute selector:
input[name="cha_n"] {
border: none;
}
To remove the borders on the chapter and section inputs, use:
input[readonly] {
border:none;
}
<form action="#" method="post" id="form" >
<table>
<tr>
<td>Chapter<input type="text" value="3" name="cha_n" readonly/></td>
<td>Section <input type="text" value="4" name="sec" readonly/></td>
</tr>
<tr>
<td>Title </td>
<td><input type="text" style="inputtext" name="title" id="title"/></td>
</tr>
<tr>
<td span='2'><a id="submit" href="javascript: check()">Send</a></td>
</tr>
</table>
</form>
Try to give inputs having the same style an 'class' attribute,then :
.style1
{
border = 0px solid #FFFFFF;
}
.style2
{
margin = 0px;
padding = 0px;
border = 1px;
}
<form action="#" method="post" id="form" >
<table>
<tr>
<td>Chapter<input type="text" value="3" name="cha_n" class="style1" readonly/></td>
<td>Section <input type="text" value="4" name="sec" class="style1" readonly/></td>
</tr>
<tr>
<td>Title </td>
<td><input type="text" style="inputtext" class="style2" name="title"id="title"/></td>
</tr>
<tr>
<td span='2'><a id="submit" href="javascript: check()">Send</a></td>
</tr>
</table>
<form action="#" method="post" id="form" >
<table>
<tr>
<td>Chapter<input type="text" value="3" name="cha_n" /></td>
<td>Section <input type="text" value="4" name="sec" /></td>
</tr>
<tr>
<td>Title</td>
<td><input type="text" style="border:none;font-size:14px;" name="title"/></td>
</tr>
<tr>
<td span='2'><a id="submit" href="javascript: check()">Send</a></td>
</tr>
</table>
</form>