<form name="bizLoginForm" method="post" action="?
In order to stay on the same page on submit you can leave action empty ( action="" ) into the form tag, or leave it out altogether. For the message, create a variable ( $message = "Success! You entered: ". $input;" ) and then echo the variable at the place in the page where you want the message to appear with <?
If you want to add content to a page you need to work with the DOM. Google "create div javascript" or "create span javascript" for examples, you basically need to create an element that has your text in it and add that element to the part of the page you want the text to display.
You could include a hidden iframe on your page and set the target attribute of your form to point to that iframe.
In 2013, with all the HTML5 stuff, you can just omit the 'action' attribute to self-submit a form
<form>
Actually, the Form Submission subsection of the current HTML5 draft does not allow action="" (empty attribute). It is against the specification.
From this other Stack Overflow answer.
Use ?
:
<form action="?" method="post">
It will send the user back to the same page.
You can leave action attribute blank. The form will automatically submit itself in the same page.
<form action="">
According to the w3c specification, action attribute must be non-empty valid url in general. There is also an explanation for some situations in which the action attribute may be left empty.
The action of an element is the value of the element’s formaction attribute, if the element is a Submit Button and has such an attribute, or the value of its form owner’s action attribute, if it has one, or else the empty string.
So they both still valid and works:
<form action="">
<form action="FULL_URL_STRING_OF_CURRENT_PAGE">
If you are sure your audience is using html5 browsers, you can even omit the action attribute:
<form>
If you are submitting a form using php be sure to use:
action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"
for security.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With