page reload with success message php - javascript

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');

Related

Dynamically submit form and show the value of the input without reloading

I want to create a fully dynamic chat UI for my website,
But it reloads the whole page if a person submits the button this will directly show the div
<div class="messeging" id="msg">
<?php print $message->getName() ." : " . $chat->message . ""; ?>
</div>
Without reload msgs are save in some xml file path like example (../user/xml)
HTML
<form action="action.php" method="post">
<input type="text" id="input" value="php echo">
<input type="submit" value="send" onclick="showDiv()">
</form>
<div class="messeging" id="msg">
<?php print $message->getName() ." : " . $chat->message . ""; ?>
</div>
i don't know javascript/ajax well how to solve this
Try jquery ajax, on submit button send last msg for save into db and fetch all record and show them into chat page. so each time you send msg it will fetch all msg. if you don't know about how ajax work then let me know.
Begin by looking at the event on forms called 'onSubmit'. https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onsubmit
Once you understand that, you can 'event.preventDefault()' in your 'onSubmit' method handler. Or in English, keep a form's default behavior to submit to the action from occurring.
After preventing the default action, you will need to do something with the form, and the easiest in latest browsers is to use the fetch API. https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
You should be able to submit the data in the form to some endpoint that returns the HTML you wish to inject.
Once the HTML has been successfully returned, simple document.createElement methods with append (https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/append) will need to be used.
Good luck learning the web!

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.

HTML form POST to direct print page

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()"> ...

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