HTML form POST to direct print page - javascript

I have the page VIEW-SALE.PHP
on this page I have a submit button form to view the invoice in print format, there is the code:
<span style='display:inline-block'>
<form name='print' id='print' action='print-invoice.php'
target='_blank' method='post'>
<input type='hidden' name='invoice' value='$invoice'>
<input class='submit-all' type='submit'
value='Print the invoice'
onClick='window.print();return false'></form></span>
The code must just open the page PRINT-INVOICE.PHP and print it but when I click it it show the print dialog but of the current page I am VIEW-SALE.PHP so it does not show the PRINT-INVOICE.PHP
How does it can be done?

doesn't post just post data you may need a header redirect the redirect being php code
header("Location: blabla")
I found this you may find it of help
redirect after submit

the problem is the onClick='window.print();return false'. The window object is the current window containing the form. You should include an javascript event handler in your PRINT-INVOICE.PHP:
... <body onload="window.print()"> ...

Related

page reload with success message php

i am trying above but message is displayed on php page.instead of reloading on index page AND DISPLAY MESSAGE ABOVE SUBSCRIBE FORM ITS REDIRECTING TO PHP PAGE.You can check on test site link attached.Form is on index
page.I tried to reload page through jquery onload and onclick onsubmit but didn't worked.below are test which i did.
//form is on index.html page
<!-- your form here -->
<form action="forms/subscribe.php"id="form" method="post">
<input type="email" name="email" placeholder="Enter your Email">
<input type="submit" value="Subscribe">
</form>
//form is on index.html page
My php page
<?php
// My Code goes here form to email
header.location(Location: /index.html)
?>
You cannot use js variable values after reload. You need to do things without reloading the page means you just need to update the content and control your HTML tags.
The above example you mentioned. They are not reloading the page, they are getting values from input box then hide that div. After hiding the div they are showing another div with the information.
For your solutions you can do the same but remember to reset input values for every request.
You can do it in PHP with page reloads if you store a message in the session. At the top of each page make sure that the first line is
session_start()
Then on the page that receives the data set a session message
$_SESSION['message'] = 'Some Value';
Then on your page with the form you check to see if the session has a message. If it does, display it and then clear it.
if(isset($_SESSION['message']) {
echo $_SESSION['message'];
session_unset('message');
}
some silly syntax error
using onsubmit="alert()"
<script>
function alert() {
alert("Thank you for contacting us. We will be in touch with you very soon.!");
}
</script>
on subscribe pageheader('Location: /index?message=success');

Redirect the website URL Form to a particular Page

My Form Works Successfully But in website URL it only Shows the address to a Form.I have multiple Pages in which the Form button shown.All I want when a user click on The Form for Page A for that Particular page it should shown as
"www.form.com?test=page A" - this should displayed on website URL
or when the Form is submitted the receiver should view that this form coming from Page A..In the Form field I hidden this fields name 'Test' so the user cannot see it but only the receiver can view it that its coming from Page A
On my Html code I have redirected to the Build in Form.
Here is my java script code
<script type="text/javascript" src="http://test.com/form/y.php/test2"></script><no1script>Online Form - </no1script>
How to show it to my Website URL
I understand your question as "How can I redirect with a specific GET parameter?", correct me if I'm wrong.
The solution for that would be quite simple: Append the GET parameter to the forms action:
<form action="target.php">
gets
<form action="target.php?test=page_a">
so that on target.php if you evaluate the GET values, test has the value page_a.
If you're trying to hide the post data, you can try something like:
<form action="https://test.com/forms/discount" style="display:none">
<input type="text" name="couponCode" value="secret">
<input id="myform" type="submit">
</form>
<script>
document.querySelector("#myform").click();
</script>
Note: This won't stop any web ninjas, so you should think of something else, like web tokens that function sortta like private public keys.

Submit info and then open new webpage in button. Multiple actions using Form type = submit

How can I submit entries to my db and then open a link to a new page? In my situation I need to submit information filled out on a form to the DB and then open to a page that says thank you all in one click!
Here is what I have for the form portion minus the stuff in the middle
<form id="rent_form" action="<?= $_SERVER['PHP_SELF'] ?>" method='post' >
Stuff
<input type="submit" value="Submit" onClick="location.href='thankyou.php'" >
And the onclick does not work.
Mahalo in advance!
You could redirect to a success page using php if the submission is successful.
You can use header to redirect: header("Location: http://yoursite.com/success");
Alternitvely you could use AJAX to submit the data, and then in the success of your AJAX call redirect like this: window.location.replace("http://yoursite.com/success")
You could use the target attribute of the form tag to redirect the response from the action page to a new window i.e add target='_blank' to your form tag and have the response from your form submission be the HTML you want to display in the new page. This would save a redirect, I guess, at least.

Back to the form with back button

How does I can make the browser back button resend me the form? I have my page www.example.com/results where I see all results of $_POST search, when I click in one result I load it in www.example.com/result1 . I need to click on the back button and loads the form again without showing "Confirm form Resubmission" (F5). I do not care to do it with PHP, with JS, jQuery.
For example:
Index.html
<form method="post" action="results.html">
<input type="text" name="findSomething" />
</form>
In results.html show the results:
<a href="result1.html>Result1</a>
<a href="result2.html>Result1</a>
<a href="result3.html>Result1</a>
.......
In result1.html,resutlt2.html.... if a click on back button, brower says that I must to Resubmission the form.
It is default browser functionality ,you can change the setting using PHP only. You can use these syntax in your PHP config file before the session start:
<?php
session_cache_limiter ('private, must-revalidate');
$cache_limiter = session_cache_limiter();
session_cache_expire(60); // in minutes
?>
Now it will be not ask to re-submission the form.

Thank you alert upon form submission

I have a very basic form at http://www.happyholidaylites.com/contact.html and it is working great. When you submit the form, the user is brought to the index.html with no message that the form has been sent. I am looking to initiate an alert that says, "your form has been submitted" with an x button. My code looks like this:
<form method="post" id="myForm" action="dynaform.php">
<input type='hidden' name='rec_mailto' value='JBIRD1111#gmail.com'>
<input type='hidden' name='rec_subject' value='New Contact Form'>
<input type='hidden' name='rec_thanks' value='index.html'>
so on and so forth.....
The last line is what is telling the form what to do after the submit button is pressed, but I dont want it to point the browser to the index, rather I want a javascript popup with a success message. Any ideas?
Why not a simple onSubmit?
<form method="post" id="myForm" action="dynaform.php" onSubmit="alert('Thank you for your feedback.');" >
To be honest you are better re-directing to another page in order to avoid the user re-submitting the page on a refresh. Have a look at Post/Redirect/Get Pattern.
Popups can be extremely annoying on websites. You should create a page called "thank-you.html" that you can re-direct the user to on successful submission which has access to the site navigation options or even just do a re-direct back to the form page after a few seconds.
Instead of redirecting to index.html, redirect to thanks.html; your users will thank you because everybody hates popups!
Sounds like your PHP script handles the form submission by processing the input and redirecting the browser to the value in the rec_thanks field.
You can add something like onsubmit="YourJavaScriptFunction()" to the form tag to add client-side behavior prior to actually submitting the form. Within that function you can perform validation, use alert('Thank You!'), etc..

Categories

Resources