i have an div (id="id_content") in Main.html, and an php file "cmp.php" is dynamically loaded by JQuery.load() in "id_content". It is working fine.
However after the "cmp.php" called itself (for updating) using following code : <form action="<?php echo $_SERVER['PHP_SELF']?>" target="_self" method="post" >
the "cmp.php" occupies the complete browser, what i want ist that "cmp.php" is always being displaye in div "id_content".
Thanks in advance.
The problem is that you are posting the form with the target="_self". This tells the browser that what is returned from the cmd.php should replace the content of the current window.
You have some options:
1) Create an iframe on the main.html like:
<iframe id="postframe"></iframe>
Change the the form to:
<form action="<?php echo $_SERVER['PHP_SELF']?>" target="postframe" method="post" >
The result of cmd.php will now appear inside the iframe when you submit.
2) Use Jquery to post/get your form data and handle the result in Javascript.
<form id="yourform">
</form>
$("#yourform").on("submit",function(e){
//Called when you hit submit
e.preventDefault(); //Don't post the form
//Create a request from form variables and send to server.
//Depending on the result alter id_content.
return false;
});
you can submit form by using Ajax
Related
First page has form using method POST with action to the offer page.
<form id="value-form" method="POST" action="/offer/">
When user submits form on the first page, I want on the offer page class="add-info" to be added to the <form so then it fires up the jQuery script
<form id="formOffer" class="add-info">
Jquery
if (formOffer.hasClass('add-info')) {
launchrocket();
}
I can't figure out class tag can be added via PHP to the new form on the process page.
<?php
if($run == TRUE)
echo "Data Inserted Successfully <a href='index.html'>Click here to insert more</a>";
else
echo "Error !";enter code here
?>
I have created one html submit button and connects with php code but, after selecting that how can i go back my html page?
Realistically I would change the form to run the PHP on the same page. So on the line where you create a form, instead of putting <form action='whatever.php'></form> I'd remove the action piece, then move the PHP script onto the same page (make sure it's .php instead of .html), and then wrap your whole script in something like this:
if (isset($_GET['submit'])){ //or post depending on if you're using POST for your form, which is set by doing method=POST (suggested) or method=GET when creating the form's HTML
//your regular php script would go here :)
}
But if you insist on having the PHP on another page and having it direct back you can do it like such:
die(header('Location: index.html')); //change index.html to the directory of the page (or even a URL) that you want them directed to
Best of luck to you!
Use $_SERVER['PHP_SELF'] as action in the form
I would prefer you write your html in php file and then use $_SERVER['PHP_SELF'] this willl submit the data on the same page and you can handle the data of the form being on the same page/php file
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
I want to call a function which deletes my cookies, so I don't get any issues with that.
After deleting the cookies, it should return to my main HTML page.
echo '<tr><td colspan="5"><form method="" action="returnMain()"><button type="Submit">Zurück</button></form></td></tr>';
That's where I want to call my function. So if the button is clicked, it should call the function returnMain, delete the cookies and go back to my HTML page.
How am I able to call the function through php?
At the moment, the only thing that happens is that if I click the button, the function name is added to my URL which doesn't work at all.
Please add form like below code
<form method="" onclick="returnMain()" action="<?php echo $_SERVER['PHP_SELF']; ?>">
I am making an e-commerce website where I have lots of products. If a user goes to any product items page and submits any form there then they should come on the same page.
So, how to come on the same page?
On the formular target page set:
header('Location: http://www.example.com/same_page');
Leave action attribute of form blank. Like so:
<form action="" method="post">
Or
<form action="#" method="post">
On your opening form tag add
action="submit.php"
then once it goes to that page when the submit button is hit add this
to the bottom of that php page:
header("Location: success.html OR success.php");
If you want to submit various forms on same page and then go back to the page where the form is submitted, you must also send the form URL of the page where it was sent, preferably in a hidden element. And after processing form redirect to URL stored in hidden.
You can use this :
header('Location: filename.php);
If you get any $_POST errors put it in a condition: if(isset[$_POST])
Thank You All. I Got My Answer
$_SERVER['REQUEST_URI']; will give the current URL with query strings.
Like my page is 'products.php?Product=20'
echo $_SERVER['REQUEST_URI']; =>/products.php?Product=20
So, we can directly use this in header location.
I have looked all over stack, and googled the crap out of it, but everytime I come across something I only come across snippets and I cannot find the full code, how can I get a div to reload on form submit?
this is the div I want to refresh
<div id="accsettings">
<?php require_once('profileform.php'); ?>
</div>
this is the form
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] . '?username=' . $user_name; ?>">
Thanks
I need it to refresh on submit so that it shows the affect the player had on their profile
(by showing their comment and that they increased their rep on the webpage by +1 and removing the textfields/submit form, all that is already taken care of, I just need it to refresh on submit)
What's the name of you submit button? If it were submit, you could do something like:
<div id="accsettings">
<?php if (!isset($_POST['submit'])) { require_once('profileform.php');} else {echo ' ';} ?>
</div>
This assumes that the form submits to the current page.
$("form").on('submit', function (e) {
$.post($(this).attr('action'), $(this).serialize() + '&submit=TRUE').done(
function () {
$("#accsettings").load('profileform.php');
}
);
e.preventDefault();
});
What this will do is an ajax load of profileform.php into the contents of the #accsettings div. This assumes that your form submission properly updates the output of profileform.php and is done via ajax (I see no evidence of that in your code currently, though).