How To Make My HTML5 Form Refresh On Its Own? - php

I have a contact form on my website, and once you click submit button, an echo message comes up but on a new page.
I want the page to automatically refresh when someone clicks submit, but also along with the echo message.
This is the HTML5 Code:
<form method="post" id="form" action="send3.php" class="sendmail" onsubmit="return validateForm()" style="text-align:center;">
<!-- Form Name -->
<center><h2 class="">Contact Us</h2>
</div>
<center><label class="control-label">Your Email Address</label>
<center><input type="text" id="eadd" name="eadd" class="input-xlarge" required>
<center><label class="control-label">Topic of Message</label>
<center><input type="text" id="top" name="top" class="input-xlarge" required>
<center><label class="control-label">Message</label>
<center><textarea id="mess" name="mess" required></textarea>
<Br>
<!-- Button -->
<label class="control-label"></label>
<div class="controls">
<center><input class="btn btn-primary" type="submit">
</div>
</form>
Any Tips/Adivce would be very much appreciated!

Sound like this is what you are looking for...
[myContactPage.php]
if ($_SERVER['REQUEST_METHOD'] == 'POST') //Here you could check other items like referrer or some of your posted fields if you want
{
//do whatever your current send3.php does
//echo the result back out
}
<form method="post" id="myForm" action="myContactPage.php" onsubmit="return validateForm()">
[email field]
[name field]
[message field]
etc...
[submit button]
</form>

Related

mailchimp auto pre filled url encoding

how to pre fill my subscription forum with email.for example if some one want to enter his "email" and click "senden" button for subscription, his "Email" should already be there in my subscription forum. down is the urls from website(for embedded subscription forum), code of this embedded widget and subscription forum.
mail chimp subscription forum url: http://boooo.us7.list-manage.com/subscribe?u=2e01f07a729f6f76a41a34ca5&id=66efb8b1bb
website url: www.boooo.com
code:
<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
<form action="//eepurl.com/-xxxx" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate="">
<div id="mc_embed_signup_scroll">
<input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder=" E-Mail Adresse" required="" />
<!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;">
<input type="text" name="xxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxx" tabindex="-1" value="" />
</div>
<div class="clear">
<input type="submit" value="senden" name="senden" id="mc-embedded-subscribe" class="button" />
</div>
</div>
</form>
</div>
<!--End mc_embed_signup-->
Thanks for the help.
Sorry for not mentioning the code it was my first question and didn't notice to put 4 spaces for the code.
I solved it by adding "&email=value" in the last of my url.
<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
<form action="http://boooo.us7.list-manage.com/subscribe?u=2e01f07a729f6f76a41a34ca5&id=66efb8b1bb&email=value" method="post" id="mc-embedded-subscribe-form" name=
"mc-embedded-subscribe-form" class="validate" target="_blank" novalidate="">
<div id="mc_embed_signup_scroll">
<input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder=" E-Mail Adresse" required="#" />
<!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;">
<input type="text" name="e01f07a729f76a41a34ca5_66efb8" tabindex="-1" value="" />
</div>
<div class="clear">
<input type="submit" value="senden" name="senden" id="mc-embedded-subscribe" class="button" />
</div>
</div>
</form>
</div>
<!--End mc_embed_signup mce-EMAIL mc4wp_email //eepurl.com/-Mi4r
-->
You can use the $_POST variable on your backend form for this.
The first form:
<form action="subscription.php" method="post">
<input type="text" name="first_email">
<input type="submit">
</form>
The subscription form:
<form action="mailchimp.php">
<input type="text" name="email" value="<?php echo $_POST['first_email']; ?>"
....
For more info:
http://php.net/manual/en/reserved.variables.post.php
If all you want to do is go to that mailchimp signup page and prefill the email, this link seems to work:
https://boooo.us7.list-manage.com/subscribe?u=2e01f07a729f6f76a41a34ca5&id=66efb8b1bb&MERGE0=foobar#foobar.com
If you need a form, try
<!-- Mailchimp Signup Form -->
<form
action="https://boooo.us7.list-manage.com/subscribe?u=2e01f07a729f6f76a41a34ca5&id=66efb8b1bb"
method="post" target="_blank">
<input type="email" name="MERGE0" placeholder="Your e-mail">
<input type="submit" value="Subscribe">
</form>
<!--End Mailchimp Signup Form -->

PHP how to make form disappear after pressing submit button

Lets say i have a form that asks for name and exam result. Id like to make the form disappear and display another div when the user hits submit.
heres the form code
<form action="exam.php" method="post" id = "coursedata" class="form-horizontal">
<fieldset>
<legend>Please Complete the Details</legend>
<div class ="form-group">
<label for="name" class="control-label col-xs-2">Student name</label>
<div class="col-xs-6">
<input type="text" name="name" id="name" size="20" class="form-control" autofocus required pattern = "[A-Z][a-z]+( [A-Z][a-z]+)?" title="Please enter a name (Surname optional) with First Letter capitalised">
</div></div>
<div class ="form-group">
<label for="CA1" class="control-label col-xs-2">Assessment One</label>
<div class="col-xs-6">
<input type="number" class="form-control" min = "0" max = "100"name="CA1" id="CA1" size="3" maxlength ="3" onkey ="limit(this);" onkeyup="limit(this);" required>
</div></div>
<div class="buttonarea">
<input type="submit" value="Submit" name = "Submit">
<input type="reset" value="Clear the Info">
</div>
</fieldset>
</form>
The shortest way (asuming that form and exam.php are the same files...):
<?php
if (!isset($_POST['Submit'])) {
?>
Your form code
<?php
}
else {
// form engine
echo "<div>SUCCESS</div>";
}
?>
Hope it helps :). PS. This is a strict answer to Your question, whether there are many other questions, like how to handle form, how to verify it, etc. But this is another side of answered coin ;). Best regards :).
Use jQuery for this (JavaScript library).
Copy this in your head section
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('button[type="submit"]').click(function(){
$("#coursedata").hide();
return false;
})
})
</script>

How to return php code into html body

I am building a simple form script that collects a users email and returns a PIN.
The input sits in standard HTML below:
<p>
<form class="form-inline" role="form" method="POST">
<div class="form-group">
<label class="sr-only" for="srEmail">Email address</label>
<input type="email" name="srEmail" class="form-control input-lg" id="srEmail" placeholder="Enter email">
</div>
<button type="submit" name="srSubmit" class="btn btn-default btn-lg">Generate PIN</button>
</form>
</p>
I have the following if statement that checks the database to see if the email already exists, and if the user would like a PIN reminder.
if($num_rows != 0) {//if email found in table
?>
Email already registered, would you like a PIN reminder?
<form method="POST" action="">
<input type="submit" name="srSend" value="Click here to get pin reminder" />
<input type="hidden" name="srEmail" value="<?php echo strtolower($email);?>" />
</form>
<?php
exit;
}
At the moment, this returns the result to the user as a new page; how do I put this in the actual HTML of the body page, so it would actually appear below the original form input in a new <p> element?
This is a piece of cake with jquery.post
include the jquery library in your html head and you'll need a short script to get the php content by ajax
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function(){
$('#yourForm').submit(function(e){
e.preventDefault();
var data=$('#yourForm').serialize();
$.post('yourphp.php',data,function(html){
$(body).append(html);
});
});
});
</script>
</head>
<body>
<p>
<form id="yourForm" class="form-inline" role="form" method="POST">
<div class="form-group">
<label class="sr-only" for="srEmail">Email address</label>
<input type="email" name="srEmail" class="form-control input-lg" id="srEmail" placeholder="Enter email">
</div>
<button type="submit" name="srSubmit" class="btn btn-default btn-lg">Generate PIN</button>
</form>
</p>
</body>
You could able to achieve that without ajax too. Simply use a hidden iframe in your main page, then set the target attribute of your form to the iframe as follows:
<form method="post" action="page.php" target="myIframe">
.....
</form>
<p id="theResultP"></p>
<iframe src="#" name="myIframe" style="visibility: hidden"></iframe>
The question now, How could you make the page loaded in the iframe "page.php" to interact with the opener page to update the p. This may be done as follow:
//page.php
<script>
result = parent.document.getElementById('theResultP');
result.innerHtml = "<b>The message you want</b>"
</script>
I dont know if I get what you asking for,but this is my solution :
<p>
<form class="form-inline" role="form" method="POST">
<div class="form-group">
<label class="sr-only" for="srEmail">Email address</label>
<input type="email" name="srEmail" class="form-control input-lg" id="srEmail" placeholder="Enter email">
</div>
<button type="submit" name="srSubmit" class="btn btn-default btn-lg">Generate PIN</button>
</form>
</p>
<?php
if (isset($message)){
<p><?php print $message ?></p>
?>
<?php
}
?>
and in top of your file write something like this :
<?php
if($_post['srSend']){
$message='write your message here';
}
?>

form is sending variables by get method

i got a form.
<form id="site-contact-form">
<div>
<div class="wrapper"><span>Ձեր անունը:</span>
<div class="bg">
<div>
<input type="text" class="input" name="contactname" id="contactname" />
</div>
</div>
</div>
<div class="wrapper"><span>Ձեր E-mail-ը:</span>
<div class="bg">
<div>
<input type="text" class="input" name="email" id="email" />
</div>
</div>
</div>
<div class="textarea_box"><span>Տեկստ:</span>
<div class="bg">
<div>
<textarea cols="1" rows="1" name="message" id="message"></textarea>
</div>
</div>
</div>
<div style="clear:both;"></div>
<button id="sub" name="submit">ուղարկել</button>
</div>
</form>
As you see i got no action on it, no method. But when im clicking on button, its refreshing the page (like when it have action) and adding to URL ?contactname=&email=&message=&submit= ... I never met this problem before, why it is sending variables? I dont have any php on page yet...
Beacause the default method is GET and the URL is the same of the page. Use:
<form method="POST" action="/reactor">
<!-- .... -->
</form>
Actually, the action property is mandatory.
Please correct the code with:
<form id="site-contact-form" method="post">
And the submitted values will not be displayed on the URL.
If you do not specify the form method, it will "get" by default.
This is happening here.
Change the type of button as button
<button id="sub" name="submit" type="button">ուղարկել</button>

Using "action" in Twitter Boostrap classes

I'm a newbie programmer trying to utilize Twitter Bootstrap to build out a concept. I'm using PHP and assigning actions within HTML tags to POST data and essentially take a user through the navigation. This has been pretty straightforward when using forms: i.e. here is a snippet that does work. For example, for this snippet of HTML:
<form action="?viewnotes" method="post">
<input type="hidden" name="id" value="<?php htmlout($note['id']); ?>">
</form>
It successfully triggers the following if statement in my index.php:
if (isset($_GET['viewnotes']))
However, I'm trying to do the same thing in my registration page, using a Twitter Bootstrap class for buttons. Here is the HTML:
<a class="btn btn-primary btn-large" action="?register">Sign Up Free!»</a></p>
The PHP code is:
if (isset($_GET['register']))
{
include 'register.html.php';
}
Clicking on the Sign Up button is not invoking the PHP code. If I hard code the URL it works, but then I have a similar issue on the register.html.php page. HTML on the register page has:
<form class="form-horizontal" action="?storeuser" method="post">
<fieldset>
<legend>It's quick and easy...</legend>
<div class="control-group">
<label class="control-label">First Name</label>
<div class="controls">
<input type="text" name="fname" class="input-xlarge" id="fname">
</div>
</div>
<div class="control-group">
<label class="control-label" name="lname">Last Name</label>
<div class="controls">
<input type="text" name="lname" class="input-xlarge" id="lname">
</div>
</div>
<div class="control-group">
<label class="control-label" name="email">Email Address</label>
<div class="controls">
<input type="text" name="email" class="input-xlarge" id="email">
</div>
</div>
<div class="control-group">
<label class="control-label" name="password">Password</label>
<div class="controls">
<input type="password" name="password" class="input-xlarge" id="password">
</div>
</div>
</fieldset>
<button type="submit" name="action" class="btn btn-primary btn-large">Complete Registration</button>
</form>
However, when clicking on the button, the index file does not trigger the following, which would store the fields into the DB.
if (isset($_GET['storeuser']))
If I hardcode the URL to register.html.php, then the resulting URL looks like localhost/register.html.php?storeuser instead of localhost/?storeuser. I'm not sure if that's affecting the behavior here.
Thank you for the help!
I think you're approaching this the wrong way, and it's not Twitter Bootstrap's fault.
Usually, you'd use POST, not GET, to handle user registrations. Your form would look like this:
<form action="register.php" method="post">
<!-- your form -->
<fieldset>
<input type="submit" name="register" value="Register" class="btn btn-primary" />
</fieldset>
</form>
You can then build register.php as follows:
<?php
if (isset($_POST['register'])) {
// handle user registration
}
// display form
?>
This will display the form when the user visits register.php, but will try and process the user registration first if the form's been POSTed.
try passing a value with your GET variable
<form action="?viewnotes=1" method="post">

Categories