I am facing a problem for my form.
It cannot receive well when i set abc#xxxx.co.id as receiver. All message is correct, just it will stat with "Content-type: text/html; charset=utf-8 " and come with table format.
It should look tidy.
Content-type: text/html; charset=utf-8
To: crm#merekmu.co.id
From: <hl.tam#webnic.cc>
Message-Id: <20130618031715.7DA4712406D9#gemilang-pandi.localdomain>
Date: Tue, 18 Jun 2013 10:17:15 +0700 (WIT)
<html>
<head>
<title>Merekmu “LIKE and WIN” Contest Submission</title>
</head>
<body>
<h2>Merekmu “LIKE and WIN” Contest Submission</h2>
<table width='95%' cellpadding='0' cellspacing='11'>
However, this form work well if i use another email as receiver(123#xxxx.com). Use same code, i just change email.
I made some testing as below:
email 1:abc#xxxx.co.id
email 2:123#xxxx.com
web 1:www.456.com
web 2:www.abc.co.id
Test 1: set email abc#xxxx.co.id as receiver at www.abc.co.id - messy message receive
Test 2: set email 123#xxxx.com as receiber at www.abc.co.id - work well and show tidy message
Test 3: set email abc#xxxx.co.id as receiver at www.456.com - work well and show tidy message
I have no idea with what problem is it?
<?php
$firstName= $_POST['firstName'];
$lastName= $_POST['lastName'];
$email= $_POST['email'];
$fbUrl= $_POST['fbUrl'];
$blog= $_POST['blog'];
// subject
$subject = $name;
// message
$message = "
<html>
<head>
<title>Merekmu “LIKE and WIN” Contest Submission</title>
</head>
<body>
<h2>Merekmu “LIKE and WIN” Contest Submission</h2>
<table width='95%' cellpadding='0' cellspacing='11'>
<tr>
<td width='189'> First Name:</td>
<td>$firstName</td>
</tr>
<tr>
<td width='189'> Last Name:</td>
<td>$lastName</td>
</tr>
<tr>
<td width='189'> Email:</td>
<td>$email</td>
</tr>
<tr>
<td width='189'> Facebook profile URL:</td>
<td>$fbUrl</td>
</tr>
<tr>
<td width='189'> Blog:</td>
<td>$blog</td>
</tr>
</tr>
</table>
</body>
</html>
";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
// Additional headers
$headers .= "To:crm#merekmu.co.id" . "\r\n";
$headers .= "From:".$name."<".$email.">\r\n";
$subject .= "Merekmu “LIKE and WIN” Contest Submission ";
//$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
//$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
if(mail($toemail, $subject, $message, $headers)) {
echo '';
} else {
echo '';
}
?>
valindation
$(document).ready(function() {
$('form#contactForm').submit(function() {
$('form#contactForm .error').remove();
var hasError = false;
$('.requiredField').each(function() {
if(jQuery.trim($(this).val()) == '') {
var labelText = $(this).prev('label').text();
$(this).parent().append('<div class="error">Lapangan tidak boleh kosong.</div>');
hasError = true;
} else if($(this).hasClass('email')) {
var emailReg = /^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test(jQuery.trim($(this).val()))) {
var labelText = $(this).prev('label').text();
$(this).parent().append('<div class="error">Silakan masukkan email yang valid.</div>');
hasError = true;
}
}
});
if(!hasError) {
$('form#contactForm li.submit_btn').fadeOut('normal', function() {
$(this).parent().append('<img src="/wp-content/themes/td-v3/images/template/loading.gif" alt="Loading…" height="31" width="31" />');
});
var formInput = $(this).serialize();
$.post($(this).attr('action'),formInput, function(data){
$('form#contactForm').slideUp("fast", function() {
$(this).before('<p class="thanks">Formulir telah dikirimkan.</p>');
});
});
}
return false;
});
});
HTML
<form action="submit.php" id="contactForm" method="post">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" colspan="2" align="center"> <div class="title"> Merekmu “LIKE and WIN” Contest Submission </div></td>
</tr>
<tr>
<td valign="top" width="200" class="form-left"><label for="contactName"><strong>First Name:</strong> <span class="require">*</span></label></td>
<td valign="top">
<input type="text" name="firstName" id="firstName" value="" class="requiredField" /></td>
</tr>
<tr>
<td valign="top" class="form-left"><label for="contactName"><strong>Last Name:</strong> <span class="require">*</span></label></td>
<td valign="top">
<input type="text" name="lastName" id="lastName" value="" class="requiredField" /></td>
</tr>
<tr>
<td valign="top" class="form-left"><label for="email"><strong>Email:</strong> <span class="require">*</span></label></td>
<td valign="top">
<input type="text" name="email" id="email" value="" class="requiredField email" /></td>
</tr>
<tr>
<td valign="top" class="form-left"><label for="tel"><strong>Facebook profile URL:</strong> <span class="require">*</span></label>
</td>
<td valign="top">
<input type="text" name="fbUrl" id="fbUrl" value="" class="requiredField" /></td>
</tr>
<tr>
<td valign="top" class="form-left"><label for="tel"><strong>Blog:</strong> </label>
</td>
<td valign="top">
<input type="text" name="blog" id="blog" value="" /></td>
</tr>
<tr>
<td valign="top" colspan="2" align="center"> <input class="submit_btn" type="submit" value="Submit" />
</td>
</tr>
</table>
</form>
Related
Let's say I have rendered the output rom the get request on an html template, now I need to use this same data to pass to a post request via a button on a same page. How do I do that?
I'm trying to do something like this:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Customer Home</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div th:replace="fragments/header :: header">
</div>
<div class="container">
<p> Thanks for booking with Gamma Airlines, here are your booking summary: </p>
<table th:object="${booking} class="table table-bordered table-striped">
<tbody>
<tr>
<td>Source</td>
<td th:text="${routeStart}"></td>
</tr>
<tr>
<td>Destination</td>
<td th:text="${routeDestination}"></td>
</tr>
<tr>
<td>Booking Charges</td>
<td th:text="${bookingCharges}"></td>
</tr>
<tr>
<td>Booking Charges Currency</td>
<td th:text="${chargesCurrency}"></td>
</tr>
<tr>
<td>Booking Date</td>
<td th:text="${#calendars.format(bookingDate)}">July 11, 2012 2:17:16 PM CDT</td>
<tr>
<td>
<div class="col-sm-9">
<form action="#" th:action="#{/email}"
th:object="${booking}" method="post"
role="form">
<button type="submit" class="btn btn-primary btn-block">Email</button>
</form>
</div>
</td>
<td>
<div class="col-sm-9">
<form action="#" th:action="#{/genpdf}"
th:object="${booking}" method="post"
role="form">
<button type="submit" class="btn btn-primary btn-block">Generate PDF</button>
</form>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Edit: Somebody please help tell me a simple method to pass the object since I have to use it at many places and object contains many child object as well in some cases. eg. the following case:
<div style = "margin-top: 2cm" class="container">
<table class="table table-bordered table-striped">
<thead>
<tr>
<td>Source</td>
<td>Destination</td>
<td>Amount</td>
<td>Currency</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<tr th:if="${offers.empty}">
<td colspan="5">No Offers</td>
</tr>
<tr th:each="offer : ${offers}">
<td th:text="${offer.route.from}"></td>
<td th:text="${offer.route.to}"></td>
<td th:text="${offer.price.amount}"></td>
<td th:text="${offer.price.currency}"></td>
<td>
<form action="#" th:action="#{/user/booking}"
th:object="${offer}" method="post"
role="form">
<button type="submit" class="btn btn-primary btn-block">Book</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
UPDATE 2:
I even changed the template by sending a new object in the get request and try to assign values one by one but I still get it as null in a controller.
<table class="table table-bordered table-striped">
<thead>
<tr>
<td>Source</td>
<td>Destination</td>
<td>Amount</td>
<td>Currency</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<tr th:if="${offers.empty}">
<td colspan="5">No Offers</td>
</tr>
<tr th:each="offer : ${offers}">
<td th:text="${offer.route.from}"></td>
<td th:text="${offer.route.to}"></td>
<td th:text="${offer.price.amount}"></td>
<td th:text="${offer.price.currency}"></td>
<td>
<form action="#" th:action="#{/user/booking}"
th:object="${booking}" method="post"
role="form">
<input type="hidden" th:attr="value = ${offer.route.from}" th:field="*{routeStart}" />
<input type="hidden" th:attr="value = ${offer.route.to}" th:field="*{routeDestination}" />
<input type="hidden" th:attr="value = ${offer.price.amount}" th:field="*{bookingCharges}" />
<input type="hidden" th:attr="value = ${offer.price.currency}" th:field="*{chargesCurrency}" />
<button type="submit" class="btn btn-primary btn-block">Book</button>
</form>
</td>
</tr>
</tbody>
</table>
These are my get and post methods:
#RequestMapping(value="/user/booking", method = RequestMethod.GET)
public ModelAndView getOffers()
{
ModelAndView modelAndView = new ModelAndView();
AirlineOffer[] offersArray= airlineClient.getOffers();
List<AirlineOffer> offers = Arrays.asList(offersArray);
modelAndView.addObject("offers", offers);
Booking booking = new Booking();
modelAndView.addObject("booking", booking);
modelAndView.setViewName("user/booking");
return modelAndView;
}
/** POST method for submitting deposit request */
#RequestMapping(value = "/user/booking", method = RequestMethod.POST)
public ModelAndView book(#Valid Booking booking,
BindingResult bindingResult, HttpServletRequest request)
{
ModelAndView modelAndView = new ModelAndView();
......
}
Alright, I finally resolved it using the following in my form:
<table class="table table-bordered table-striped">
<thead>
<tr>
<td>Source</td>
<td>Destination</td>
<td>Amount</td>
<td>Currency</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<tr th:if="${offers.empty}">
<td colspan="5">No Offers</td>
</tr>
<tr th:each="offer, stat : ${offers}">
<td th:text="${offer.route.from}"></td>
<td th:text="${offer.route.to}"></td>
<td th:text="${offer.price.amount}"></td>
<td th:text="${offer.price.currency}"></td>
<td>
<form action="#" th:action="#{/user/booking}"
th:object="${booking}" method="post"
role="form">
<input type="hidden" th:value="${offer.route.from}" name="routeStart" />
<input type="hidden" th:value = "${offer.route.to}" name="routeDestination" />
<input type="hidden" th:value = "${offer.price.amount}" name="bookingCharges" />
<input type="hidden" th:value = "${offer.price.currency}" name="chargesCurrency" />
<button type="submit" class="btn btn-primary btn-block">Book</button>
</form>
</td>
</tr>
</tbody>
All it took was to remove th:field and add the name attribute.
I "finished" my commenting system but one problem left.
After I write a comment and then reload the page, then the comment gets posted again..
Ive googled now 2~ hours and cant find some help
code:
<script type="text/javascript">
function toggle_comment(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
$(function() {
$(".submit").click(function() {
var comment = $("#comment").val();
var dataString = 'comment=' + comment;
if(comment=='')
{
alert('Please enter at least 30 characters');
return false
}
else
{
$.post("pages/comment.php", $("#postcommentform").serialize(), function(data) { });
}
});
});
$(function() {
$(".login").click(function() {
var username = $("#username").val();
var password = $("#password").val();
var dataString = 'username=' + username + '&password=' + password;
if(username=='' || password=='')
{
alert('Login is incorrect');
return false
}
else
{
$.post("pages/login.php", $("#postlogin").serialize(), function(data) { });
}
});
});
</SCRIPT>
<a class="sitelinksblue" onclick="toggle_comment('commentfield');" style="font-family: Verdana, Geneva, sans-serif;font-size:12px;font-weight:bolder;">+ Kommentar abgeben für Englisch Für Anfänger</a>
<BR></BR>
<?php
if(isset($_POST['submitcomment']) && $_POST['submitcomment']=="Submit") {
if((checkComment($_POST['comment']) && strlen($_POST['comment'])>=10 && strlen($_POST['comment'])<=1500)) {
$sqlCmd = "INSERT INTO topmovies.comments
(username,comment,date)
VALUES
('".mysql_real_escape_string($_SESSION['user_username'])."','".mysql_real_escape_string($_POST['comment']);."','".$sqlZeit."')";
$sqlQry = mysql_query($sqlCmd,$sqlHp);
?>
<?PHP
if (!$sqlQry) {
die('Invalid query: ' . mysql_error());
}else { echo'Comment Added!'; }
}else{ echo'Error! Please enter a comment with 30 or more and 1500 or less characters';}
} else { }
?>
<div id="commentfield" style="display:none">
<?PHP
if (isset($_SESSION['user_username'])){
if($getAdmin->status=='BANN'){
echo $lang['BANN'];
exit();
}else{
?>
<form id="postcommentform" method="POST" action="">
<p>Dein Name: <?PHP echo $_SESSION['user_username']; ?></p>
<textarea class="textareacom" name="comment" id="comment" rows="5" cols="20" maxlength="1500" value=""></textarea><br />
<input name="submitcomment" id="submit" type="submit" class="submit" value="Submit" />
</form>
<?PHP
}
}else{
?>
<FORM id="postlogin" action="" method="POST">
<p style="font-weight:bolder;">Um Kommentare schreiben zu können musst du dich zuerst einloggen</p>
<TABLE>
<TR>
<TD align="left"><font face="Arial" color="#000000"><?php echo $lang['REGISTER_USERNAME']; ?></TD>
<TD align="left"><input type="text" name="username"/></TD>
</TR>
<TR>
<TD align="left"><font face="Arial" color="#000000"><?php echo $lang['REGISTER_PASSWORD']; ?></TD>
<TD align="left"><input type="password" name="password"/></TD>
</TR>
<TR>
<TD></TD>
<TD align="left"><input type="submit" id="login" value="login" name="submit" /></TD>
</TR>
</TABLE>
<?php echo $lang['LOGIN_REGISTER']; ?> | <?php echo $lang['FORGOT_PW']; ?>
<BR></BR>
</FORM>
<?PHP
}
?>
</div>
<?php
$sql=mysql_query("select * from topmovies.comments ORDER BY date DESC");
while($row=mysql_fetch_array($sql))
{
$username=$row['username'];
$comment=$row['comment'];
$date=$row['date'];
$name=$row['name'];
?>
<div id="comments" name="comments">
<div class="comments" style="padding-top:5px;">
<BR>
<table width="746px" style="display:inline;" border="0" cellspacing="0" cellpadding="0">
<tr>
<td rowspan="4" valign="top" width="154px" style="padding-right:19px;"><img style="display: block; padding-top:10px;" src="http://img.movie4k.to/img/user_top.gif" height="8px"/>
<span class="test"><?php echo $username; ?><br />
<br />
<font size=1><?PHP echo date("d-m-Y", strtotime($date))?></br>
<?PHP echo date("H:i", strtotime($date))?></font></span>
<img style="display: block; background-color: #AFAFAF; padding-left:10px; padding-right:10px;" src="http://img.movie4k.to/userpics/476090.gif" width=40 height=50/>
<img style="display: block;" src="http://img.movie4k.to/img/user_bottom.gif" height="8px"/></td>
<td colspan="2" valign="bottom" height="8px"><img style="display: block; padding-top:10px;" src="http://img.movie4k.to/img/comment_top2.gif" height="8px"/></td>
</tr>
<tr>
<td rowspan="2" width="522px" class="comment" valign="top" bgcolor="#E3E3E3" style="padding-left:10px; padding-right:17px;">
<?php echo $comment; ?>
</td>
<td width="85px" valign="top" bgcolor="#E3E3E3" style="font-size:19px;">
<div style="min-height:50px;"></div>
</td>
</tr>
<tr>
<td bgcolor="#E3E3E3" valign="bottom"></td>
</tr>
<tr>
<td colspan="2" valign="top" height="8px"><img style="display: block;" src="http://img.movie4k.to/img/comment_bottom2.gif" height="8px"/></td>
</tr>
</table>
</div>
</div>
<BR />
<?php
}
?>
Does anyone see there a mistake what is wrong?
I tryed 1 thing, but then it dont show the echo "comment added!"
After the user submits the form, and after the POST data is read by the php code, you could redir to another page. That could solve it.
if you don't want to do that, you could compare the post with others to see if it has the same content, very close time-stamp, and same user. I wouldn't recommend that though.
Instead of doing
echo'Comment Added!';
You could redirect the user to the same page, thus removing the POST, with a 'flag' which tells the app a comment had just been added.
eg:
header('Location: myPage.php?commentAdded=true'); //myPage is current page
then somewhere else in the page:
if(isset($_GET['commentAdded'])){
echo'Comment Added!';
}
<script type="text/javascript">
$(document).ready(function($) {
$('#searchicon').click(function(){
$('#searchicon.toappear').toggle();
$('#searchicon2.appear').toggle();
$('#extraSearch').slideToggle('fast');
});
$('#searchicon2').click(function(){
$('#searchicon.toappear').toggle();
$('#searchicon2.appear').toggle();
$('#extraSearch').slideToggle('fast');
});
$('input[name=estimate]').click(function(){
if (this.checked) {
$("input.groupestimate").removeAttr("disabled");
} else {
$("input.groupestimate").attr("checked", false);
$("input.groupestimate").attr("disabled", true);
}
});
$("input.groupgatepass").attr("disabled", true);
$('input[name=gatepass]').click(function(){
if (this.checked) {
$("input.groupgatepass").removeAttr("disabled");
} else {
$("input.groupgatepass").attr("checked", false);
$("input.groupgatepass").attr("disabled", true);
}
});
/*
$('input.groupestimate').click(function() {
if(this.checked) {
$form = $('#globalSearch form');
if($('#globalSearch form[ACTION*="'+this.value+'"]'))
var data = new Object();
data.field = this.value;
var dataString = $.toJSON(data);
$.post('json.php',
{data: dataString},
function(res){
var obj = $.evalJSON(res);
$form.attr('ACTION',$form.attr('action')+''+obj.query);
}
);
}
});*/
$('#globalSearch form').submit(function() {
if($('input.groupheader[type=checkbox]:checked').length > 1) {
alert('Please check only Estimate or Gatepass');
return false;
}
var data = new Object();
$('input.groupheader[type=checkbox]:checked').each(function(){
data.header = this.value;
});
data.fields = new Array();
$header = 'input.group'+data.header;
$($header+'[type=checkbox]:checked').each(function(){
data.fields.push(this.value);
});
var dataString = $.toJSON(data);
$.post('json.php',
{data: dataString},
function(res){
var obj = $.evalJSON(res);
$('input[name=query]').val(obj.query);
}
);
alert($('input[name=query]').val()); //alerts nothing or the old value :(
return false;
});
});
</script>
-------------HTML PART-------------------
<form action="?<?php echo http_build_query(cloneGet(array("server-page"=>$GLOBALS["setting"]["current_folder"], "currpage"=>"0","OrderBy"=>"","ByDirect"=>"","search_flg"=>"-1")));?>" method="post" id="" name="">
<div id="extraSearch">
<table class="stripe" width="100%" id="extraTableList">
<tbody>
<tr class="striped">
<th style="cursor:pointer;text-align:left;"><input type="checkbox" name="estimate" value="estimate" checked="checked" class="groupheader">Estimates</th>
<th style="cursor:pointer;text-align:left;"><input type="checkbox" name="gatepass" value="gatepass" class="groupheader">Gatepass</th>
</tr>
<tr>
<td class="int"><input type="checkbox" name="estimate1" value="customer" class="groupestimate">Customer</td>
<td class="int"><input type="checkbox" name="gatepass1" value="old_serial" class="groupgatepass">Old Serial</td>
</tr>
<tr>
<td class="int"><input type="checkbox" name="estimate2" value="serial_no" class="groupestimate">Serial No</td>
<td class="int"><input type="checkbox" name="gatepass2" value="type" class="groupgatepass">Type</td>
</tr>
<tr>
<td class="int"><input type="checkbox" name="estimate3" value="invoice_no" class="groupestimate">Invoice No</td>
<td class="int"><input type="checkbox" name="gatepass3" value="type_id" class="groupgatepass">Type ID</td>
</tr>
<tr>
<td class="int"><input type="checkbox" name="estimate4" value="salesman" class="groupestimate">Salesman</td>
<td class="int"><input type="checkbox" name="gatepass4" value="loader" class="groupgatepass">Loader</td>
</tr>
<tr>
<td class="int"><input type="checkbox" name="estimate5" value="estimate_no" class="groupestimate">Estimate No</td>
<td class="int"><input type="checkbox" name="gatepass5" value="total" class="groupgatepass">Total</td>
</tr>
<tr>
<td class="int"><input type="checkbox" name="estimate6" value="status" class="groupestimate">Status</td>
<td class="int"> </td>
</tr>
</tbody>
</table>
</div>
<img id="searchicon" src="___images/search-arrow.png" class="toappear" alt="Extra search" title="Extra search"/>
<img id="searchicon2" src="___images/search-arrow.png" class="appear" alt="Extra search" title="Extra search"/>
<input type="text" value="<?php echo $_REQUEST['quicksearch'];?>" id="s" name="quicksearch">
<input type="hidden" value="" id="query" name="query" temp="">
<input type="submit" value="Search" id="b">
<?php if( $_REQUEST['quicksearch'] ) { ?>
<a id="c" href="?<?php echo http_build_query(cloneGet(array("quicksearch"=>"","search_flg"=>"-1")));?>">Cancel</a>
<?php } ?>
</form>
As you can see, before it submits the values I want to insert a string into the 'query' input element value attribute. It works perfectly when doing it inside the callback of $.post but after checking it using alert() outside the $.post its empty.
Is $.post always like that?or am I missing something?
when you are using $.post it is making an async request. The reason alert will contain nothing or the old value is because it is triggered before the $.post can complete its request. When the alert is placed inside of the $.post callback it will have the data you want because it is called after the $.post has completed
I am using a contact form and at the moment when you submit your details you are brought to a new page with a "thank you" message. I don't want users to be re-directed to a new page and instead I would like the "thank you" message to be displayed on the same page as the form. The code I am using is below.
Contact form code:
<form name="htmlform" method="post" action="html_form_send.php">
<table width="450px">
</tr>
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
PHP code to send form:
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "you#yourdomain.com";
$email_subject = "website html form submissions";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- place your own success html below -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
die();
?>
If you're wanting to refresh the page to the same location on which the form is located and display the results on the same page, then you could try this:
replace
<form name="htmlform" method="post" action="html_form_send.php">
with the following (so that you refresh the same page as the form).
<form name="htmlform" action="" method="post">
Adjust your submit button by giving it a name:
<input type="submit" name="submit" value="Submit">
and then validate whether the post has been submitted by checking if 'submit is set, rather than email...
if(isset($_POST['submit'])) { rather than if(isset($_POST['email'])) {
Then move the thankyou message code from the file 'html_form_send.php' to above your form code in the original file.
This should POST the data from the form to the same page on which the form is located, and only display the thank you message if the page detects that the form has been submitted... So long as you enclose any printed/echo'd thank you message inside the if(isset($_POST['submit'])) { brackets - i.e. in here } then it should work.
If you want to check if the form has been submitted without refreshing the page you'll need to look in to AJAX, but that is a bit more complicated.
I've been searching a bit for a jquery plugin that could help me to edit an entire form in place without having to write markup for both the form and displaying the data. Where you can just click "edit" and then the form fields would appear instead of the text, and then save and the form fields would turn into text again.
Does anyone know of one?
Here's the plugin in its crudest form:
(function( $ ){
var YesNo = new Array();
YesNo["true"] = "Yes";
YesNo["false"] = "No";
$.fn.inline = function() {
this.each(function(){
if ($(this).is('table')) {
$(this).find('input, select, textarea').not('[type=button],[type=submit]').each(function(){
if($(this).attr("type")=="checkbox"){
$(this).parent().append("<span class=\"editable\">"+YesNo[$(this).attr('checked')]+"</span>");
$(this).hide();
//$(this).append("<span>"+$(this).val()+"</span>");
$(this).bind('blur',function(){
var t = YesNo[$(this).attr('checked')];
$(this).hide().next().show().text(t);
});
}
else{
$(this).parent().append("<span class=\"editable\">"+$(this).val()+"</span>");
$(this).hide();
//$(this).append("<span>"+$(this).val()+"</span>");
$(this).bind('blur',function(){
var t = $(this).val();
$(this).hide().next().show().text(t);
});
}
});
$(this).find('td').live('dblclick', function(){
$(this).children('.editable').hide().prev().show().focus();
});
}
});
};
})( jQuery );
Call to plugin:
<script type="text/javascript">
$().ready(function () {
$('#dataform').inline();
});
</script>
And the supporting example markup:
<table id="dataform">
<tr>
<td class="label">First Name</td>
<td><input type="text" value="Robin" /> </td>
<td class="label">Last Name</td>
<td><input type="text" value="Maben" /> </td>
</tr>
<tr>
<td class="label">City</td>
<td><input type="text" value="Bangalore" /> </td>
<td class="label">Country</td>
<td><input type="checkbox" checked="checked" /> </td>
</tr>
<tr>
<td class="styleLabel">Status</td>
<td class="styleControl">
<select id="Select1" class="styleDrop">
<option>Active</option>
<option>Inavtive</option>
<option>Pending</option>
</select></td>
</tr>
<tr>
<td>Description</td><td><textarea>Hello World</textarea></td>
</tr>
<tr>
<td>
<input type = "button" value="Click" />
<input type = "submit" />
</td>
</tr>
</table>