HTML Form Action Attribute: Difference Between Values - html

I am learning about HTML forms and in particular the action attribute has me a bit confused. What is the difference between the following values and when is it best to use each case?
action=""
action="?"
action="?page"
action="?page=main"
action="."
action="../"
action="/"
action="#"

From W3 Form Documentation:
This [action] attribute specifies a form processing agent
That is, the form, when submitted, sends the values to wherever the action is set to. For the most part your noted actions all submit the form back to the same page the form is displayed on. You could also leave the action out all together or use <?php echo $_SERVER['PHP_SELF']; ?> (if you're on a php page) to obtain the same effect.
Now, "?page=main" will technically go to the same page as well, but with the page GET value set to "main" (might be used for processing the output somehow for example). Use it if you need the page value, otherwise do one of the blank ones.

Related

Simple cross domain form posting not working (whmcs)

I am trying to get a search box to post its content into a searchbox on another domain, using the html post method, however its not working after being redirected to the second site the search box remains empty on site 2.
Both servers belong to the same business and I have access to both, can someone tell me what I could do without using java to get the contents from the input box 1 on site 1 posted to the input box 2 on site 2
here is the line of code I am using on the first site.
form action="https://site2.com/cart.php?a=add&domain" method="post"
Thanks
You''ll need to catch and process both the GET arguments (in your action URL) and the POST stream (from the form elements) in the site2.com/cart.php file that you are using as the action.
Assuming the input box on site1 is named inputBox and is contained in the form with that action, when the form is submitted the site2.com/cart.php script can access the value at $_POST['inputBox'] - ie, wherever that goes on site2, you could do
<form name="someformonsite2" action="....">
<input type=text
<?php
if((!empty($_POST['inputBox'])&&(passes_your_validation($_POST['inputBox']))){
print("value=\"".$_POST['inputBox']."" );
}
?>
size=12 maxlength=11>
<!-- rest of form follows -->
Which would effectively send to the browser:
<input type=text value="SomeVal" size=12 maxlength=11>

Include Input In All Form Submissions

Similar to how an input outside of a form element can be including in submission using the form= attribute. Is it possible to include an input in every form submission without using javascript?
<input type="hidden" form="*" name="include-all" value="id1234"> //This is an example and is not working html
I am using a scope id server side to manage browser tabs and this id needs to be passed with each form submission. Its redundant having to include the hidden element in each and every form container.
I've considered including the id in the querystring but this destroys bookmarking and adds complexity to my request handler. Though it may be my best option...
Does the button you are using have a value? In my application, to get an id, I just set it as the value of the submit button (<button>) and call a $_POST request on the button's name attribute.

Why do we put "?" in action = "?"

When I was learning Php with Mysql, I got a problem :
<form action="?" method="POST">
.
.
.
</form>
Why do we put "?" in the action attribute?
PS: this form was for inserting text into a database.
Actually, I have an Index.php file which is the controller, and 2 files (form.html.php and joke.html.php as templates). In the tutorial, I first clicked on a link "add joke" to include the form.html.php file and in this form there is <form action="?"> </form> and a submit <input>. When I click on submit, the controller index tests and executes the inserted SQL query.
Thanks.
Personally don't ever do that.... Use action="action.php" or use action="" post to the current URL.
Not sure what you are trying to accomplish with ? in the action attribute.
"We" don't and "You" shouldn't do so either.
If you want to POST the data to the current URL, leave it empty, i.e. action="".
If you want to POST to another URL, put that URL in there, e.g. action="save.php".

xPage-Pager Control with html-FORM element does not work

When I add a normal <form> element in my xpage, the pager doesn't work any longer, means I cannot switch to other pages (clicking on "next" or something).
Here is the important part:
<xp:pager id="newsPager" for="newsList" pageCount="4" partialRefresh="true">
//pager stuff.....
</xp:pager>
<form action="#">
//form stuff... contents not important for my issue, I tested it
</form>
When I exclude the form entirely, it works
I use Domino Designer 8.5.3 on windows 7
And the "newsList" is an ID of a repeat-control
Instead of using a passthru form, use a form component:
<xp:form action="#">
// form contents
</xp:form>
This will prevent the rest of the content from being surrounded by a form tag, which also breaks events and data submission, so you'll need to surround the rest of your content in its own form:
<xp:form>
<xp:pager id="newsPager" for="newsList" pageCount="4" partialRefresh="true">
//pager stuff.....
</xp:pager>
<xp:repeat id="newsList">
//repeat contents
</xp:repeat>
</xp:form>
NOTE: do not nest forms inside each other; this confuses browsers, which is why your current design is not functional. Identify, instead, discrete portions of the page that can be safely treated as separate forms and wrap each portion in its own form component.
The XPage renderer automatically adds a form to the page unless you have disabled this in the properties of the Xpage.
This form is used to process all the partial refreshes and submitting of values to the backend. When you add your own form tag the partial refresh used by the pager ( or any xpage component ) no longer has the correct information needed to talk to the server.
if you really need to have your own form tag then I would suggest an iFrame that loads in an external page that contains your form.
i found this and it's work fine for me
http://xpageswiki.com/web/youatnotes/wiki-xpages.nsf/dx/work_with_HTML_forms#Embed+a+custom+HTML+form+in+a+XPage

HTML Form works with GET but not with POST

I'm running Firefox 2.0.0.14.
I have a form on a webpage which is working fine with the GET method.
I'm using a plugin to view my browser's HTTP request when submitting the form, and here it is :
GET /postComment.php?review=2&comment=Testing HTTP/1.1
...
However, if I make the simple change from method=GET to method=POST on the form:
GET /postComment.php HTTP/1.1
...
It isn't even attempting to POST.
Any possible reasons for this, under any circumstances?
EDIT: Here is the form:
<form method=POST action="postComment.php"><input type=hidden name=review value="2"><input type=submit value="Postit">
</form>
Is the action parameter of the form tag set? Could Javascript be intercepting the post? Some HTML from your form would be helpful, or an example link :)
I'm guessing your plugin is not capturing the POST variables. Since the output of your plugin is:
GET /postComment.php HTTP/1.1
How are you catpuring your POST varables? $_POST['key'] or $_REQUEST['key'] should contain your value if the form action and method are set properly.
POST will not be found in the query string.
EDIT:
if you are trying to capture the post value, you can check it with something like this:
if (isset($_REQUEST['submit'])) {
echo $_REQUEST['review'];
}
or
if (isset($_POST['submit'])) {
echo $_POST['review'];
}
Acorn
I would start by making sure your HTML is valid XHTML. Wrap attribute values in quotations and end the input elements with />. Use a valid DOCTYPE.
Also, try changing the value of the submit button to "submit" (as that is the default).
Try it out in different browsers, including the latest version of Firefox.
Firstly, your <form> tag needs to be adjusted:
<form method="post" ... >
Secondly, I have a function called debugArray that I use to spit out misbehaving arrays. It's very handy:
function debugArray($array){
echo("<pre>");
print_r($array);
echo("</pre>");
}
Then, call it in your code like this:
debugArray($_POST);
By looking at the entire contents of the $_POST array, you can see exactly what is being sent, what is not, and how it is being sent.
I'm willing to wager that one of the following is true:
You have a spelling mistake in a field name, remembering that names are case sensetive.
Your form field is outside your <form> tags.
You have a value that is not being escaped correctly, or otherwise being dropped from the $_POST for whatever reason.
Edit: And I would also be inclined to update your copy of Firefox.
I was having the same problem, till I remembered that my .htaccess file hides my PHP extension, and for reasons that someone else can explain (tech stuff) All I did was remove the .php extensión in the action property and it worked.
So, I went from:
action="folder/folder/file.php"
To:
action="folder/folder/file"
And the print_r($_POST) displayed the full array
I really Hope this helps someone else with the same problem.
And if anyone can technically explain why this is happening, it would be very educational 🙃