This question already has answers here:
Send ajax request
(2 answers)
Closed 5 years ago.
I read a lot questions and answers about this problem, but noone solved mine.
So i have a simple form:
<form action="#" name="pm" id="pm" method="post">
<input onclick="sendPM()" name="pmSubmit" type="submit" value="Send" />
</form>
And the following function:
function sendPM() {
$.post("something.php").then(function(data) {
});
}
In "something.php" i doing a simple INSERT INTO to my database.
This code works perfectly in IE but dont work in Firefox.
I dont know, what can i do to solve this.
Pls if anyone can help me, will save a lot of time for me.
This sounds like magic, but fixed it. Change
onclick="sendPM()"
to
onclick="sendPM(); return false"
I don't know why, but now both Chrome and Firefox perform the ajax call. Previously firefox did not even make the connection to the server...
Related
This question already has answers here:
Apache is downloading php files instead of displaying them
(27 answers)
Closed 1 year ago.
I am working on visual studio code making a few web pages and I need to send html form data from one to another. I am using the get method but when I submit the form the PHP file downloads instead of running, is there a way to fix this?
<form action="login.php" method="get">
<p class="normal" id="samelinechild">Dora the</p>
<input name="verification" id="very" type="text">
<p class="normal"id="samelinechild">explorer</p>
<input type="submit">
</form>
If you send data use POST method not GET. I don't know if this will fix the problem but it's the rule.
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 3 years ago.
So I've been trying to program a button that redirects you to another web page for quite some time now, and this is the Best solution I've come up with:
<form action="#" method="post">
<input type="submit" name="submit" value="LLL" />
</form>
<?php
$redirect_after_login='index.php';
if(isset($_POST['submit'])){
echo 'test'; //this was just a test
header('Location: ' . $redirect_after_login);
exit;
}
?>
So basically, what happens is that when I press the button I do not get redirected to the other page, but the echo command does emit test. Any ideas on how I could fix this? (Sorry for any gramar mistakes, english is not my first language, and if this is very obvious, I'm new to php :D)
You are most likely not actually executing the form through PHP. You're being redirected to the anchor # (action="#"), which does not result in a reload/re-request of the page, but only jumping to the top of the page. The action is mandatory to receive and process the forms data.
So try to change your forms action attribute to the filename of the PHP-File or just leave it blank to send the form data to "the same page".
<form action="" method="post">
<input type="submit" name="submit" value="LLL" />
</form>
Also you should do any processing first, and output last. Move the form to the bottom of the file, because header() can't send its headers when something has been output before (your form in this case).
This question already has answers here:
Call PHP function from url?
(14 answers)
What is the difference between client-side and server-side programming?
(3 answers)
Closed 3 years ago.
I want to do operation to a database that is running on xampp in my index.html I have the following code
<script src="oPBD.php" async defer></script>
<h1>This is a title</h1>
<form action="opBD.php">
<input type="submit" value="Do stuff" name="Button">
</form>
And this works fine, howevewer I would like to put all the code in opBD.php in a function called function1 for say something and run in html when needed. But How I do that.
I would like to use something like:
<script src="oPBD.php" async defer></script>
<h1>This is a title</h1>
<form action="opBD.funtion1().php">
<input type="submit" value="Do stuff" name="Button">
</form>
I don't find how to do this. Could you guys help me?
Can you just create a new file opBD.functionName.php and then use that in your form action? Otherwise your only real option is to use an MVC (Model View Controller) framework like Laravel or similar which would let you create real URLs for this kind of thing (eg. /user/update or something).
This question already has answers here:
Chrome: ERR_BLOCKED_BY_XSS_AUDITOR details
(8 answers)
Closed 4 years ago.
I have one page where I submit hidden form where I store a large html code that is made in javascript and I want to send that code via form to another php file. It should work but my browser blocks it(google chrome):
<form action="napravi.php" method="post">
<input type="text" name="code" value=""/>
<input type="submit" id="forma_napravi"/>
</form>
and in javascript:
document.getElementById("forma_napravi").click();
and php page where I send the form data:
if(isset($_POST['code'])){
echo $_POST['code'];
}
and this is error that browser shows to me:
It will show error if you send html or javascript code this way because it is google chrome's in-built design.
I tried your code it was working. But when I put some code in place of blank, e.g. value="<script>alert('123');</script>", I got the same error
You may use htmlentities() to parse the html to string. Then the code you send will have no effect at all.
give your form an id and check if it is been submitted. like this-
In your html file
<form action="napravi.php" method="post" id="form">
<input type="text" name="code" value=""/>
<input type="submit" id="forma_napravi"/>
</form>
In your javascript
document.getElementById("form").on('submit', function(){
// your code
});
Hope this will help
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!