Contact form - success message - forms

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.

Related

Flutter Webview Form Post

Below is code in PHP for PayU Payment gateway integration. Payment Gateway is opened via a Post form submit and form action is url https://sandboxsecure.payu.in
Using Webview we can redirect to https://sandboxsecure.payu.in. but need to send the data as well.
Can we create similar flow in flutter web?
Possible flow
Flutter Web --- > Submit form and open webview to show PayU Page --> After payment come back to flutter web
note - Hash generation will be done via third party API.
<?php
$MERCHANT_KEY = "";
$SALT = "";
// Merchant Key and Salt as provided by Payu.
$PAYU_BASE_URL = "https://sandboxsecure.payu.in"; // For Sandbox Mode
//$PAYU_BASE_URL = "https://secure.payu.in"; // For Production Mode
$action = '';
$posted = array();
if(!empty($_POST)) {
//print_r($_POST);
foreach($_POST as $key => $value) {
$posted[$key] = $value;
}
}
$formError = 0;
if(empty($posted['txnid'])) {
// Generate random transaction id
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
} else {
$txnid = $posted['txnid'];
}
$hash = '';
// Hash Sequence
$hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
if(empty($posted['hash']) && sizeof($posted) > 0) {
if(
empty($posted['key'])
|| empty($posted['txnid'])
|| empty($posted['amount'])
|| empty($posted['firstname'])
|| empty($posted['email'])
|| empty($posted['phone'])
|| empty($posted['productinfo'])
|| empty($posted['surl'])
|| empty($posted['furl'])
|| empty($posted['service_provider'])
) {
$formError = 1;
} else {
//$posted['productinfo'] = json_encode(json_decode('[{"name":"tutionfee","description":"","value":"500","isRequired":"false"},{"name":"developmentfee","description":"monthly tution fee","value":"1500","isRequired":"false"}]'));
$hashVarsSeq = explode('|', $hashSequence);
$hash_string = '';
foreach($hashVarsSeq as $hash_var) {
$hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : '';
$hash_string .= '|';
}
$hash_string .= $SALT;
$hash = strtolower(hash('sha512', $hash_string));
$action = $PAYU_BASE_URL . '/_payment';
}
} elseif(!empty($posted['hash'])) {
$hash = $posted['hash'];
$action = $PAYU_BASE_URL . '/_payment';
}
?>
<html>
<head>
<script>
var hash = '<?php echo $hash ?>';
function submitPayuForm() {
if(hash == '') {
return;
}
var payuForm = document.forms.payuForm;
payuForm.submit();
}
</script>
</head>
<body onload="submitPayuForm()">
<h2>PayU Form</h2>
<br/>
<?php if($formError) { ?>
<span style="color:red">Please fill all mandatory fields.</span>
<br/>
<br/>
<?php } ?>
<form action="<?php echo $action; ?>" method="post" name="payuForm">
<input type="hidden" name="key" value="<?php echo $MERCHANT_KEY ?>" />
<input type="hidden" name="hash" value="<?php echo $hash ?>"/>
<input type="hidden" name="txnid" value="<?php echo $txnid ?>" />
<table>
<tr>
<td><b>Mandatory Parameters</b></td>
</tr>
<tr>
<td>Amount: </td>
<td><input name="amount" value="<?php echo (empty($posted['amount'])) ? '' : $posted['amount'] ?>" /></td>
<td>First Name: </td>
<td><input name="firstname" id="firstname" value="<?php echo (empty($posted['firstname'])) ? '' : $posted['firstname']; ?>" /></td>
</tr>
<tr>
<td>Email: </td>
<td><input name="email" id="email" value="<?php echo (empty($posted['email'])) ? '' : $posted['email']; ?>" /></td>
<td>Phone: </td>
<td><input name="phone" value="<?php echo (empty($posted['phone'])) ? '' : $posted['phone']; ?>" /></td>
</tr>
<tr>
<td>Product Info: </td>
<td colspan="3"><textarea name="productinfo"><?php echo (empty($posted['productinfo'])) ? '' : $posted['productinfo'] ?></textarea></td>
</tr>
<tr>
<td>Success URI: </td>
<td colspan="3"><input name="surl" value="<?php echo (empty($posted['surl'])) ? '' : $posted['surl'] ?>" size="64" /></td>
</tr>
<tr>
<td>Failure URI: </td>
<td colspan="3"><input name="furl" value="<?php echo (empty($posted['furl'])) ? '' : $posted['furl'] ?>" size="64" /></td>
</tr>
<tr>
<td colspan="3"><input type="hidden" name="service_provider" value="payu_paisa" size="64" /></td>
</tr>
<tr>
<td><b>Optional Parameters</b></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input name="lastname" id="lastname" value="<?php echo (empty($posted['lastname'])) ? '' : $posted['lastname']; ?>" /></td>
<td>Cancel URI: </td>
<td><input name="curl" value="" /></td>
</tr>
<tr>
<td>Address1: </td>
<td><input name="address1" value="<?php echo (empty($posted['address1'])) ? '' : $posted['address1']; ?>" /></td>
<td>Address2: </td>
<td><input name="address2" value="<?php echo (empty($posted['address2'])) ? '' : $posted['address2']; ?>" /></td>
</tr>
<tr>
<td>City: </td>
<td><input name="city" value="<?php echo (empty($posted['city'])) ? '' : $posted['city']; ?>" /></td>
<td>State: </td>
<td><input name="state" value="<?php echo (empty($posted['state'])) ? '' : $posted['state']; ?>" /></td>
</tr>
<tr>
<td>Country: </td>
<td><input name="country" value="<?php echo (empty($posted['country'])) ? '' : $posted['country']; ?>" /></td>
<td>Zipcode: </td>
<td><input name="zipcode" value="<?php echo (empty($posted['zipcode'])) ? '' : $posted['zipcode']; ?>" /></td>
</tr>
<tr>
<td>UDF1: </td>
<td><input name="udf1" value="<?php echo (empty($posted['udf1'])) ? '' : $posted['udf1']; ?>" /></td>
<td>UDF2: </td>
<td><input name="udf2" value="<?php echo (empty($posted['udf2'])) ? '' : $posted['udf2']; ?>" /></td>
</tr>
<tr>
<td>UDF3: </td>
<td><input name="udf3" value="<?php echo (empty($posted['udf3'])) ? '' : $posted['udf3']; ?>" /></td>
<td>UDF4: </td>
<td><input name="udf4" value="<?php echo (empty($posted['udf4'])) ? '' : $posted['udf4']; ?>" /></td>
</tr>
<tr>
<td>UDF5: </td>
<td><input name="udf5" value="<?php echo (empty($posted['udf5'])) ? '' : $posted['udf5']; ?>" /></td>
<td>PG: </td>
<td><input name="pg" value="<?php echo (empty($posted['pg'])) ? '' : $posted['pg']; ?>" /></td>
</tr>
<tr>
<?php if(!$hash) { ?>
<td colspan="4"><input type="submit" value="Submit" /></td>
<?php } ?>
</tr>
</table>
</form>
</body>
</html>
You can use the below package:
https://pub.dev/packages/flutter_inappwebview
InAppWebView(
initialUrlRequest: URLRequest(
url: Uri.parse(targetUrl),
method: 'POST',
body: Uint8List.fromList(utf8.encode("msg=${requestPayload}")),
headers: {
'Content-Type': 'multipart/form-data',
'Referer': ,
'access_token': _,
'Host':'esign.egov-nsdl.com',
'Content-Length': Uint8List.fromList(utf8.encode("msg=${requestPayload}")).length.toString(),
}
),
onWebViewCreated: (controller) {
},
),
This should work with the required modifications..

How to process a form if CAPTCHA is true in ASP

I've almost got the CAPTCHA system working on this particular website. I've used the captcha form from http://www.tipstricks.org. Everything seems to be working except that when I fill out the contact form the values don't get submitted through e-mail. I just get the contact from with all the values missing. I'm not sure how to pass in the values from the form so that it is included in the e-mail. Here is the code on this particular asp page:
<form name="form1" id="form1" method="post" action="send_email.asp" value="<%
If Session("form1") <> "" Then Response.Write(Session("form1"))%>" />
<table border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td>Contact Name</td>
<td width="20" align="center">:</td>
<td><input name="name" type="text" id="name" size="30"></td>
</tr>
<tr>
<td>E-mail Address</td>
<td align="center">:</td>
<td><input name="email" type="text" id="email" size="30"></td>
</tr>
<tr>
<td>Comments</td>
<td align="center">:</td>
<td><input name="comments" type="text" id="comments" size="30"></td>
</tr>
<tr>
<td> </td>
<td align="center"> </td>
</tr>
</table>
<div style="text-align: center; margin-top: 20px;">
<%
if Request.ServerVariables("REQUEST_METHOD") = "POST" and IsEmpty(Request.Form("btnRetry")) then
Dim lblResult, lblColor
if IsEmpty(Session("ASPCAPTCHA")) or Trim(Session("ASPCAPTCHA")) = "" then
lblResult = "This test has expired."
lblColor = "red"
else
Dim TestValue : TestValue = Trim(Request.Form("txtCaptcha"))
'//Uppercase fix for turkish charset//
TestValue = Replace(TestValue, "i", "I", 1, -1, 1)
TestValue = Replace(TestValue, "İ", "I", 1, -1, 1)
TestValue = Replace(TestValue, "ı", "I", 1, -1, 1)
'////////////////////
TestValue = UCase(TestValue)
if StrComp(TestValue, Trim(Session("ASPCAPTCHA")), 1) = 0 then
lblResult = "CAPTCHA PASSED"
lblColor = "green"
Session("form1") = Request.Form("form1")
response.redirect "send_email.asp"
else
lblResult = "CAPTCHA FAILED"
lblColor = "red"
end if
'//IMPORTANT: You must remove session value for security after the CAPTCHA test//
Session("ASPCAPTCHA") = vbNullString
Session.Contents.Remove("ASPCAPTCHA")
'////////////////////
end if
%>
<p><span style="color: <%=lblColor%>; font-weight: bold;"><%=lblResult%></span></p>
<input type="submit" name="btnRetry" id="btnRetry" value="Take another test" />
<%else%>
<img src="captcha.asp" id="imgCaptcha" /> Get a new challenge<br />
Write the characters in the image above<br />
<input type="text" name="txtCaptcha" id="txtCaptcha" value="" /><br />
<input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" />
<%end if%>
</form>
Any help would be greatly appreciated.

show the "add another" button when the form is successfully send using codeigniter

i have this form called news and events, I want that when the form is successfully saved, the table form will hide then the add another button will appear. Im using session set userdata so that when the form is successfully saved the add another button will appear then the table form will hide. my code runs well but the problem is, after it successfully send the add another button will not work here's my controller below
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start();
class News_and_events extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->library('form_validation');
$this->load->model('admin_model', 'am');
}
public function index(){
if($this->session->userdata('logged_in')){
$this->data['title'] = 'News and Events | Spring Rain Global Consultancy Inc Admin Panel';
$this->data['logout'] = 'Logout';
$session_data = $this->session->userdata('logged_in');
$this->data['id'] = $session_data['id'];
$this->data['username'] = $session_data['username'];
$this->data['allData'] = $this->am->getAllData();
$this->load->view('pages/admin_header', $this->data);
$this->load->view('content/news_and_events', $this->data);
$this->load->view('pages/admin_footer');
}else{
redirect('login', 'refresh');
}
}
public function add(){
if($this->session->userdata('logged_in')){
$this->form_validation->set_rules('date', 'Date', 'trim|required|xss_clean');
$this->form_validation->set_rules('event', 'Event', 'trim|required|xss_clean');
$this->form_validation->set_rules('description', 'Description', 'trim|required|xss_clean');
if($this->form_validation->run() == FALSE){
$this->data['title'] = 'News and Events | Spring Rain Global Consultancy Inc Admin Panel';
$this->data['logout'] = 'Logout';
$session_data = $this->session->userdata('logged_in');
$this->data['id'] = $session_data['id'];
$this->data['username'] = $session_data['username'];
$this->data['allData'] = $this->am->getAllData();
$this->load->view('pages/admin_header', $this->data);
$this->load->view('content/news_and_events', $this->data);
$this->load->view('pages/admin_footer');
}else{
$array = array(
'Date' => $this->input->post('date'),
'Event' => $this->input->post('event'),
'Description' => $this->input->post('description')
);
$this->am->saveData($array);
$this->session->set_userdata('add_another', $array);
redirect('news_and_events', 'refresh');
}
}else{
redirect('homepage', 'refresh');
}
}
}
and my views
<div class="container" >
<br />
<br />
<br />
<ul id="nav">
<li><h4>Home</h4></li>
<li><h4>News and Events</h4></li>
<li><h4>Activities</h4></li>
</ul>
<div class="starter-template">
<h1>News And Events</h1>
<?php if($this->session->set_userdata('add_another')):?>
<div id="add_another" style="float:left;">
<input type="button" value="Add Another" class="btn btn-primary" />
</div>
<?php else: ?>
<form action="<?php echo base_url().'news-and-events/add'?>" method="post">
<?php echo validation_errors('<div class="error">', '</div>');?>
<table class="table-striped">
<tr>
<td>Date: </td>
<td><input type="text" id="datepicker" name="date" value="<?php echo set_value('date');?>" /></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td >Event: </td>
<td ><input type="text" name="event" value="<?php echo set_value('event');?>" /></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td width="20%">Description: </td>
<td><textarea cols="30" rows="5" name="description" ><?php echo set_value('description');?></textarea></td>
</tr>
<tr>
<td width="20%"> </td>
<td><input type="submit" value="Add" class="btn btn-success" /></td>
</tr>
</table>
</form>
<?php endif; ?>
<br />
<br />
<table class="table" >
<tr>
<th>Date</th>
<th width="51%">Event</th>
<th>Description</th>
<th>Options</th>
</tr>
<?php foreach($allData as $allData): ?>
<tr>
<td><?php echo $allData->Date; ?></td>
<td><?php echo $allData->Event; ?></td>
<td></td>
<td></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div><!-- /.container -->
<script>
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#datepicker').datepicker({
minDate: new Date(currentYear, currentMonth, currentDate),
dateFormat: "yy-mm-dd"
});
</script>
in my views file ive added there the if else statement $this->session->set_userdata('add') just below the h1 tag which is news and events this will trigger the statement when the form is successfully saved!
can someone help me figured this out? or how to do this correctly?
any help is much appreciated! thanks!
istead of this line
<?php if($this->session->set_userdata('add_another')):?>
use this
<?php if($this->session->userdata('add_another')):?>
and in your controller before loading the view add this line
$this->session->set_userdata('add_another',1);

Block submit after reload page

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!';
}

Contact form cannot work well on specific email

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>