Prevent page load on refresh - html

I have a simple html form which submits to the database on submit click.
It's working fine till here but after that when I refresh the page or page loads again,the values resubmit.How to rectify that?

After u submit the page and data get stored in the database successfully reload the same page
using
echo "<script>window.location='yourpagename.php'</script>";

After the form has been submitted, redirect to another page. Then refreshes will not matter.
See Post/Redirect/Get on Wikipedia for details on this pattern.

Related

Form action wordpress

My wordpress site has one contact form and even I have another website (Used html code).
I called wordpress form in html using id,Now I added captche to both the site because of that not abled to submit the form showing an error. How can I call that form using Iframe and while submitting the button in my site(HTML) bth the form(wordpress site and my site) the form should take the action . Need to show thank you message in the site.

How to stay on the same page without reloading on form submit in nodejs?

After form submit, I want to stay on the same page without reloading the page. Currently I'm using redirect method & specifying the same html page name to redirect to the same page in nodejs post method. But it is reloading. We dont want to reload.

What's the best way to do a bunch of delete links in a list?

Delete requests should be POSTs (or DELETEs). But we can't create a POST/DELETE with an <a> tag.
Is it really necessary to wrap a single delete button in a giant <form> complete with hidden CSRF token for ~30 different items on a page, or is there a nicer way to approach this?
You could do it in pure JavaScript by sending a POST request with XmlHttpRequest, as discussed here: Send POST data using XMLHttpRequest
A solution without JS:
Make a landing page with PHP that will handle the deletion and redirect you back - that way, you'll have no worries about the UI and you can even get away with a GET request from standard anchor tags. The user flow will look more natural than doing AJAX + refresh on success.
You can even use the existing page (let's call it page.php), for example:
click an anchor that will take you to page.php?action=delete&token=123&ids=1-2-3-4-5
the page will recognize the action parameter, validate the token and delete items with the submitted IDs
after it's done, it will redirect you back to page.php (so the URL looks nice again and you're safe with users clicking the refresh button)
From what I've gathered from the comments, there's basically 3 approaches:
Wrap each delete button in a <form> as originally stated in the question
Issue an AJAX DELETE request and when it completes, either
Refresh UI elements with jQuery (or other front-end framework)
Reload the entire page
Make the delete buttons link to an intermediate page with a single <form> element. This may also serve as a confirmation page.
Have the form submit itself automatically with JS
The AJAX solution with full page reload (2.2) sounds like it would produce the least cruft to me.

How to return an image through asmx web service and show in html page

I want to return image(s) through asmx webservice and show them in a html page.
I should not images are located in a folder named by numbers (1.jpg, 2.jpg and etc.) on server and also I should note that I don't want to make and use url for each image because it may cause security issues for me.
I have a textbox in my html page with a submit button and I want to see "1.jpg" in my html page when I insert 1 in textbox and press submit button.
Please help me to play out.
I have a textbox in my html page with a submit button and I want to see "1.jpg" in my html page when I insert 1 in textbox and press submit button.
Simply return the image data from your service along with the appropriate Content-Type header, such as image/jpeg. Then, use JavaScript to create an img element that references your service:
<img src="images.asmx?image=1.jpg" />
I don't want to make and use url for each image because it may cause security issues for me.
I don't know what security issues you're referring to, but just because you can access these images via script doesn't make them secure. Anyone can access them this way unless you take steps to prevent it. It's no different than simply changing the URL.

f5 - refresh only the frame

Is it possible to refresh only one frame in the windows and not all the frames?
My problem is that i have a page index.php and inside there are two frames - menu and content. when the user clicks on refresh(f5) the index.php has been loaded again and the content page is blank.
What can i do?
If you are familiar with javascript's usage in page refresh. You can try that instead of traditional html do a job.
javascript:location.reload(false)
will do a page reload from the cache. Set this to your content page and for menu page you can set this.
javascript:location.reload(true)
What you can do is store the last page selected by the user in cookie (using client side code) then in the page load even (client side again) check for that cookie and if exists, load that page by default instead of showing blank page.
Using jQuery accessing cookies becomes really simple: http://plugins.jquery.com/project/Cookie