Paypal form submitting USD instead of GBP - php

On my website, when you fill out the donation form at the bottom of the page and click 'Make Donation', you are directed to PayPal and greeted with the following error message:
This recipient does not accept payments denominated in USD. Please contact the seller and ask him to update his payment receiving preferences to accept this currency.
So it seems my website is trying to submit the donation amount in USD and it should be submitting it in GBP... From the code I have, I can't see anything that relates to USD, I see this in code for the donate form:
<div id="donate_form" style="width:465px; text-align:right; margin-left:auto; margin-right:auto;">
<form action="https://www.paypal.com/cgi-bin/webscr" target="_self" method="post" name="form1" id="form1">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="office#lifechurch.org.uk">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="item_name" value="CLC">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="rm" value="1">
<input type="hidden" name="return" value="http://www.lifechurchgive.org.uk/thanks.php">
<input type="hidden" name="cancel_return" value="http://www.lifechurchgive.org.uk/cancel.php">
<input type="hidden" name="currency_code" value="GBP">
<!--<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----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-----END PKCS7-----">-->
<span id="ajaxresult" name="ajaxresult"><?PHP include("validate.php"); ?></span>
<?PHP
#$ajax = "loadXMLDoc('/validate.php','ajaxresult','submit2','displaydonation=true&title1='+title1.value+'&first_name='+first_name.value+'&last_name='+last_name.value+'&H_PhoneNumber='+H_PhoneNumber.value+'&email='+email.value+'&amount='+amount.value+'&message='+message.value);document.getElementById('submit2').disabled=true;cursor_wait();";
$ajax = "loadXMLDoc('/validate.php','ajaxresult','submit2','displaydonation=true&title1='+title1.value+'&first_name='+first_name.value+'&last_name='+last_name.value+'&email='+email.value+'&amount='+amount.value+'&message='+message.value+'&giftaid='+giftaid.checked);document.getElementById('submit2').disabled=true;cursor_wait();";
echo '<br /><div class="submitbutton">'.make_form_var('input','button','submit2','submit2','Make Donation','','','','','','','','','',$ajax).'</div>';
?>
</form>
<!--
<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="PayPal - The safer, easier way to pay online!" /> -->
</div><!-- end of donate_form -->
It does have a lot thats commented out.
I have a validate.php file, but I don't see anything about currency / GBP / USD in there so there must be something that sets it to USD but doesn't use those terms perhaps?
I'll actually post the code thats in the validation.php file sorry about the length...
<?PHP
ini_set( 'display_errors', 0 );
date_default_timezone_set('Europe/London');
#session_start();
function make_form_var($formvar='',$type='',$name='',$id='',$value='',$size='',$maxlength='',$checked='',$src='',$rows='',$columns='',$class='',$title='',$align='',$onclick='',$onblur='') {
if ($formvar == '') { return; }
$object = '<'.$formvar.' '; # 1
if ($type != '') { $object.= 'type="'.$type.'" '; } # 2
if ($name != '') { $object.= 'name="'.$name.'" '; } # 3
if ($id != '') { $object.= 'id="'.$id.'" '; } # 4
if ($value != '') { $object.= 'value="'.$value.'" '; } # 5
if ($size != '') { $object.= 'size="'.$size.'" '; } # 6
if ($maxlength != '') { $object.= 'maxlength="'.$maxlength.'" '; } # 7
if ($checked != '') { $object.= 'checked="'.$checked.'" '; } # 8
if ($src != '') { $object.= 'src="'.$src.'" '; } # 9
if ($rows != '') { $object.= 'rows="'.$rows.'" '; } # 10
if ($columns != '') { $object.= 'cols="'.$columns.'" '; } # 11
if ($class != '') { $object.= 'class="'.$class.'" '; } # 12
if ($title != '') { $object.= 'title="'.$title.'" '; } # 13
if ($align != '') { $object.= 'align="'.$align.'" '; } # 14
if ($onclick != '') { $object.= 'onclick="'.$onclick.'" '; } # 15
if ($onblur != '') { $object.= 'onblur="'.$onblur.'" '; } # 16
if ($formvar == 'textarea') {
$object.='>'.$value.'</'.$formvar.'>';
} else {
$object.=' />';
}
return $object;
}
function valid_email($email)
{
// check an email address is valid
if (preg_match('/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+#([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/', $email))
return true;
else
return false;
}
$newarray = $_POST;
if ($_SERVER['PHP_SELF'] == '/index.php' || isset($_POST['displaydonation'])) {
# place values on the session
if (isset($newarray['title1'])) {
$_SESSION['DONATION']->title1 = $newarray['title1'];
} else {
if (!isset($_SESSION['DONATION']->title1)) { $_SESSION['DONATION']->title1 = ''; }
}
if (isset($newarray['first_name'])) {
$_SESSION['DONATION']->first_name = $newarray['first_name'];
} else {
if (!isset($_SESSION['DONATION']->first_name)) { $_SESSION['DONATION']->first_name = ''; }
}
if (isset($newarray['last_name'])) {
$_SESSION['DONATION']->last_name = $newarray['last_name'];
} else {
if (!isset($_SESSION['DONATION']->last_name)) { $_SESSION['DONATION']->last_name = ''; }
}
if (isset($newarray['email'])) {
$_SESSION['DONATION']->email = $newarray['email'];
} else {
if (!isset($_SESSION['DONATION']->email)) { $_SESSION['DONATION']->email = ''; }
}
if (isset($newarray['amount'])) {
$_SESSION['DONATION']->amount = $newarray['amount'];
} else {
if (!isset($_SESSION['DONATION']->amount)) { $_SESSION['DONATION']->amount = '0.00'; }
}
if (isset($newarray['message'])) {
$_SESSION['DONATION']->message = $newarray['message'];
} else {
if (!isset($_SESSION['DONATION']->message)) { $_SESSION['DONATION']->message = ''; }
}
if (isset($newarray['giftaid'])) {
if ($newarray['giftaid'] == 'true') { $newarray['giftaid'] = 1; } else { $newarray['giftaid'] == 0; }
$_SESSION['DONATION']->giftaid = $newarray['giftaid'];
} else {
if (!isset($_SESSION['DONATION']->giftaid)) { $_SESSION['DONATION']->giftaid = '1'; }
}
$emailvalid = ''; $emailvalid = valid_email($_SESSION['DONATION']->email);
if (isset($_POST['displaydonation']) && $_SESSION['DONATION']->first_name != '' && $_SESSION['DONATION']->last_name != '' && $_SESSION['DONATION']->email != '' && $emailvalid != false && $_SESSION['DONATION']->amount != '' && $_SESSION['DONATION']->amount >= 5.00) {
# email details
$subject = "Website Donation";
$body = $body."The following donation was started on ".date('l dS F').". The user was forwarded to paypal to complete the transaction.\n\n";
$body = $body."Contact Name: ".$_SESSION['DONATION']->title." ".$_SESSION['DONATION']->first_name." ".$_SESSION['DONATION']->last_name."\n\n";
$body = $body."Email: ".$_SESSION['DONATION']->email."\n\n";
$body = $body."Amount: ".$_SESSION['DONATION']->amount."\n\n";
if ( $_SESSION['DONATION']->message != '') { $body = $body."Message: ".$_SESSION['DONATION']->message."\n\n"; }
if ( $_SESSION['DONATION']->giftaid == '1') { $body = $body."Gift aid: Yes\n\n"; }
$to = "office#lifechurch.org.uk";
$from = $_SESSION['DONATION']->email;
$headers = 'From: ' . $from . "\n";
$headers .= 'Return-Path: ' . $from . "\n";
$headers .= 'BCC: gavin.lloyd#sky.com'."\n";
$headers .= 'BCC:'."\n";
$headers .= 'MIME-Version: 1.0' ."\n";
$headers .= 'Content-Type: text/plain; charset=ISO-8859-1' ."\n";
$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\n";
$mailOk=mail($to, $subject, $body, $headers);
# forward form to paypal
echo 'submitform';
} else {
echo '<div class="formlabel">Title: </div>';
echo '<div class="formobject">';
echo make_form_var('input','text','title1','title1',$_SESSION['DONATION']->title1,'5','6','','','','','paypaltextbox');
echo '</div>';
echo '<div class="formclear"></div>';
if (isset($_POST['displaydonation']) && $_SESSION['DONATION']->first_name == '') {
echo '<div class="error">Please enter your first name:</div>';
}
echo '<div class="formlabel"><span class="requiredtext">First name:* </span></div>';
echo '<div class="formobject">';
echo make_form_var('input','text','first_name','first_name',$_SESSION['DONATION']->first_name,'26','100','','','','','paypaltextbox');
echo '</div>';
echo '<div class="formclear"></div>';
if (isset($_POST['displaydonation']) && $_SESSION['DONATION']->last_name == '') {
echo '<div class="error">Please enter your last name:</div>';
}
echo '<div class="formlabel"><span class="requiredtext">Last name:* </span></div>';
echo '<div class="formobject">';
echo make_form_var('input','text','last_name','last_name',$_SESSION['DONATION']->last_name,'26','100','','','','','paypaltextbox');
echo '</div>';
echo '<div class="formclear"></div>';
if (isset($_POST['displaydonation']) && $_SESSION['DONATION']->email == '') {
echo '<div class="error">Please enter your email:</div>';
} else if (isset($_POST['displaydonation']) && $emailvalid == false) {
echo '<div class="error">Please enter a valid email address:</div>';
}
echo '<div class="formlabel"><span class="requiredtext">Email:* </span></div>';
echo '<div class="formobject">';
echo make_form_var('input','text','email','email',$_SESSION['DONATION']->email,'26','100','','','','','paypaltextbox');
echo '</div>';
echo '<div class="formclear"></div>';
if (isset($_POST['displaydonation']) && $_SESSION['DONATION']->amount == '') {
echo '<div class="error">Please enter a donation:</div>';
} else if (isset($_POST['displaydonation']) && $_SESSION['DONATION']->amount < 5.00) {
echo '<div class="error">Please enter a donation of £5.00 or more:</div>';
}
echo '<div class="formlabel"><span class="requiredtext">Donation:* </span></div>';
echo '<div class="formobject">';
echo make_form_var('input','text','amount','amount',$_SESSION['DONATION']->amount,'6','16','','','','','paypaltextboxcost','','right','','MM_changeProp(\'amount\',\'\',\'value\',cent(this.value),\'INPUT/TEXT\')');
echo ' (minimum £5.00)</div>';
echo '<div class="formclear"></div>';
echo '<div class="formlabel">Message: </div>';
echo '<div class="formobject">';
echo make_form_var('textarea','','message','message',$_SESSION['DONATION']->message,'','','','','5','','paypaltextbox');
echo '</div>';
echo '<div class="formclear"></div>';
echo '<div class="formlabel">Gift aid: </div>';
echo '<div class="formobject">';
$checked='';
if ($_SESSION['DONATION']->giftaid == 1) { $checked = 'checked'; }
echo make_form_var('input','checkbox','giftaid','giftaid','1','','',$checked,'','','','');
echo '</div>';
echo '<div class="formclear"><br /><p class="donate_small">I am a UK taxpayer. Please treat the gift I have made to Chesterfield Christian Life Church (CLC) as a Gift Aid Donation. I understand CLC will reclaim income tax at the basic rate on my donations and I must pay an amount of income tax or capital gains tax equal to the amount that will be reclaimed. IE - You are confirming that you are a UK tax payer and that you are happy for us to reclaim the tax - for every £1 you give to CLC we can reclaim 25p from the tax man - which is pretty cool. All donations qualify - large or small, regular or one-off, and whatever the method of payment. </p></div>';
}
}
Can anyone tell me what I should be looking for?

Related

Change "FROM" mailadress in a function

I installed a plugin called Message 2 Auther and its doing the job that i request. But, i dont want the "FROM" adress to be the Wordpress default mail, i want it to be from the user that wrote the message.
I've changed so that the subject is what i want it to be, but i dont know where to find the default mail.
Here is the code:
<?php defined('ABSPATH') or die('No script kiddies please!'); ?>
<?php
function m2a_getMessageBoxHTML() {
$messagebox = '<script src="https://www.google.com/recaptcha/api.js">
</script><form class="form" method="post" action="' .
esc_url(admin_url('admin-post.php')) . '"><input style="margin-bottom:15px;"
type="text" name="subject" placeholder="Subject">';
if (!is_user_logged_in()) {
$messagebox .= '<input style="margin-bottom:15px;" type="email"
name="user_email" placeholder="Email">';
}
$messagebox .= '<textarea style="margin-bottom:15px;" name="message"
placeholder="Message"></textarea>
<input type="hidden" name="action" value="m2a_new_message"
/>
<input type="hidden" name="post_id" value="' . get_the_ID()
. '" />';
$options = get_option('m2a_setting');
if ($options['googlecaptcha'] && $options['googlecaptchapublickey']) {
$messagebox .= '<div class="g-recaptcha" data-sitekey="' .
$options['googlecaptchapublickey'] . '"></div>';
}
$messagebox .= '<input type="submit" class="button btn"
name="submit_message" value="submit" />
</form>';
return $messagebox;
}
function m2a_getPopupHTML() {
add_thickbox();
$messagebox = '<div id = "my-content-id" style = "display:none;">
<form class = "form" method = "post" action = "' . esc_url(admin_url('admin-
post.php')) . '" style = "text-align:center;">';
if (!is_user_logged_in()) {
$messagebox .= '<p class="mail_rubrik">Mail:</p><input
class="ruta_rubrik" style = "margin-bottom:15px;" type = "email" name =
"user_email" placeholder = ""><br/><br/>';
}
$messagebox .= '<p class="meddelande_text">Meddelande:</p><textarea
class="meddelande_ruta" style = "margin-bottom:15px;" name = "message"
placeholder = "" rows = "5"></textarea>
<input type = "hidden" name = "action" value = "m2a_new_message" />
<input type = "hidden" name = "post_id" value = "' . get_the_ID() . '" />';
$options = get_option('m2a_setting');
if ($options['googlecaptcha']) {
$messagebox .= '<div class="g-recaptcha" data-sitekey="' .
$options['googlecaptchapublickey'] . '"></div>';
}
$messagebox .= '<br/><br/><input type = "submit" class = "button btn" name =
"submit_message" value = "Skicka" />
</form></div>
<a href = "#TB_inline?width=auto&height=auto&inlineId=my-content-id" class =
"thickbox btn button">Skicka ett meddelande</a>';
return $messagebox;
}
function m2a_sendemail($to, $subject, $message, $usermail = 0, $post_id) {
$post_title = get_the_title($post_id);
$site_name = get_bloginfo('url');
if ($type == 'author') {
$message = "Du har ett nytt meddelande från {$usermail}<br/>Meddelande:
{$message} </a>";
} else {
$message = "Du har ett nytt meddelande från {$usermail}<br/>Meddelande:
{$message}<br/></a>";
}
$subject = "Nytt meddelande på 4 Happy Pets";
wp_mail($to, $subject, $message, array('Content-Type: text/html;
charset=UTF-8'));
}
function m2a_aftercontent() {
$m2a_setting = get_option('m2a_setting');
if (isset($m2a_setting['aftercontent']) && $m2a_setting['aftercontent'] ==
1) {
if ((!isset($m2a_setting['nonuser'])) || ($m2a_setting['nonuser'] == 1
&& is_user_logged_in())) {
function m2a_messagebox($content) {
$m2a_setting = get_option('m2a_setting');
if (is_single()) {
if ($m2a_setting['showas'] == 'messagebox')
return $content . m2a_getMessageBoxHTML();
else
return $content . m2a_getPopupHTML();
}
}
add_filter('the_content', 'm2a_messagebox');
}
}
}
add_action('init', 'm2a_aftercontent');
/*
* Saving Data to database
*/
function m2a_message_db_store() {
global $wpdb;
// global $post;
$postid = $_REQUEST['post_id'];
$authorid = get_post_field('post_author', $postid);
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$options = get_option('m2a_setting');
if ($options['googlecaptcha']) {
$captcha = $_REQUEST['g-recaptcha-response'];
$response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$options['googlecaptchasecretkey']."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
if ($response['success'] == false) {
wp_safe_redirect(wp_get_referer());
}
}
if (!is_user_logged_in()) {
$userid = $_REQUEST['user_email'];
$usermail = $userid;
} else {
$userid = get_current_user_id();
$usermail = get_userdata($userid)->user_email;
}
$tableName = $wpdb->prefix . 'm2a_message';
$wpdb->insert($tableName, array('user_id' => $userid, 'author_id' =>
$authorid, 'post_id' => $postid, 'subject' => $subject, 'message' =>
$message));
$options = get_option('m2a_setting');
if (isset($options['emailtoauthor']) && $options['emailtoauthor'] == 1)
{
$to = get_userdata($authorid)->user_email;
m2a_sendemail($to, $subject, $message, $usermail, $postid);
}
if (isset($options['emailtouser']) && $options['emailtouser'] == 1) {
m2a_sendemail($usermail, $subject, $message, 0, $postid);
}
wp_safe_redirect(wp_get_referer());
}
add_action('admin_post_nopriv_m2a_new_message', 'm2a_message_db_store');
add_action('admin_post_m2a_new_message', 'm2a_message_db_store');
// Create shortcode
function messagebox($atts = array()) {
$a = get_option('m2a_setting');
$atts = shortcode_atts(array(
'style' => 'default',
), $atts, 'message2author');
if ((!isset($a['nonuser'])) || ($a['nonuser'] == 1 &&
is_user_logged_in())) {
if ($atts['style'] == 'messagebox') {
return m2a_getMessageBoxHTML();
} elseif ($atts['style'] == 'popup') {
return m2a_getPopupHTML();
} elseif ($atts['style'] == 'default') {
if ($a['showas'] == 'messagebox') {
return m2a_getMessageBoxHTML();
} elseif ($a['showas'] == 'popup') {
return m2a_getPopupHTML();
}
}
}
}
add_shortcode('message2author', 'messagebox');
?>

How to debug a form that is not saving data? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have made a signup page in PHP, I've made it ask for a name, username, email, password (and confirm), gender and country. I can make it all go through except the first and last name, which are not posting to my database.
I think it won't post to the database because the names are not going through. I have tried a lot and I'm now completely stuck. I've tried google, youtube etc and I can't find anything.
<?php
session_start();
include_once("php_includes/check_login_status.php");
if($user_ok == true){
header("location: profile.php?u=".$_SESSION["username"]);
exit();
}
?>
<?php
// Ajax calls this NAME CHECK code to execute
if(isset($_POST["usernamecheck"])){
include_once("php_includes/db_connect.php");
$username = preg_replace('#[^a-z0-9]#i', '', $_POST['usernamecheck']);
$sql = "SELECT id FROM users WHERE username='$username' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$uname_check = mysqli_num_rows($query);
if (strlen($username) < 3 || strlen($username) > 16) {
echo '<strong style="color:#FFF;">3 - 16 characters please</strong>';
exit();
}
if (is_numeric($username[0])) {
echo '<strong style="color:#F00;">Usernames must begin with a letter</strong>';
exit();
}
if ($uname_check < 1) {
echo '<strong style="color:#009900;">' . $username . ' is OK</strong>';
exit();
} else {
echo '<strong style="color:#F00;">' . $username . ' is taken</strong>';
exit();
}
}
?>
<?php
// Ajax calls this REGISTRATION code to execute
if(isset($_POST["u"])){
// CONNECT TO THE DATABASE
include_once("php_includes/db_connect.php");
// GATHER THE POSTED DATA INTO LOCAL VARIABLES\
$f = $_POST['firstname'];
$l = $_POST['lastname'];
$u = preg_replace('#[^a-z0-9]#i', '', $_POST['u']);
$e = mysqli_real_escape_string($db_conx, $_POST['e']);
$p = $_POST['p'];
$g = preg_replace('#[^a-z]#', '', $_POST['g']);
$c = preg_replace('#[^a-z ]#i', '', $_POST['c']);
// GET USER IP ADDRESS
$ip = preg_replace('#[^0-9.]#', '', getenv('REMOTE_ADDR'));
// DUPLICATE DATA CHECKS FOR USERNAME AND EMAIL
$sql = "SELECT id FROM users WHERE username='$u' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$u_check = mysqli_num_rows($query);
// -------------------------------------------
$sql = "SELECT id FROM users WHERE email='$e' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$e_check = mysqli_num_rows($query);
// FORM DATA ERROR HANDLING
if($f = "" || $l = "" || $u == "" || $e == "" || $p == "" || $g == "" || $c == ""){
echo "The form submission is missing values.";
exit();
} else if ($u_check > 0){
echo "The username you entered is alreay taken";
exit();
} else if (strlen($u) < 3 || strlen($u) > 16) {
echo "Username must be between 3 and 16 characters";
exit();
} else if (is_numeric($u[0])) {
echo 'Username cannot begin with a number';
exit();
} else if (strlen($p) < 8) {
echo 'Your password must be 8 characters';
exit();
} else if ($e_check > 0){
echo "That email address is already in use in the system";
exit();
} else {
// END FORM DATA ERROR HANDLING
// Begin Insertion of data into the database
// Hash the password and apply your own mysterious unique salt
$p_md5 = md5($p);
$p_hash = hash('sha512', $p_md5);
// Add user info into the database table for the main site table
$sql = "INSERT INTO users (firstname, lastname, username, email, password, gender, country, ip, signup, lastlogin, notescheck)
VALUES('$f', '$l', '$u','$e','$p_hash','$g','$c,'$ip',now(),now(),now())";
$query = mysqli_query($db_conx, $sql);
$uid = mysqli_insert_id($db_conx);
if(!$query) {
echo "DB1, FAIL<br>";
} else {
echo "DB1, Success<br>";
}
// Establish their row in the useroptions table
$sql = 'INSERT INTO useroptions (id, username, background)
VALUES ("$uid", "$u", "original")';
$query = mysqli_query($db_conx, $sql);
if(!$query) {
echo "DB2, FAIL<br>";
} else {
echo "DB2, Success<br>";
}
// Establish their row in the links table
$url = "www.elefind.x10.bz/profile.php?u=$u";
$sql = "INSERT INTO links (link_id, site_id, url, title, subtitle, description, fulltxt, indexdate, size, md5sum, visible, level)
VALUES('', '', '$url', '$u', '$f $l', '', now(), '', '', '', '')";
$query = mysqli_query($db_conx, $sql);
if(!$query) {
echo "DB3, FAIL<br>";
} else {
echo "DB2, Success<br>";
}
echo "Fname: ".$f."<br>";
echo "Lname: ".$l."<br>";
echo "Uname: ".$u."<br>";
echo "pwd: ".$p_hash."<br>";
echo "Gender: ".$g."<br>";
echo "Country: ".$c."<br>";
echo "ip: ".$ip."<br>";
// Create directory(folder) to hold each user's files(pics, MP3s, etc.)
if (!file_exists("user/")) {
mkdir("user/", 0755);
echo "User folder created.<br>";
}
if (!file_exists("user/$u")) {
mkdir("user/$u", 0755);
echo "profile folder created.<br>";
}
// Email the user their activation link
$to = "$e";
$from = "noreply#elefind.x10.bz";
$subject = 'Elefind Account Activation';
$message = ' <!DOCTYPE html>';
$message .= ' <html>';
$message .= ' <head>';
$message .= ' <meta charset="UTF-8">';
$message .= ' <title>Elefind Message</title>';
$message .= ' </head>';
$message .= ' <body style="margin:0px; font-family:Tahoma, Geneva, sans-serif;">';
$message .= ' <table style="background:#343642;padding:40px;border:1px solid #DDD;margin:0 auto;font-family:calibri;">';
$message .= ' <tr>';
$message .= ' <td>';
$message .= ' <table style="background:#505260;width:100%;border:1px solid #CCC;padding:0;margin:0;border-collapse:collapse;max-width:100%;width:550px;border-radius:10px;">';
$message .= ' <!-- Logo -->';
$message .= ' <tr>';
$message .= ' <td style="padding:10px 30px;text-align:center;margin:0">';
$message .= ' <p>';
$message .= ' <img src="http://www.elefind.x10.bz/img/logo.png" width="100">';
$message .= ' </p>';
$message .= ' </td>';
$message .= ' </tr>';
$message .= ' <!-- Welcome Salutation -->';
$message .= ' <tr>';
$message .= ' <td style="padding:10px 30px;margin:0;font-size:2.5em;color:#4A7BA5;text-align:center;">';
$message .= ' Welcome to Elefind!';
$message .= ' </td>';
$message .= ' </tr>';
$message .= ' <!-- User Msg -->';
$message .= ' <tr>';
$message .= ' <td style="padding:10px 30px;margin:0;text-align:left;color:FFF;">';
$message .= ' <p>Hey there '.$u.',</p>';
$message .= ' <p>To activate your profile please follow link on the below link,</p>';
$message .= ' </td>';
$message .= ' </tr>';
$message .= ' <!-- Link Button -->';
$message .= ' <tr>';
$message .= ' <td style="padding:10px 30px;text-align:center;">';
$message .= ' <a href="http://elefind.x10.bz/activation.php?id='.$uid.'&u='.$u.'&e='.$e.'&p='.$p_hash.'" title="Activate Profile">';
$message .= ' <img src="http://elefind.x10.bz/img/activate.png" width="300" height="auto">';
$message .= ' </img>';
$message .= ' </a>';
$message .= ' </td>';
$message .= ' </tr>';
$message .= ' <!-- Seperator -->';
$message .= ' <tr>';
$message .= ' <td style="padding:10px 30px;">';
$message .= ' </td>';
$message .= ' </tr>';
$message .= ' <!-- Footer Content -->';
$message .= ' <tr>';
$message .= ' <td style="padding:10px 30px;margin:0;background:#555;color:#CCC;border-top:1px solid #CCC;">';
$message .= ' <p>Once your account is active you can sign in with your email adress.</p>';
$message .= ' <p>Didn\'t request this? If you didn\'t request a to make an account with us, please let us know.</p>';
$message .= ' <p>This email is sent from an unmonitored address. Please do not reply.<!-- Please use links inline to get additional information or help.--></p>';
$message .= ' <!--<p>If you no longer wish to receive these emails, click here to Unsubscribe</p>-->';
$message .= ' </td>';
$message .= ' </tr>';
$message .= ' </table>';
$message .= ' <!-- Some more content -->';
$message .= ' <tr>';
$message .= ' <td style="padding:10px 30px;margin:0;font-size:10px;">';
$message .= ' <p> Click on the link above to activate your account, If the button does not work please use the following link,</br>';
$message .= ' <a href="http://elefind.x10.bz/activation.php?id='.$uid.'&u='.$u.'&e='.$e.'&p='.$p_hash.'">';
$message .= ' http://elefind.x10.bz/activation.php?id='.$uid.'&u='.$u.'&e='.$e.'&p='.$p_hash;
$message .= ' </a>';
$message .= ' </p>';
$message .= ' </td>';
$message .= ' </tr>';
$message .= ' </td>';
$message .= ' </tr>';
$message .= ' </table>';
$message .= ' </body>';
$message .= ' </html>';
$headers = "From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
mail($to, $subject, $message, $headers);
echo "ACCOUNT_CREATED_SUCCESSFULLY";
exit();
}
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<head name="Default">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<meta charset="UTF-8">
<title>Sign Up</title>
</head>
<head name="CSS">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="css/pages/signup.css">
<link rel="stylesheet" href="css/header.css">
<link rel="stylesheet" href="css/footer.css">
<link rel="stylesheet" href="css/fonts.css">
</head>
<head name="JS">
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="js/pages/signup.js"></script>
<script src="js/header.js"></script>
<script src="js/main.js"></script>
<script src="js/ajax.js"></script>
<script>
$('.send').click(function(e){
$(".send").addClass("sending");
})
function restrict(elem){
var tf = document.getElementById(elem);
var rx = new RegExp;
if(elem == "email"){
rx = /[' "]/gi;
} else if(elem == "username"){
rx = /[^a-z0-9]/gi;
} else if(elem == "name"){
rx = /[^a-z]/gi;
} else if(elem == "name"){
rx = /[^a-z]/gi;
}
tf.value = tf.value.replace(rx, "");
}
function emptyElement(x){
document.getElementById(x).innerHTML = "";
}
function checkusername(){
var u = document.getElementById("username").value;
if(u != ""){
document.getElementById("unamestatus").innerHTML = 'checking ...';
var ajax = ajaxObj("POST", "signup.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
document.getElementById("unamestatus").innerHTML = ajax.responseText;
}
}
ajax.send("usernamecheck="+u);
}
}
function signup(){
var fn = document.getElementById("firstname").value;
var ln = document.getElementById("lastname").value;
var u = document.getElementById("username").value;
var e = document.getElementById("email").value;
var p1 = document.getElementById("pass1").value;
var p2 = document.getElementById("pass2").value;
var c = document.getElementById("country").value;
var g = document.getElementById("gender").value;
var status = document.getElementById("status");
if(fn == "" || ln == ""|| u == "" || e == "" || p1 == "" || p2 == "" || c == "" || g == ""){
status.innerHTML = "Some of the form data is missing, Please fill it all out.<br>first name: "+fn+"<br>Last name: "+ln;
$(".send").removeClass("sending");
} else if(p1 != p2){
status.innerHTML = "Your password fields do not match";
$(".send").removeClass("sending");
} else {
var ajax = ajaxObj("POST", "signup.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText != "ACCOUNT_CREATED_SUCCESSFULLY"){
status.innerHTML = ajax.responseText;
$(".send").removeClass("sending");
} else {
window.scrollTo(0,0);
$(".send").removeClass("sending");
document.getElementById("signupform").innerHTML = "OK "+u+", check your email inbox and junk mail box at <u>"+e+"</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account. <br><br>fname: "+fn+"<br>lname: "+ln+"<br> username: "+u+"<br>email: "+e+"<br>password: "+p1+ "<br><br>Correct?";
}
}
}
ajax.send("fn="+fn+"&ln="+ln+"&u="+u+"&e="+e+"&p="+p1+"&c="+c+"&g="+g);
}
}
</script>
</head>
</head>
<body>
<?php include_once("header.php"); ?>
<div class="content">
<div class="cont">
<form name="signupform" id="signupform" action="signup()">
<div class="demo">
<div class="signup">
<div class="signup__check"></div>
<div class="signup__form">
<div class="signup__row">
<input type="text" placeholder="First name" class="signup__input name" id="firstname" name="firstname" onfocus="emptyElement('status')" onkeyup="restrict('name')" maxlength="32">
<br>
</div>
<div class="signup__row">
<input type="text" placeholder="Last name" class="signup__input name" id="lastname" name="lastname" onfocus="emptyElement('status')" onkeyup="restrict('name')" maxlength="32">
<br>
</div>
<div class="signup__row">
<input type="text" placeholder="Username" class="signup__input name" id="username" onfocus="emptyElement('status')" onblur="checkusername()" onkeyup="restrict('username')" maxlength="16">
<br>
<span id="unamestatus"></span>
</div>
<div class="signup__row">
<input type="text" placeholder="Email" class="signup__input name" id="email" onfocus="emptyElement('status')" onkeyup="restrict('email')" maxlength="88">
</div>
<div class="signup__row">
<input type="password" placeholder="Password" class="signup__input pass" id="pass1" onfocus="emptyElement('status')" maxlength="16">
</div>
<div class="signup__row">
<input type="password" placeholder="Confirm password" class="signup__input pass" id="pass2" onfocus="emptyElement('status')" maxlength="16">
</div>
<div class="signup__row">
<select id="gender" onfocus="emptyElement('status')" placeholder="Gender" class="signup__input">
<option value="">Please select a gender</option>
<option value="m">Male</option>
<option value="f">Female</option>
</select>
</div>
<div class="signup__row">
<select id="country" onfocus="emptyElement('status')" placeholder="Country" class="signup__input">
<?php include_once("inc/countries.php"); ?>
</select>
</div>
<div>
<p class="signup__terms"> By creating an account you accept the terms of service </p>
</div>
<p id="status"></p>
<button id="signupbtn" onclick="signup()" class="send"name="Submit">Sign up</button>
</div>
</div>
</div>
</form>
</div>
</div>
<?php include_once("footer.php"); ?>
</body>
</html>
In your code besides what was mentioned in the comments you have an if statement that is assigning variables.
if($f = "" || $l = "" || $u == "" || $e == "" || $p == "" || $g == "" || $c == ""){}
Notice the = and not == after $f and $l, it should be:
if($f == "" || $l == "" || $u == "" || $e == "" || $p == "" || $g == "" || $c == ""){}
This way you aren't replacing the original contents and are now checking the contents.
And for future an empty() check will check for "" or even unset POST variables, allowing you to check missing POST values and empty strings in 1 go.
trap for the weary who have gazed at the screen for way, way tool long
if($f = "" || $l = "" || $u == "" || $e == "" || $p == "" || $g == "" || $c == ""){
In the line above you use a single = for $f and $l which gives them new values, in this case "".
Change it to
if($f == "" || $l == "" || $u == "" || $e == "" || $p == "" || $g == "" || $c == ""){
and you'll be back in business!

Need help to troubleshoot php (Warning: Missing argument 11 ...)

I have had to modify some php code to suit my needs and my forms page is now spitting out this
"Warning: Missing argument 11 for cash_payment(), called in
/.../wp-content/plugins/inkappointmentpro/ink-admin/apt-form.php
on line 66 and defined in
/.../wp-content/plugins/inkappointmentpro/ink-admin/appointments-form/getway/paypal-page.php
on line 26"
when submitting the form.
Here are the two files in question. Can someone please help? I'm not a programmer, just a guy who manages to fuddle his way through this stuff usually.
paypal-page.php
<?php
/**
* Paypal Transaction
* # gateway_sandbox
* */
function gateway_sandbox() {
if (isset($_POST['submit'])) {
$db_obj = new Apt_DB();
if (file_exists($db_obj->dir . "ink-admin/appointments-form/getway/paypal/paypal_sandbox.php")) {
include_once($db_obj->dir . "ink-admin/appointments-form/getway/paypal/paypal_sandbox.php");
}
}
}
/**
* Paypal Transaction
* # gateway_paypal
* */
function gateway_paypal() {
if (isset($_POST['submit'])) {
$db_obj = new Apt_DB();
if (file_exists($db_obj->dir . "ink-admin/appointments-form/getway/paypal/paypal_response.php")) {
include_once($db_obj->dir . "ink-admin/appointments-form/getway/paypal/paypal_response.php");
}
}
}
function cash_payment($sr_apt_id, $sr_apt_time, $sr_apt_date, $sr_apt_persion_name, $sr_apt_email, $sr_apt_phone, $sr_msg, $sr_apt_message, $sr_apt_ugs, $sr_apt_lawnarea, $sr_data_rand) {
global $wpdb;
$db_obj = new Apt_DB();
$apt_service = $db_obj->tbl_service;
$appointment_data = $db_obj->tbl_appointment_data;
$sql_srdata = $wpdb->get_row("SELECT * FROM $apt_service Where service_id='$sr_apt_id'", ARRAY_N);
$cr_code = get_option('apt_currency_code');
$price = $sql_srdata[2] . '&nbsp' . $cr_code . '&nbsp- Pay Cash Later';
$priceshow = $sql_srdata[2] . '' . $cr_code;
$apt_txn_booking_date = date("F j, Y, g:i A");
$apt = new AptService();
if (isset($_POST['submit'])) {
$sql_val = $wpdb->get_row("SELECT * FROM $appointment_data Where apt_data_rand='$sr_data_rand'");
if (!$sql_val) {
$apt->insert_data_frontend($sr_apt_id, $sr_apt_date, $sr_apt_persion_name, $sql_srdata[1], $sr_apt_time, $price, $sr_apt_email, $sr_apt_phone, $sr_msg, $sr_apt_message, $sr_apt_ugs, $sr_apt_lawnarea, $sr_data_rand, $apt_txn_booking_date, 'cash');
echo '<p>Your appointment request has be submitted successfully. We will email or phone you with confirmation.</br>Thank you for choosing Saskatoon ProLawn.</p>';
/**
* Send transaction notification to admin or client
*/
$transaction_details = '';
$personname = $sr_apt_persion_name;
$servicename = $sql_srdata[1];
$aptime = $sr_apt_time;
$aptdate = $sr_apt_date;
$aptmessage = $sr_apt_message;
$aptugs = $sr_apt_ugs;
$aptlawnarea =$sr_apt_lawnarea;
$aptemail = $sr_apt_email;
$url = site_url();
$adminurl = str_replace('http://', '', $url);
$transaction_details .= "Hello $personname,\r";
$transaction_details .= "\r";
$transaction_details .= "Your appointment request has been received, below are the details of your request. \r \r";
$transaction_details .= "Service Name: $servicename \r";
$transaction_details .= "Appointment Date: $aptdate\r";
$transaction_details .= "Appointment Time: $aptime\r";
$transaction_details .= "Contact Phone: $aptphone\r";
$transaction_details .= "Address: $aptmessage\r";
$transaction_details .= "Underground Sprinklers Present: $aptugs\r";
$transaction_details .= "Lawn Area to be Done: $aptlawnarea\r \r";
$transaction_details .= "Thanks for choosing Saskatoon ProLawn.\r";
$transaction_details .= "When I confirm the date and time, I will send another email or contact you at the phone number provided. Please add us \r \r";
$transaction_details .= "Warm Regards,\r";
$transaction_details .= "Shane\r \r";
$transaction_details .= "$adminurl\r";
$subject = __("Your Appointment Request Has Been Received", 'appointment');
$filecontent = $transaction_details;
$admin_email = get_option('admin_email');
$headers = 'From: ' . $admin_email . ' <' . $aptemail . '>' . "\r\n" . 'Reply-To: ' . $admin_email;
$header = 'From: ' . $aptemail . ' <' . $admin_email . '>' . "\r\n" . 'Reply-To: ' . $aptemail;
//mail($to_admin, $subject, $filecontent, $headers);
wp_mail($aptemail, $subject, $filecontent, $headers); //email to user
wp_mail($admin_email, $subject, $filecontent, $header); //email to admin
} //refresh value if end
} //submit data if end
}
//function end
apt-form.php
<?php
add_shortcode('ink-appointments-form', 'ink_appoitment');
function ink_appoitment() {
?>
<script>
jQuery.noConflict();
jQuery(function () {
jQuery("#aptcal").datepicker();
jQuery("#aptcal").datepicker("option", "minDate", 0);
});
</script>
<?php
$db_obj = new Apt_DB();
global $wpdb;
$cpt_true = false;
$apt_service = $db_obj->tbl_service;
$check_apt = isset($_POST['chk_apt']) ? $_POST['chk_apt'] : null;
$cpt_apt = isset($_POST['apt_cpt']) ? $_POST['apt_cpt'] : null;
if ($check_apt != $cpt_apt) {
$cpt_true = true;
}
$msg = '';
$captcha_details = '';
$is_captcha_on = get_option('cpt_enable');
if ($_SERVER["REQUEST_METHOD"] == "POST" && $is_captcha_on == 'on') {
$recaptcha = $_POST['g-recaptcha-response'];
if (!empty($recaptcha)) {
$secret = get_option('apt_recaptcha_private');
$secret = empty($secret) ? 'Google secret key' : $secret;
$captcha_data = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secret . "&response=" . $_POST['g-recaptcha-response']);
$response = json_decode($captcha_data, TRUE);
if ($response['success']) {
$captcha_details = true;
} else {
$captcha_details = false;
$error = array_search("invalid-input-secret", $response['error-codes']);
if ($error == 0) {
$msg = "Please enter correct reCAPTCHA key.";
} else {
$msg = "Please re-enter your reCAPTCHA.";
}
}
} else {
$captcha_details = false;
$msg = "Please re-enter your reCAPTCHA.";
}
}
$blank_data = "";
if ((isset($_POST['submit']) && $is_captcha_on != 'on' && $cpt_true == false ) || (isset($_POST['submit']) && $captcha_details == true)) {
$_POST['time'];
if (($_POST['time'] == 'notavi') || ($_POST['service_select'] == 'notavi')) {
echo "<p>Please Insert All data.</p>";
$blank_data = true;
} else {
$blank_data = false;
echo $badUrl = (isset($_POST['sr_price'])) ? $_POST['sr_price'] : null;
if (get_option('apt_paypal') == "sandbox") {
gateway_sandbox();
} elseif (get_option('apt_paypal') == "paypal") {
gateway_paypal();
} elseif (get_option('apt_paypal') == "cash") {
$datechange = $_POST['aptcal'];
$dateformat = explode('/', $datechange);
$newaptdate = $dateformat[1] . '/' . $dateformat[0] . '/' . $dateformat[2];
cash_payment($_POST['service_select'], $_POST['time'], $newaptdate, $_POST['fname'], $_POST['aptemail'], $_POST['aptphone'], $_POST['aptmessage'], $_POST['aptugs'], $_POST['aptlawnarea'], $_POST['random']);
}
}
}
if (isset($_GET['paypal-trans'])) {
ink_apt_trans_display();
} else {
$ruri = $_SERVER['REQUEST_URI'];
$sname = $_SERVER['SERVER_NAME'];
$fullpath = 'http://' . $sname . $ruri;
update_option('return_apt_url', $fullpath);
$br = new AptService();
$iechk = $br->ink_browser();
if ((!isset($_POST['submit'])) || ($check_apt != $cpt_apt) || ($captcha_details == false) || ($blank_data == true)) {
?>
<div class="ink-container">
<div class="inkappointment_wrapper">
<div class="inkappointment_form_top">
</div>
<div class="inkappointment_form_wrapper">
<form method="post" action="" id="ink-form" name="ink-form" class="ink-form" >
<header id="ink-header" class="ink-info">
</header>
<ul class="inkappform">
<li class="textheading"><h2><span class="msg_text"><?php echo get_option('apt_form_head'); ?></span></h2></li>
<li class="textfname"><input type="text" name="fname" id="fname" class="inktext inklarge inkrequired" placeholder="Name" maxlength="100" />
<label id="apt_error"> </label>
</li>
<li class="textaptemail"><input type="email" name="aptemail" id="aptemail" class="inktext inklarge inkrequired" placeholder="Email" maxlength="100" /></li>
<li class="textaptphone"><input type="text" name="aptphone" id="aptphone" class="inktext inklarge" placeholder="Contact Number" maxlength="12” /></li>
<li class="textfixdate"><span class="fix_date"><?php echo get_option('apt_fix_date'); ?></span></li>
<li class="select_item"><select id="service_select" name="service_select" class="inktext inklarge inkrequired" >
<option value="noavi">Select Service</option>
<?php
$showts = $wpdb->get_results("SELECT * FROM $apt_service ", ARRAY_A);
foreach ($showts as $timerow) {
?>
<option value="<?php echo $timerow['service_id']; ?>"><?php echo $timerow['service_name']; ?></option>
<?php } ?> </select></li>
<li class="textaptcal"><input type="text" name="aptcal" id="aptcal" class="dateField inktext inklarge" placeholder="Select Date" /></li>
<li class="select_item"><select id="time" name="time" class="inktext inklarge inkrequired">
<option value="notavi">Select Time</option> </select></li>
<li class="textfixdate"><span class="fix_date">Do you have underground Sprinklers?</span></li>
<li class="textfixdate"><span class="fix_date"><input type="radio" name="aptugs" id="aptugs" value="yes" checked>Yes <input type="radio" name="aptugs" id="aptugs"” value="no">No</span></li>
<li class="textfixdate"><span class="fix_date">Area Required</span></li>
<li class="textfixdate"><span class="fix_date"><input type="radio" name="aptlawnarea" id="aptlawnarea" value="frontback" checked>Front+Back <br> <input type="radio" name="aptlawnarea" id="aptlawnarea" value="front">Front Only <br> <input type="radio" name="aptlawnarea" id="aptlawnarea" value=“back”>Back Only</span></li>
<li class="textfixdate"><span class="fix_date"><?php echo get_option('apt_custom_msg'); ?></span></li>
<li class="textaptmessage"><textarea name="aptmessage" id="aptmessage" class="inktext inklarge inkrequired" maxlength="255" rows="3" cols="50" placeholder="Address (required)" ></textarea></li>
<?php if ($is_captcha_on === 'on') { ?><li>
<div class="g-recaptcha-div"><div class="g-recaptcha" data-sitekey="<?php
if (get_option('apt_recaptcha_public')) {
echo get_option('apt_recaptcha_public');
} else {
echo 'Google Public Key';
}
?>"></div>
</div>
<span class='msg'><?php echo $msg; ?></span>
</li>
<?php } ?>
<li class="submit_bg">
<input type="hidden" name="random" id="random" value="<?php echo rand(); ?>"/>
<input type="submit" name="submit" id="submit" class='ink-submit inkrequired' value="Book Appointment"/> </li>
</ul>
</form>
</div>
<div class="inkappointment_form_bottom">
</div>
</div>
</div>
<?php
} //submit not set
}
}
you have missing one parameter for the following function: cash_payment()
Function Definition having 11 parameters:
function cash_payment($sr_apt_id, $sr_apt_time, $sr_apt_date, $sr_apt_persion_name, $sr_apt_email, $sr_apt_phone, $sr_msg, $sr_apt_message, $sr_apt_ugs, $sr_apt_lawnarea, $sr_data_rand) {}
Function calling 10 parameters:
cash_payment($_POST['service_select'], $_POST['time'], $newaptdate, $_POST['fname'], $_POST['aptemail'], $_POST['aptphone'], $_POST['aptmessage'], $_POST['aptugs'], $_POST['aptlawnarea'], $_POST['random']);
If you don't have any 11th parameters of any values against parameters than pass the empty string but no of parameters in definition is always equal to no of parameters of calling a function.
I think this error comes due to missing argument in cash_payment function, please check all fields of this function.
cash_payment($_POST['service_select'], $_POST['time'], $newaptdate, $_POST['fname'], $_POST['aptemail'], $_POST['aptphone'], $_POST['aptmessage'], $_POST['aptugs'], $_POST['aptlawnarea'], $_POST['random']);
}
Please try to echo all fields and check if you found any of null value.

Wrong Securimage verification code still sends the form

First time poster, be gentle.
I have a form with a .php processing script that worked fine for the longest time except for the fact that I started to receive spam. I did some research on Captcha's and came across Securimage which was (supposedly) one of the easiest to implement. I downloaded the files and installed it into my script. I came across two problems.
The form was still sending if the captcha was left blank (it still notified me that it was blank).
The form was still sending if the captcha was wrong (it still notified me that it was wrong).
You can see it in action here: http://216.119.71.44/contact/
I "patched" issue 1 just by making the field a required field. I need some help fixing number 2. Below is my code and you can find the documentation for securimage here:
contact.php:
<?php
$thisPage = "Contact";
$errors = array();
$missing = array();
$date = date('F j, Y');
// check if the form has been submitted
if (isset($_POST['send'])) {
// sends the message to recipient
ini_set("SMTP","mail.abcprintingink.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","587");
// Please specify the return address to use
$to = 'paulr#abcprintingink.com'; //recipient's email address
$from = $_POST['email']; // this is the sender's Email address
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$subject = 'Online Form Submission';
$expected = array('fname','lname','email','phone','comments','captcha_code');
$required = array('fname','lname','email','phone','comments','captcha_code','');
$headers = "From: Technical Staffing Solutions";
// sends a copy of the message to the sender
$receiptHeader = "From: Technical Staffing Solutions";
$receiptSubject = "Copy of your form submission";
$receipt = "Hello " . $fname . "," . "\n" . "Below is a copy of the message you sent to us on " . $date . ". We will contact you as soon as possible. Thank you!" . "\n\n" . $_POST['comments'];
mail($from,$receiptSubject,$receipt,$receiptHeader);
// detailed processing script (checks for errors)
require('../include/processmail.php');
}
?>
<h1>CONTACT US</h1>
<?php
// Various on submit mail messages
if ($mailSent) {
echo "<div id=\"form-success\"><div>✓</div><p>Thank you " . $fname . ", your message has been sent.</p></div>";
}
elseif (($_POST && $suspect) || ($_POST && isset($errors['mailfail']))) {
echo "<div id=\"form-error\"><div>!</div><p>Your message could not be sent. Please try again.</p></div>";
}
elseif ($missing || $errors) {
echo "<div id=\"form-error\"><div>!</div><p>Please fill out the required fields and try again.</p></div>";
}
?>
<form id="getquote" method="post" action="" style="float:left;">
<input type="text" id="fname" name="fname" placeholder="First Name"
<?php if ($missing && in_array('fname', $missing)) { ?>style="border: 1px solid #cc0000;"
<?php } if ($missing || $errors) { echo 'value="' . htmlentities($fname, ENT_COMPAT, 'UTF-8') . '"'; } ?>>
<input type="text" id="lname" name="lname" placeholder="Last Name"
<?php if ($missing && in_array('lname', $missing)) { ?>style="border: 1px solid #cc0000;"
<?php } if ($missing || $errors) { echo 'value="' . htmlentities($lname, ENT_COMPAT, 'UTF-8') . '"'; } ?>>
<input type="email" id="email" name="email" placeholder="Email Address"
<?php if ($missing && in_array('email', $missing)) { ?>style="border: 1px solid #cc0000;"
<?php } if ($missing || $errors) { echo 'value="' . htmlentities($email, ENT_COMPAT, 'UTF-8') . '"'; } ?>>
<input type="text" id="phone" name="phone" placeholder="Phone Number"
<?php if ($missing && in_array('phone', $missing)) { ?>style="border: 1px solid #cc0000;"
<?php } if ($missing || $errors) { echo 'value="' . htmlentities($phone, ENT_COMPAT, 'UTF-8') . '"'; } ?>>
<textarea placeholder="How can I help you?" id="comments" name="comments"
<?php if ($missing && in_array('comments', $missing)) { ?>style="border: 1px solid #cc0000;"
<?php } if ($missing || $errors) { echo 'value="' . htmlentities($comments, ENT_COMPAT, 'UTF-8') . '"'; } ?>> </textarea><br>
<!-- Captcha -->
<img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" />
↻
<input type="text" id="captcha_code" name="captcha_code" size="10" maxlength="6"
<?php if ($missing && in_array('captcha_code', $missing)) { ?>style="border: 1px solid #cc0000;"
<?php } if ($missing || $errors) { echo 'value="' . htmlentities($captcha_code, ENT_COMPAT, 'UTF-8') . '"'; } ?>>
<!-- Submit -->
<div style="width:292px;"><input type="submit" id="send" name="send" value="SUBMIT"></div>
</form>
processmail.php:
<?php
session_start();
$suspect = false; //assume nothing is suspect
$pattern = '/Content-Type:|Bcc:|Cc:/i'; //create a pattern to locate suspect phrases
function isSuspect($val, $pattern, &$suspect) { //function to check for suspect phrases
if (is_array($val)) { //if the variable is an array, loop thorugh each element and pass it recursively back to the same function
foreach ($val as $item) {
isSuspect($item, $pattern, $suspect);
}
} else {
if(preg_match($pattern, $val)) {
$suspect = true;
}
}
}
if (!$suspect) {
foreach ($_POST as $key => $value) {
$temp = is_array($value) ? $value : trim($value); //assign to temporary variable and strip whitespace if not an array
if (empty($temp) && in_array($key, $required)) { //if empty and requires, add to $missing array
$missing[] = $key;
} elseif (in_array($key, $expected)) {
${$key} = $temp; //otherwise, assign to a variable of the same name as $key
}
}
}
if (!$suspect && !empty($email)) {
$validemail = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
if ($validemail) {
$headers .= "\r\nReply-To: $validemail";
} else {
$errors['email'] = true;
}
}
$mailSent = false;
if (!$suspect && !$missing && !$errors) { //go ahead only if not suspect and all required fields are ok
$message = "";
foreach($expected as $item) { //loop through the $expected array
if (isset(${$item}) && !empty(${$item})) {
$val = ${$item};
} else {
$val = 'Not Selected'; //if it has no value, assign 'not selected'
}
if (is_array($val)) { //if an array, expand as comma-separated string
$val = implode(', ', $val);
}
$item = str_replace(array('_', '-'), ' ', $item); //replace underscores and hyphens in the label with spaces
$message .= ucfirst($item).": $val\r\n\r\n"; //add label and value to the message body
}
$message = wordwrap($message, 70); //limit the line length to 70 characters
$mailSent = mail($to, $subject, $message, $headers);
if (!$mailSent) {
$errors['mailfail'] = true;
}
}
include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == false) {
// the code was incorrect
// you should handle the error so that the form processor doesn't continue
// or you can use the following code if there is no validation or you do not know how
echo "The security code entered was incorrect.<br /><br />";
echo "Please go <a href='javascript:history.go(-1)'>back</a> and try again.";
exit;
}

How do I validate this email contact form with PHP?

Link to website: http://www.leonardpfautsch.com/contact.php
How do I make my contact form validated only using PHP? I want to be able to have error messages directly under the text field that has an error. For each text field, I do not want multiple errors to show up at once. If you submit the form with nothing in the fields, you see that under name and email two errors show up for each. I want the errors to show up only once due to some type of specifications. Right now I think I am on the right track. However, the code below does not have the email being sent. I am very new to PHP. If anybody could help me, I would really appreciate it.
<?php
if (($_SERVER['REQUEST_METHOD'] == 'POST') && (!empty($_POST['action']))){
$errors = array($name_error_1, $name_error_2, $email_error_1, $email_error_2, $subject_error, $message_error);
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
if ($name === '') {
$name_error_1 = '<div style="color:red;"> Name is a required field! </div>';
}
if ($email === '') {
$email_error_1 = '<div style="color:red;"> Email is a required field! </div>';
}
if ($subject === '') {
$subject_error = '<div style="color:red;"> Subject is a required field! </div>';
}
if ($message === '') {
$message_error = '<div style="color:red;"> Message is a required field! </div>';
}
if (isset($email) && (filter_var($email, FILTER_VALIDATE_EMAIL) === false)){
$email_error_2 = '<div style="color:red;"> The email address must be real! </div>';
}
if (ctype_alpha($name) === false) {
$name_error_2 = '<div style="color:red;"> Your name must only contain letters! </div>';
}
/*Main way that mail works*/
if (empty($errors) === true) {
/*Where_mail_goes_to, Subject, Body_text, Who_email_is_from*/
mail('email_address', $subject, "From " . $name . "\r\r" . $message, 'From: ' . $email);
/*Shows up in the URL if the message has been sent*/
header('Location: contact.php?sent');
exit();
}
} //end of main if
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>" >
<span class="label">Name</span><br/>
<?php if (isset($name_error_1)) { echo $name_error_1; } ?>
<?php if (isset($name_error_2)) { echo $name_error_2; } ?>
<input type="text" class="textfield" name="name" size="50" maxlength="50" <?php if (isset($_POST['name']) === true) { echo 'value="', strip_tags($_POST['name']), '"'; } ?> > <br/>
<span class="label">Email</span><br/>
<?php if (isset($email_error_1)) { echo $email_error_1; } ?>
<?php if (isset($email_error_2)) { echo $email_error_2; } ?>
<input type="text" class="textfield" name="email" size="50" maxlength="50" <?php if (isset($_POST['email']) === true) { echo 'value="', strip_tags($_POST['email']), '"'; } ?> > <br/>
<span class="label">Subject</span><br/>
<?php if (isset($subject_error)) { echo $subject_error; } ?>
<input type="text" class="textfield" name="subject" size="50" maxlength="50" <?php if (isset($_POST['subject']) === true) { echo 'value="', strip_tags($_POST['subject']), '"'; } ?> > <br/>
<span class="label">Message</span><br/>
<?php if (isset($message_error)) { echo $message_error; } ?>
<textarea rows="5" cols="50" name="message" id="textarea" maxlength="500"><?php if (isset($_POST['message']) === true){ echo $_POST['message'];}?></textarea><br/>
<input type="submit" value="Send" id="submit" name="action">
</form>
You could create an array of errors for each field and display just the first error added to it.
<?php
$email_errors = array();
if ($email == '')
{
$email_errors[] = 'First error';
}
if (more_email_checks($email) == false)
{
$email_errors[] = 'Second error';
}
?>
...
<span class="label">Email</span><br />
<?php echo array_shift($email_errors); ?>
To know whether to send e-mails or not, you could do something like this:
$errors_found = 0;
if (check_email($email) == false)
{
$email_error = 'Error message';
$errors_found++;
}
...
if ($errors_found == 0)
{
mail(...);
}
You can do it by using the elseif check
<span class="label">Email</span><br/>
<?php if (isset($email_error_1))
{
echo $email_error_1;
}
elseif(isset($email_error_2)) {
echo $email_error_2;
} ?>
Also move this line after the last validation check
if (ctype_alpha($name) === false) {
$name_error_2 = '<div style="color:red;"> Your name must only contain letters! </div>';
}
$errors = array($name_error_1, $name_error_2, $email_error_1, $email_error_2, $subject_error, $message_error);
you can by this code for name
<?
$message = "<div style = 'color :red ' /> ;
if (isset(name == '' ) {
echo $message
}
?>
this is name php vaildation but yo can create js
Change your email validation to:
<span class="label">Email</span><br/>
<?php if (isset($email_error_1))
{
echo $email_error_1;
}else if(isset($email_error_2)) {
echo $email_error_2;
} ?>
same if else can be applied to all the fields with multiple validation conditions.
and then move your error array just above the email condition check:
<?php
$errors = array($name_error_1, $name_error_2, $email_error_1, $email_error_2, $subject_error, $message_error);
//and change your mail function as:
$to = 'email_address';
$headers = $headers .= 'From: $name <$email>';
mail($to, $subject, $message, $headers);
?>
Also perform a check on the control, if you have filled the form completely then it should come to the mail function, I mean just check the if condition, in case you have some issue with the condition, try to put an echo inside if statement(which is responsible for sending email), and if that echo statement executes then mail should work.
:)

Categories