I'm doing a project and using PHP. There is signup.php page with form and it is sending "GET" instead of "POST". Even after hours of debugging, I could not come up with anything, I found a similar question but that seems to be of no help in my case. I have similar login.php page with almost same code and that works fine, I don't know what wrong I'm doing.
<form name="signUpForm" id="signUpForm" action="signup.php" method="post">
//form elements
<button type="submit" value="Submit">Submit</button>
</form>
Following the question mentioned, I tried to change it to
<button type="submit" value="Submit" formmethod="POST" formaction="signup.php" >Submit</button>
But this also gives the same result.
echo $_SERVER["REQUEST_METHOD"];
Above statement prints "GET" in PHP.
I would like to know what I'm missing, I know similar questions exist but I checked them before putting the question.
GET is the automatic default. Make sure that you close all of your open form tags and set the method="POST".
I just ran into this problem!
Related
Basically what i wanted to achieve here is adding a "?" to the form url.
My current code that is not working:
<form action="'.$config['base_url'].'/whatever/users.php?f=verification">
<button class="btn btn-success">Verification</button>
</form>
i would love for someone to explain what i did wrong so i can learn from my mistake and also possibly solve the issue to retain a good answer along with me learning to see what i did wrong here.
As far as my testing goes everything else seams to be working, what is happening here is that i get redirected to "/whatever/users.php" instead of "/whatever/users.php?f=verification"
echo the base_url into the form action and add the f parameter and value to the button element. On submit f=verification will be in the POST/GET.
<form action="<?=$config['base_url']?>/whatever/users.php">
<button class="btn btn-success" type="submit" name="f" value="verification" >Verification</button>
</form>
This is what I am currently doing:
<form method="get" go="welcome.php">
<button type="submit">continue</button>
</form>
But it is just taking me to an error page that says:
Firefox can't find the file at /action_page.php?
Check the file name for capitalization and other typing errors,
Check to see if the file was moved, renamed or deleted.
I even did rename it and I put in my form and it still doesn't go to my php page! Anyone know how to do it better.
Still I am only a starter at code and barely know what I'm doing.
You would use the action attribute.
<form method="get" action="welcome.php">
<button type="submit">continue</button>
</form>
i send an HTML email with a form and a button like this:
<form action="http://myurl/index.php" method="post">
<input type="hidden" name="testing" value="123456">
<button class="btn" type="submit">SEND</button>
</form>
then in my index.php page i read the testing variable, in this way:
echo $_POST['testing'];
but i can't read the variable and give me this:
Notice: Undefined index: testing
there is a way to send a variabile from an html mail to a php page?
Oh. Got that Email Part now.
Most Mail-Programs won't do POST requests, for security/privacy reasons. Use GET here:
in HTML:
SEND
and in PHP:
echo $_GET['testing']
Of course the data is visible in that case - but that's the entire point.
Emails don't play well with a lot of fairly standard html. In this case, I'd use something like this:
Submit
And then style your anchor to look like a button. Then on your php side, use this to make sure the variable gets there:
print_r($_GET);
What happens when you replace:
<button class="btn" type="submit">SEND</button>
With
<input type="submit" value="Send" />
I realize you are probably styling it given that you have a class statement but you can still style an input type="submit" easily enough. I ran into issues posting variables using the object.
Also, FWIW, you don't need to specify the full URL in the action. In fact, you should probably do the following to safeguard your self against XSS attacks:
<form action="<? echo htmlentities('/path/to/index.php'); ?>" method="post">
In native PHP I can include a javascript code to change the action of a form sent in case I need to direct the user to which page he selects to go like this
<form action="change.php" method="post" name="form">
<input type="submit" value="Click to Page1" onclick="form.action='page1.php';return true;"/>
<input type="submit" value="Click to Page2" onclick="form.action='page2.php';return true;"/>
</form>
I would like to do the same in case I must use codeigniter or cakephp. Someone could help me with this problem ?
CodeIgniter is a backend technology. What you're writing is front end. You're pretty much all set; there isn't really much for you to change. You could, theoretically use CI's form helper, but it's unnecessary...personally, I never use it.
Unless you've removed the index.php file, change the form.action from page1.php and page2.php to index.php/mycontroller/myfunction.
The whole form idea though is sort of flawed; you don't really need it. Why not just use:
onclick="window.location.replace('index.php/mycontroller/myfunction');"
Then you can remove the form all together.
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.