I just started using twitter bootstrap, and I got stuck trying to get my form submit button to submit (PHP $_POST). Does anyone know why its not working?
No clue really..
I've been doing this previously and its been working until bootstrap:
<?php
if (isset($_POST["login"]) && $_POST["login"]=="login") {
echo "login here";
}
?>
<form action="http://mysite.com" method="post">
<input type="hidden" id="login" name="login" value="login" />
<button class="btn success" type="submit">Login</button>
</form>
The page seems to load but the PHP does not. Is the POST information being blocked?
My form input elements did not have an id or name (I didn't include them in my example).
Not an HTML expert, but I've always used <input type="submit" /> and not <button type="submit" />, not sure that button is a functional form element.
Also, your button element is closed twice - first with /> in the opening tag, and then again with a closing tag for no reason.
Maybe you are wrong with the action="http://mysite.com"? That attribute is for specifing the form data receiver, so in your case I think it's the page itself. So, if your page is named mypage.php, use action="mypage.php".
I had this same issue as well, turns out I was missing the name="submit". Gotta have that so the $_POST has a key in the assoc array!
it is adviseable that every element has a name thus (name="elementName") this makes it easy to reference them in your php scipt; also ensure that a form action and method are set.
Related
I am trying to pass a GET parameter through a button but I can't figure out what I am doing wrong. The parameter is set, as it shows up fine in the header, but it isn't being added to the edit.php url. The button is directing me to edit.php, just without the GET parameter added. I am pretty new to this stuff and this is my first time using links that aren't through anchor tags, so I am clearly missing something here. Any advice is greatly appreciated.
<h1 class="headerWithButton">Claim #<?echo($_GET['claim_id'])?>
<form>
<button type="submit" formaction="index.php" class="backButton">Back</button>
<?echo('<button type="submit" formaction="edit.php?claim_id='.$_GET['claim_id'].'" class="editButton">Edit</button>');?>
</form>
</h1>
When you submit a form using the GET method, any existing query string in the action will be replaced by a new one generated by the name and value of the successful controls associated with that form.
In your case, the only successful control is the submit button, which doesn't have a name or a value.
You could get the effect you desire by moving the data to those attributes:
<h1 class="headerWithButton">Claim #<?php echo htmlspecialchars($_GET['claim_id']); ?>
<form>
<button formaction="index.php" class="backButton">Back</button>
<button formaction="edit.php" name="claim_id" value="<?php echo htmlspecialchars($_GET['claim_id']); ?>" class="editButton">Edit</button>
</form>
</h1>
Important security note: inserting data from the URL directly into a page makes you highly vulnerable to XSS attacks. You need to take precautions against that. The most basic of those is using htmlspecialchars.
Note, however, that it isn't really appropriate to use a form here. Your form buttons are not submitting any data the user has entered, nor performing any kind of action. The affordances offered by buttons are misleading here.
You can, and should, use regular links instead.
<form method="get" action="edit.php">
<?echo('<button type="submit" formaction="edit.php?claim_id='.$_GET['claim_id'].'" class="editButton">Edit</button>');?>
</form>
instead of using the form you can just use a straightforward link
k with the anchor tag
edit
or you can specify the methos of get on the form with a hidden for input to place the link get parameter
If you have to use formaction, you must specify name and value of element:
<h1 class="headerWithButton">Claim #<? echo($_GET['claim_id'])?>
<form>
<button type="submit" formaction="index.php" class="backButton">Back</button>
<?php echo('<button type="submit" formaction="/edit.php" name="claim_id" value="'.$_GET['claim_id'].'" class="editButton">Edit</button>');?>
</form>
here it is better to place buttons in different blocks. But personally, in this case, I use a hyperlink
<form method="get" action=""></form>
<?echo('Edit
I find the easiest way to pass values with a button is to just wrap a form around the button.
$id = $_GET['claim_id'];
echo <<<EOT
<form action="index.php" method="get">
<button>Back</button>
</form>
<form action="edit.php" method="get">
<button name="claim_id" value="$id">Edit</button>
</form>
EOT;
I have a button in my html form that I want it to take user to food.php when they click on it, I did this but it's not redirecting, Please help
<a href="food.php">
<button name="submit" type="button" id="food">Food - Equipment</button>
</a>
Try this:
<button>Food - Equipment</button>
Why use a button element inside a link tag? Why not just:
Food - Equipment
Try that and see if it fixes it.
A button is requested, not a link. Sometimes linked php files don't work as expected in some browsers. Use a form submit button and you'll get what you're looking for.
<form action="food.php" method="GET"> <!-- use get or post if you want
to send anything -->
<input type="submit" value="GO">
</form>
I'm having a problem with my HTML GET form that's connected to a PHP script, so, basically, when the action is done I see the SUBMIT button value in the URL, so it's like this http://url.com/?valueI=Want&submit=Submit+Value.
How do I stop that from happening?
Remove the name attribute from the submit element to prevent it from being passed in the query parameters.
See: Stop the 'submit' button value from being passed via GET?
This is the nature of GET requests. The submitted values, aka Query String, are shown as part of the URL after a ? suffixing the page URL.
If you don't want it to show up, use POST method, or make a script that submits using Ajax.
Now if the question is only about the text in the submit button being shown, if you don't want it to get submitted along with the rest of the form all you have to do is not give it a name.
<input type="submit" value="Send Form">
No name="..." in the tag.
you need to set the form method
<form action"/your/path" method="post">
...
</form>
You can use button tag to submit the value using GET method.
<button type="submit">Submit</button>
do something like:
<form action="myfile.php" method="get">
(your form elements here)
<input type="submit" value="Submit" />
</form>
For my php file, I need to grab the unique form name.
The php file is executed when a user clicks the submit button. However, there are multiple submit button each with the same id, but they all have unique names. I need the name when they click on the submit button.
you dont want elements in html with the same id - bad practice in general. Your page will likely load normally but an html validator will notice it as an error.
html validator: http://validator.w3.org/
without seeing your code, its difficult to give you a definitive answer. if you have miltuple forms you can use hidden inputs. e.g.
<input type="hidden" name="form_name" />
Otherwise you can use javascript to put data in the form when the button is clicked. example javascript using jquery
html:
<form id="formid" >
<button type="button" id="someid" onclick="submitForm('btn1')" />
<button type="button" id="someid" onclick="submitForm('btn2')" />
<input type="hidden" id="btnsubmitid" value="" />
</form>
js:
function submitForm(btnID){
$("#btnsubmitid").val(btnID);
$("#formid").submit();
}
1 way is to put a hidden input inside of your form.
<input type="hidden" name="formName" value="[name of form]" />
then in your php, you can get it using
$form-name = $_POST['formName'];
pretty sure there are other ways, but this came to mind first.
I was wondering if my code below is even correct, I've been having numerous errors with this, but am not sure if the problem really exists here. The code is below:
The user will click 'Exit Group'.
<p class="logout"><a id="exit" name="logout" href="#">Exit Group</a></p>
The code that should be execute when 'Exit Group' is clicked is below:
if(isset($_GET['logout'])){
//CODE TO BE EXECUTED
}
However, the code I am trying to execute when the user clicks 'Exit Group' is not even being executed. There is nothing wrong with the code within the braces, as numerous people have checked it. But I was wondering if my problem may lie in the code above? Thank you.
If you click the link, nothing happens because the URL only contains the fragment identifier #. Not even a GET request will be issued.
You use this kind of link normally to jump to an element inside the page (e.g. Top to jump to an element with ID top). This is completely handled in the browser.
And if you only put the fragment identifier there, just nothing will happen. This is very often used if the link should execute some JavaScript and should actually not link to something else.
You are testing the $_POST array at the server side. But this array only contains elements, if you initiate a POST request by a form. That means you need to create a form with a submit button, e.g.:
<form action="" method="POST">
<input type="submit" name="logout" value="Exit Group" />
</form>
Here comes the name attribute into play, which will be the key in the $_POST array. But assigning this on a normal link will have no effect.
You could do it also with the link, but with a GET request this way:
<a id="exit" href="?logout=1">Exit Group</a>
<!-- ^-- parameter must be part of the URL, name has no effect -->
and
if(isset($_GET['logout'])){
//CODE TO BE EXECUTED
}
Note that you have to pass a parameter logout it here.
It seems you have mixed up GET and POST requests. If you have a form, the name s of the form elements will be transmitted as parameters to the server. That means given this form:
<form method="POST">
<input type="text" name="foo" value="" />
<input type="text" name="bar" value="" />
<input type="submit" name="send" value="Send" />
</form>
if the user clicks on the submit button, the $_POST array at the server side will have the keys:
$_POST['foo']
$_POST['bar']
$_POST['send']
This does not work with links though. A click on a link will create a normal GET request, and here, the parameters must be part of the URL, appended after a question mark ? and separated by an ampersand &:
Link
will result in
$_GET['foo']
$_GET['bar']
$_GET['andMore']
You probably should read about the HTTP protocol.
a isnt a form control. it needs to be an input or select if it's within a form.
For manual linking, do href="/page?logout"
You're using a regular hyperlink, no form will get posted. you need a submit button of some kind in a form with method="post" to do that. regular links just result in GET requests and nothing will ever be posted that way.
edit: added simple example:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Form test</title>
</head>
<body>
<?if ($_SERVER['REQUEST_METHOD'] == 'POST'):?>
<pre><? print_r($_POST)?></pre>
<?endif;?>
<? // $_SERVER['REQUEST_URI'] holds the current URL, so we know that ?>
<? // we'll end up back in this file when the form is submitted. ?>
<form method="post" action="<?= $_SERVER['REQUEST_URI']; ?>">
<input type="text" name="textbox"
value="<?= isset($_POST['textbox'])?$_POST['textbox']:'Type something' ?>" />
<input type="submit" name="submitbutton" value="Submit" />
</form>
</body>
</html>
$_POST will only be filled if you use a form with method=post.
Yes. A POST and a GET are two different things ;)
if(isset($_GET['logout']))
This <a id="exit" name="logout" href="#"> should be <a id="exit" href="?logoff=true#">.
Then logoff will be in the $_GET array.