I've seen <form> opening tags that look like this:
<form action="<?= $_SERVER['REQUEST_URI'] ?>">
Does the action attribute here make any sense?
Wouldn't the form behave the same way without it?
You should always include the action attribute in your form tag if you want a good valid markup (which you should). It is a required attribute (though most browsers will work around it if you don't and assume action="").
Using:
<form action="" method="post">
...will work and just use the current page as the action page.
http://www.w3schools.com/tags/tag_form.asp
Hope this helps.
If you set it to blank you get the same effect (which is what I prefer)
<form action="" method="post"> ....
Yes, you have to include action attribute within <form> tag. See some documentation.
However, you do not need to pass current URI, you can add empty action attribute like that:
<form action="">
...
</form>
and then the form will be sent to the current location (current URI).
Related
I am wondering if there is a way to declare a Global HTML- tag, that gets submittet with each form that gets called.
I mean something in the way like this:
<input type="hidden" name="x" value="200">
<form action="test.php" method="POST" enctype="multipart/form-data">
#Some Form-Stuff
</form>
<form action="test.php" method="POST" enctype="multipart/form-data">
#Some more Form-Stuff
</form>
And in both of these Forms, when a Submit is being made, there is supposed to be the Global hidden Input-Tag that gets delivered with the rest.
I already tried it and it didnt work, but I wonder if there is just something that is missing or if there is a similar or better way to accomplish this.
Would appreciate your help.
EDIT:
What I want in my current Project is to let the User <SELECT> an option that represents like an Folder in which there will be displayed data that is inside that folder.
I dont want the User to have to Select the Folder again after each click and the folder has to be submitted every time to the php-script so that it can handle data accordingly to the folder selected.
My Question in this case however still remains on wether you can or cannot make a <input> tag global or not, if it´s permanent or not doesnt matter.
Either include the following in your form
<input type='hidden'>
It is great for passing values without much code.
Or set it as a cookie/session variable as required.
I am working with PHP forms.
The opening form tag looks like this:
<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="GET">
This generated the following HTML:
<form name="adv_search_form" action="index.php?&rel=common_listing&module=company&sort_option=&search_option=&show_max_row=15" method="GET">
When I submit this form, I land on a URL:
http://localhost/projectcode12may2014/ampanel/index.php?field%5B%5D=broker_name&adv_operation%5B%5D=LIKE&value%5B%5D=&query_type%5B%5D=AND&submit=Submit
But what I want is that
?field%5B%5D=broker_name&adv_operation%5B%5D=LIKE&value%5B%5D=&query_type%5B%5D=AND&submit=Submit
should be appended to the action URL on the landing page. Can anyone suggest any good method for doing this?
Thanks in advance.
If you are using method="get" the parameters in action are overwritten. Only what is in the from will be transmitted.
You need to add hidden fields for all these values. For example:
<input type="hidden" name="module" value="company" />
That is your from data.
You have method="get" in your form tag. This means that the form data is concatinated to the URL. Use method="post" to have send form data as a POST request and keep your URI clean.
So change this line
<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="GET">
to this
<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="post">
Then you can access your form data in PHP with the global $_POST var which holds an array with the submitted data.
This is a normal behavior. Using GET method discard all parameters specified directly in action attribute.
Use POST method instead or move parameters from action attribute of the form to input fields with type="hidden".
Let's say I have a form on my website homepage: www.mysite.com
Now, the form tag looks like this:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
...
</form>
When that form submits, it does everything it's suppose to. But it also reloads the page with the full filename and extension. So the user will now find the URL in the address bar is: www.mysite/index.php
Is there a way to make the form fire to the same page without adding this extension?
There may be situations where the form is as an include in a footer, so I cann't be specific about the page the form needs to fire to, hense the PHP_SELF code.
That's because $_SERVER['PHP_SELF'] refers to the actual filename of the current script.
Try this:
<form action="" method="post">
An empty action will post back to the current URL.
Try setting the action to #:
<form action="#" method="post">
...
</form>
The # refers to the current page.
Try changing action to #, this post to the current page.
Edit: Mike beat me to it.
Edit 2: It looks like you can leave out the action all together and it will default to the same page.
Edit 3: Mike beat me to that one too.
So I have a profile page: profile.php?pin=xx, where I use the GET method for determining which profile to display. I am going to test if $_SESSION['pin'] == $_GET['pin'] and if so, give the option to edit profile.
I don't want to write a-whole-nother script and direct the user to another page. So for usability sake, and keeping the server neat so I'm not always guessing which script does what, I want to mix POST and GET. I've done some research and it seems legal, but how?
<form method="post" action="profile.php?pin=xx">
<form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
That's all I can think of without really getting the code messy.
If you keep the action attribute empty it will be the same URI including the GET parameters (query-info part of the URI):
<form method="post" action="">
Maybe this is what you're looking for? See HTML <form> tag for a reference about tag and attribute.
If you want to understand how that works: This is a so called Relative URI. It resolves to the Base URI of the document. As the Relative URI is empty, the Base URI is being taken over completely.
I would like to use the data entered in the html form and insert into MYSQL. I have a separate php (cus.php). but nothing is happening with current code I have
at the moment when I click "register" I'm nav to the php file. Thank you
You forgot the most important thing about an HTML form: the <form> tag.
You have to wrap the whole form (all inputs) which should be submitted when clicking like this:
<form method="POST" action="cus.php">
...
</form>
This will send all inputs to cus.php and make them available there as variables $_POST['input_name']. You can alternatively use GET as the method (and then use the $_GET array instead).
Edit: Didn't see it, you actually do have a form tag. However it's missing the target file in its action attribute.
First, see DCoder's comment. It's the most important.
Change:
<form action="" method="seller">
To:
<form action="cus.php" method="post">
Does that fix it?
Try to do this
FORM action="your script" method="Post"