Form is not appearing but its content does - html

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.

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>

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.

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.

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>

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.

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

Related

Getting Submit Button to Pick Up Text in Textarea

I have a textarea that shows a random joke. I want the joke to post to Twitter using this link with the submit button: https://twitter.com/intent/tweet?text=
but I cannot for the life of me figure out how to get the text that's been generated in the textarea to be picked up in the link. I know there's an easy way to make this happen, but nothing I've tried has worked. Any help would be greatly appreciated!!! Here's the code I've got:
<form name="quoteForm">
<textarea wrap="virtual" name="quoteHere" rows="6" cols="40">Your joke is loading... unless your JavaScript is disabled
</textarea><br> <input type=button value="Previous" onClick="prevQuote();">
<input type=button value="Next" onClick="nextQuote();">
<input type=button value="Random" onclick="randQuote();"><br>
<p>
<input type="submit" value="Tweet This Joke"></p>
</form>
If you want to put the data in the query string then you need to make a GET request (which you are already doing), not a POST request (which you say you want to do).
If you want to send the data to https://twitter.com/intent/tweet then you need to put that URL in the action attribute of the <form> element. Since you have no action it will submit to the URL of your current page instead.
If you want the data to be associated with the query string parameter text then you need to name the textarea text and not, as you have, quoteHere.
The name attribute of textarea was changed from quoteHere to text.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form name="quoteForm" action="https://twitter.com/intent/tweet" onsubmit="submit();">
<textarea wrap="virtual" name="text" rows="6" cols="40">Your joke is loading... unless your JavaScript is disabled
</textarea><br> <input type=button value="Previous" onClick="prevQuote();">
<input type=button value="Next" onClick="nextQuote();">
<input type=button value="Random" onclick="randQuote();"><br>
<p><input type="submit" value="Tweet This Joke"></p>
</form>
</body>
</html>

HTML tag form without "action" attribute

I'm using this HTML code in an HTML page:
<form method="post">
<div class="form-group">
<input type="text" class="form-control" name="username">
</div>
<div class="form-group">
<input type="password" class="form-control" name="password">
</div>
<input type="hidden" name="ref" value="post-ad.php"/>
<button type="submit" name="submit" id="submit" class="btn">S'identifier</button>
</form>
On clicking submit button which action will this form execute? I noticed that it execute the value of input named "ref" in this example "post-ad.php" or "index.php" or "dashboard.php". Is it normal?! As I know the action attribute is mandatory?
without action attribute it will POST/GET to the same page
see here
If I understood right you're asking about action attribute that goes inside <form>.
If you put nothing there, it'll send the POST to the same page it is right now. If that form is in "index.php" it'll send all <form> data to "index.php"
You call form without action with this code:
<form action="javascript:void(0);"></form>

How can I make an html button that passes a parameter?

I want a html button with parameter functionality.
new/?sorting=desc is the url that it should link to. But when I try, the parameter is not passed. How should it be done? I tried both the methods below but none worked.
<FORM METHOD="GET" ACTION="./?sorting=desc">
<INPUT TYPE="submit" VALUE="Äldst först">
</FORM>
I want buttons that behave like these links:
Äldst först
Nyast först
If you want something to act as a link, then you should use a link.
That said:
When you submit a GET form, the query string is removed from the action and a new one is generated from the data in the form.
You need to store the data in hidden inputs.
<form action="/social/tracking/new/">
<input type="hidden"
name="sorting"
value="desc">
<input type="submit"
value="Nyast först">
</form>
<form action="/social/tracking/new/">
<input type="hidden"
name="sorting"
value="asc">
<input type="submit"
value="Sort the other way">
</form>
If you are using jQuery, you can use the code below.
This will fill a hidden input with the correct value when you click on one of the submit buttons.
<form method="get" action="./">
<input type="hidden" name="sorting" id="sorting" value="" />
<input type="submit" value="Äldst först" id="sort_desc" />
<input type="submit" value="Nyast först" id="sort_asc" />
</form>
<script>
$('#sort_desc').click(function(){
$('#sorting').val('desc');
});
$('#sort_asc').click(function(){
$('#sorting').val('asc');
});
</script>
I think its not possible. A form is used to send data (mostly) via POST or GET. Your goal is to open a specific URL. I would create a standard and would style it like a button. Whats the reason you want to use a button?

IE9 is auto-submiting form when <a> links clicked

While using IE9, every link (when clicked) the search form is being submitted. Every link seems as if it is redirecting to the action value of the search form.
There is no java script attached to the form element.
<form action="/my-search-url" method="post">
<input type="submit" value="search" />
<input type="text" value="" />
</form>
The issue was with the order of the form elements. Apparently the original developer decided to place the submit button before any input elements. By putting the submit input last (or removing it) fixed this issue.
<form action="/my-search-url" method="post">
<input type="text" value="" />
<input type="submit" value="search" />
</form>

how use button in internet explorer?

on my source i use
<a href='pag.php'><input type='button' value='Next'/></a>
in firefox and crome when i click on the button i'm redirected to pag.php
but in ie it don't work. how can i do?
The simple way is:
<input type='button' value='Next' onclick="location.href='pag.php'"/>
Form buttons are meant to be used for submitting a form to the page specified in the action attribute, not to be wrapped in <a> tags, which is bad syntax. If this is for a multi-part form, simply add the action attribute to the <form> tag like
<form method="POST" action="pag.php">
<!-- your form elements -->
<input type="submit" value="Next">
</form>
And that will submit the form to pag.php. Otherwise, just use a link, or, if you insist on having it look like a button, use an image link like:
<img src="image_that_looks_like_a_button.png">
Hope this helps.
Instead of what you are doing right now, go for:
<form action="pag.php" method="post" enctype="multipart/form-data">
<INPUT TYPE="submit" name="Submit" value="Next">
</form>
But if you want image instead in place of button, go for:
<INPUT TYPE="image" SRC="image location" ALT="Next">
Hope it solves your problem! :)