Adding a subject line to PHP form - php

So I've put a contact form into my site but I can't seem to add a subject line. (I'm SUPER new to PHP so I'm only about 40% sure of what I'm doing. The rest of the time I'm just learning through trial and error).
Here's what I have for the form:
<?PHP
require_once("./include/fgcontactform.php");
$formproc = new FGContactForm();
$formproc->AddRecipient('email address');
$formproc->AddSubject('Website Communication:');
$formproc->SetFormRandomKey('boQQEtSLenwppBa');
if(isset($_POST['submitted']))
{
if($formproc->ProcessForm())
{
$formproc->RedirectToURL("thank-you.php");
}
}
?>
<!-- Form Code Start -->
<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
<fieldset >
<legend>Contact us</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div class='short_explanation'>* required fields</div>
<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container'>
<label for='name' >Your Full Name*: </label><br/>
<input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
<span id='contactus_name_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='email' >Email Address*:</label><br/>
<input type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
<span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='message' >Message:</label><br/>
<span id='contactus_message_errorloc' class='error'></span>
<textarea rows="10" cols="50" name='message' id='message'><?php echo $formproc->SafeDisplay('message') ?></textarea>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form>
I added the $formproc->AddSubject('Website Communication:'); segment but it doesn't seem to be working and I'm wondering if there's something I'm missing?

What you're really asking is how to use a specific library class that you've downloaded from the Internet! If you look into the code of the class you're including at the top (which I assume is the same as this?) then you'll see it's automatically generating a subject line here:
$this->mailer->Subject = "Contact form submission from $this->name";
The reason your AddSubject function doesn't work is because that behaviour doesn't exist within the class.
If you want to change this behaviour, you'll have to change the class. You'll want to change the above line to something like
$this->mailer->Subject = $this->getSubject();
and implement a getSubject() method, similar to the GetFromAddress() one.
Better yet, create your own mailer class! Look into the PHP mail function to get started!

Related

Form not submitting , Its submit in nonwww.domain when it come with www it only reload the page

I have a form on my website it works fine with nonwww.domain. if I try with www.domain in the same site
It won't go, Its keep on rotating after captcha, refresh page with new captcha and filled form is there.
Help me solve this error
I had this form earlier its work fine in other domain
This domain is under yahoo hosting
And
I have not any reply from them
Please find the code
Is this server error
<link rel="STYLESHEET" type="text/css" href="contact.css" />
<script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
<script type='text/javascript' src='scripts/fg_captcha_validator.js'></script>
<!-- Form Code Start -->
<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
<fieldset >
<legend>Contact us</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div class='short_explanation'>* required fields</div>
<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container'>
<label for='name' >Your Full Name*: </label><br/>
<input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
<span id='contactus_name_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='email' >Email Address*:</label><br/>
<input type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
<span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='message' >Message:</label><br/>
<span id='contactus_message_errorloc' class='error'></span>
<textarea rows="10" cols="50" name='message' id='message'><?php echo $formproc->SafeDisplay('message') ?></textarea>
</div>
<div class='container'>
<label for='photo' >Upload your photo:</label><br/>
<input type="file" name='photo' id='photo' /><br/>
<span id='contactus_photo_errorloc' class='error'></span>
</div>
<div class='container'>
<div><img alt='Captcha image' src='show-captcha.php?rand=1' id='scaptcha_img' /></div>
<label for='scaptcha' >Enter the code above here:</label>
<input type='text' name='scaptcha' id='scaptcha' maxlength="10" /><br/>
<span id='contactus_scaptcha_errorloc' class='error'></span>
<div class='short_explanation'>Can't read the image?
<a href='javascript: refresh_captcha_img();'>Click here to refresh</a>.</div>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form>
<!-- client-side Form Validations:
Uses the excellent form validation script from JavaScript-coder.com-->
<script type='text/javascript'>
// <![CDATA[
var frmvalidator = new Validator("contactus");
frmvalidator.EnableOnPageErrorDisplay();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email address");
frmvalidator.addValidation("email","email","Please provide a valid email address");
frmvalidator.addValidation("message","maxlen=2048","The message is too long!(more than 2KB!)");
frmvalidator.addValidation("photo","file_extn=jpg;jpeg;gif;png;bmp","Upload images only. Supported file types are: jpg,gif,png,bmp");
frmvalidator.addValidation("scaptcha","req","Please enter the code in the image above");
document.forms['contactus'].scaptcha.validator
= new FG_CaptchaValidator(document.forms['contactus'].scaptcha,
document.images['scaptcha_img']);
function SCaptcha_Validate()
{
return document.forms['contactus'].scaptcha.validator.validate();
}
frmvalidator.setAddnlValidationFunction("SCaptcha_Validate");
function refresh_captcha_img()
{
var img = document.images['scaptcha_img'];
img.src = img.src.substring(0,img.src.lastIndexOf("?")) + "?rand="+Math.random()*1000;
}
// ]]>
</script>

sender doesnt recieve mail in popup contact form in php

I m trying pop up contact form in php. Popup form works fine.But i want the mail received by both sender and recipient. In my form recipient receives the mail whereas the sender doesn't receive the mail. Can you please help me whats wrong in the code. Here is the code
<form id='contactus' action='javascript:fg_submit_form()' method='post' accept-charset='UTF-8'>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div class='short_explanation'>* required fields</div>
<div id='fg_server_errors' class='error'></div>
<div class='container'>
<label for='name' >Your Full Name*: </label><br/>
<input type='text' name='name' id='name' value='' maxlength="50" /><br/>
<span id='contactus_name_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='email' >Email Address*:</label><br/>
<input type='text' name='email' id='email' value='' maxlength="50" /><br/>
<span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='message' >Message:</label><br/>
<span id='contactus_message_errorloc' class='error'></span>
<textarea rows="10" cols="50" name='message' id='message'></textarea>
</div>
<?php
require_once("./include/fgcontactform.php");
require_once("./include/captcha-creator.php");
$formproc = new FGContactForm();
$captcha = new FGCaptchaCreator('scaptcha');
$formproc->EnableCaptcha($captcha);
//1.Add your email address here.
//You can add more than one receipients.
$formproc->AddRecipient('abc#gmail.com'). $email;
$formproc->SetFormRandomKey('dz0sbNoc7mZPgXa');
if(isset($_POST['submitted']))
{
if($formproc->ProcessForm())
{
echo "success";
}
else
{
echo $formproc->GetErrorMessage();
}
}
?>
Try this:
$formproc->AddRecipient('senderEmail#gmail.com, receiverEmail#gmail.com');
$formproc->AddRecipient('abc#gmail.com'). $email;
This line looks really questionable. What are you trying to do here. If you want to send to two users you need to make two calls to the AddRecipient method

how to validate a form that uses 'action' by php server-side

I uses this from to submit some information to '2co' as a payment method some of this information I need to validate it by PHP server-side and in the same time send a notification to the admin by mail to tell him that someone has been paid.
now this is the form.
<form method="post" action="https://sandbox.2checkout.com/checkout/purchase">
<div class="body">
<div class="half f_right">
<label for="card_holder_name" class="width_100per"><span class="fontRed2">*</span>card_holder_name
</label>
<input type="text" name="card_holder_name" id="card_holder_name"
class="form_textarea_rec"/>
</div>
<div class="half">
<label for="country" class="width_100per"><span class="fontRed2">*</span>country</label>
<select name="country" id="country" class="form_select_rec">
<option value="EGY" title="Egypt">Egypt</option>
<option value="SaudiArabia" title="saudi Arabia">Any other</option>
</select>
</div>
<div class="half">
<label for="street_address" class="width_100per"><span class="fontRed2">* </span>street_address </label>
<textarea name="street_address" id="street_address"
class="form_textarea_rec height_50px"></textarea>
</div>
<div class="half">
<label for="street_address2" class="width_100per"> address2</label>
<textarea name="street_address2" id="street_address2"
class="form_textarea_rec height_50px"></textarea>
</div>
<div class="half f_right">
<label for="city" class="width_100per"><span class="fontRed2">* city</span>
</label>
<input id="city" type="text" name="city" class="form_textarea_rec"/>
</div>
<div class="half f_right">
<label for="state" class="width_100per"><span class="fontRed2">*</span>
States</label>
<input id="state" type="text" name="state" class="form_textarea_rec"/>
</div>
<div class="half">
<label for="email" class="width_100per"> <span class="fontRed2">*</span>Email</label>
<input id="email" type="text" name="email" class="form_textarea_rec"/>
</div>
<div class="half">
<label for="zip" class="width_100per"> <span class="fontRed2">*</span>Zip</label>
<input id="zip" type="text" name="zip" class="form_textarea_rec"/>
</div>
<div class="half">
<label for="phone" class="width_100per"> <span class="fontRed2">*</span>
Phone</label>
<input id="phone" type="text" name="phone" class="form_textarea_rec"/>
</div>
</div>
<?php
$fullName = #$_POST['card_holder_name'];
?>
<input type='hidden' name='sid' value='*****'/>
<input type='hidden' name='mode' value='2CO'/>
<input type='hidden' name='li_0_type' value='product'/>
<input type='hidden' name='li_0_name' value='<?php echo $planName ?> '/>
<input type='hidden' name='li_0_price' value='<?php echo $planPrice ?> '/>
<input type='hidden' name='card_holder_name' value='<?php echo $fullName ?>'/>
<input type='hidden' name='street_address' value='<?php #$_POST['street_address']; ?>'/>
<input type='hidden' name='street_address2' value='<?php #$_POST['street_address2']; ?>'/>
<input type='hidden' name='city' value='<?php #$_POST['city']; ?>'/>
<input type='hidden' name='state' value='<?php #$_POST['state']; ?>'/>
<input type='hidden' name='zip' value='<?php #$_POST['zip']; ?>'/>
<input type='hidden' name='country' value='<?php #$_POST['country']; ?>'/>
<input type='hidden' name='email' value='<?php #$_POST['email']; ?>'/>
<div class="footer">
<input name="submit" type="submit" value="Continue" class="s_btn"/>
</div>
</form>
now I need to validate this fields and send the form and I need to send notes to the admin
I know about make it like this
<?php
if(isset($_POST['submit'])){
//remove the action from the form
//write the validation here ...
//and then send the mail
//but how to post all this in the end to '2co'??
}
?>
You could use curl to finally post it to 2co http://php.net/manual/en/book.curl.php
Sending mail is as simple as using mail function http://php.net/manual/en/function.mail.php
<?php
if(isset($_POST['submit'])){
//Do validation
//send mail
//post to 2co via curl
}
?>
As said in this question there are non curl ways to do so How do I send a POST request with PHP?
you are asking the wrong question, you should have asked "how to post data to another server using php?"
there are many answers here are some :
How do I send a POST request with PHP?
http://www.lornajane.net/posts/2010/three-ways-to-make-a-post-request-from-php
You need to do it by JavaScript on page load event.
Changes you need to do:
change action to same php page OR different AND check submit action by if(isset($_POST['submit'])) as you said.
validate all data, send mail, set php var $validated=true else false AND set some session variable which you should validate to confirm, on response from payment server. Ex: payment_id, user_id | these should also be sent to payment gateway and gateway returns on response, in your case I think sid
if($validated) echo the JavaScript code to create a hidden form with all information in hidden input field and submit form automatically on page load event.
on response from payment server, which will come on your specific php page validate session/user info.
If you are using jquery the autosubmit code will be like following:
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- if you are not using jQuery and want to then use above code -->
<?php if($validated) { ?> <script type="text/javascript">
$(function(){
var form = $('<form></form>');
form.attr("method", "post");
form.attr("action", link);
form.attr("style","display: none");
var field = $('<input />');
field.attr("type", "hidden");
field.attr("name", "post_var1");
field.attr("value", "val_1");
form.append(field); //echo values by php <?php echo $value1; ?> like:
var field1 = $('<input />');
field1.attr("type", "hidden");
field1.attr("name", "li_0_name");
field1.attr("value", "<?php echo $planName ?>");
form.append(field1);
//do same for all fields
$(document.body).append(form);
form.submit();
}
</script> <?php } ?>
For non jQuery (Pure JavaScript) code you can search OR ask me i'll edit the answer.

PHP email send form - drop down list on $_POST send form

Here is my html and php code:
<!-- Form Code Start -->
<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
<fieldset >
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container'>
Years Active (from and to):<br/>
<select name='years_active_from'>
<option value='<?php echo $formproc->SafeDisplay('NULL') ?>'>select</option>
<option value='<?php echo $formproc->SafeDisplay('from 2013') ?>'>2013</option>
<option value='<?php echo $formproc->SafeDisplay('from 2012') ?>'>2012</option>
</select>
<br/>
<span id='contactus_name_errorloc' class='error'></span>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form>
I am trying to get the different drop down options to change the var $years_active_from; to each of the different years, 2012, 2013 and post NULL if the drop down menu is not used.
value='<?php echo $formproc->SafeDisplay('NULL') ?>' is not changing the $years_active_from, what is the correct coding for this?
Honestly, I am not 100% sure I understand what you are looking for, but my guess is that you want to have the first drop down option pre-selected on page load. For that, you would need to do add the selected attribute to the option you want to show as selected:
<option selected value='<?php echo $formproc->SafeDisplay('NULL') ?>'>select</option>

Mysql Query clearing a row instead of updating

I have no idea why this is acting this way, I did echo out $sqll in my code and it shows all the right information but when it goes back to the page with the information it is blank.
Here is the script
<?php
include("header.php");
include("sidebar.php");
$memberon = $_GET['user'];
$getmember = mysql_query("SELECT * FROM accounts WHERE username='".$memberon."'");
$member = mysql_fetch_array($getmember);
?>
<h2>Edit User</h2>
<?php
$points = asql($_POST['points']);
$cash = asql($_POST['cash']);
$banned = asql($_POST['banned']);
$completed = asql($_POST['completed']);
$confirm= asql($_POST['confirm']);
$referral= asql($_POST['ref']);
$email= asql($_POST['email']);
$username= asql($_POST['username']);
$fname= asql($_POST['fname']);
$lname= asql($_POST['lname']);
$add= asql($_POST['address']);
$state= asql($_POST['state']);
$country= asql($_POST['country']);
$postal= asql($_POST['postal']);
$apt= asql($_POST['suite']);
$city= asql($_POST['city']);
$phone= asql($_POST['phone']);
$dob= asql($_POST['dob']);
if ($_POST['subm']) {
if($points <> $member['points'] || $cash <> $member['current_b']){
$final_report = "Checking";
print"This users balance has been updated, please input your pass code to confirm these changes <br />
<form method='post' action=''><input type='hidden' name='points' value='$points'><input type='hidden' name='cash' value='$cash'><input type='hidden' name='banned' value='$banned'><input type='hidden' name='confirm' value='$confirm'><input type='hidden' name='ref' value='$referral'><input type='hidden' name='email' value='$email'><input type='hidden' name='fname' value='$fname'><input type='hidden' name='lname' value='$lname'><input type='hidden' name='address' value='$add'><input type='hidden' name='state' value='$state'><input type='hidden' name='country' value='$country'><input type='hidden' name='postal' value='$postal'><input type='hidden' name='suite' value='$apt'><input type='hidden' name='city' value='$city'><input type='hidden' name='phone' value='$phone'><input type='hidden' name='dob' value='$dob'><input type='password' name='passcode' /><input type='submit' name='pcheck' value='Sumbit' /></form>";
}
else
{
$final_report = "";
}
if($final_report == NULL){
$updatemembers = mysql_query("UPDATE accounts SET points='$points', current_b='$cash', level='$banned', email_check='$confirm', referral='$referral', username='$username', fname='$fname', lname='$lname', email='$email', address='$add', state='$state', country='$country', postal='$postal', suite='$apt', city='$city', phone='$phone', dob='$dob' WHERE username='".$memberon."'") or die(mysql_error());
print "You Have Successfully Updated this Information";
header("Refresh: 2;url=edit.php?user=".$memberon."");
}
}
if($_POST['pcheck']){
$pchecki = asql($_POST['passcode']);
$pchecks = md5($pchecki);
$check = mysql_query("SELECT * FROM panel_access WHERE psn = '".$_SESSION['aname']."'") or die(mysql_error());
$checkar = mysql_fetch_array($check);
$final_report = "Checking.";
if($pchecks != $checkar['change_ab']){
$final_report = "That password is incorrect.";
print "".$final_report."";
header("Refresh: 2;url=edit.php?user=".$memberon."");
}
else
{
$final_report = "";
}
if($final_report == NULL){
$sqll = "UPDATE accounts SET points='".$points."', current_b='".$cash."', level='".$banned."', email_check='".$confirm."', referral='".$referral."', username='".$username."', fname='".$fname."', lname='".$lname."', email='".$email."', address='".$add."', state='".$state."', country='".$country."', postal='".$postal."', suite='".$apt."', city='".$city."', phone='".$phone."', dob='".$dob."' WHERE username='".$memberon."'";
$updatemember = mysql_query($sqll) or die(mysql_error());
print "You Have Successfully Updated this Information ".$sqll."";
header("Refresh: 2;url=edit.php?user=".$memberon."");
}
}
if(!isset($_POST['subm']) && !isset($_POST['pcheck']))
{
?>
<div class='form'>
<form action='' method='post'><input type=hidden name=subm value=1>
<div class="element">
<label for='email'>Email:</label>
<input type='text' name='email' id='email' value='<?php echo $member['email'] ?>' size='54' />
</div>
<div class="element">
<label for='username'>Username:</label>
<input type='text' name='username' id='username' value='<?php echo $member['username'] ?>' size='54' />
</div>
<div class="element">
<label for='ip'>IP Address:</label>
<input type='text' name='ip' id='ip' value='<?php echo $member['ip'] ?>' size='54' readonly='readonly' />
</div>
<div class="element">
<label for='banned'>Banned: <font color='red' size='1'><b>1=No 2=Yes</b></font></label>
<input type='text' name='banned' id='banned' value='<?php echo $member['level'] ?>' size='54' />
</div>
<div class="element">
<label for='confirm'>E-Mail Confirmed: <font color='red' size='1'>0=No 1=Yes</font></label>
<input type='text' name='confirm' id='confirm' value='<?php echo $member['email_check'] ?>' size='54' />
</div>
<div class="element">
<label for='ref'>Referral:</label>
<input type='text' name='ref' id='ref' value='<?php echo $member['referral'] ?>' size='54' />
</div>
<div class="element">
<label for='points'>Points:</label>
<input type='text' name='points' id='points' value='<?php echo $member['points'] ?>' size='54' />
</div>
<div class="element">
<label for='cash'>Cash:</label>
<input type='text' name='cash' id='cash' value='<?php echo $member['current_b'] ?>' size='54' />
</div>
<div class="element">
<label for='fname'>First Name:</label>
<input type='text' name='fname' id='fname' value='<?php echo $member['fname'] ?>' size='54' />
</div>
<div class="element">
<label for='lname'>Last Name:</label>
<input type='text' name='lname' id='lname' value='<?php echo $member['lname'] ?>' size='54' />
</div>
<div class="element">
<label for='phone'>Phone:</label>
<input type='tel' name='phone' id='phone' value='<?php echo $member['phone'] ?>' size='54' />
</div>
<div class="element">
<label for='dob'>Date of Birth:</label>
<input type='text' name='dob' id='dob' value='<?php echo $member['dob'] ?>' size='54' />
</div>
<div class="element">
<label for='address'>Address:</label>
<input type='text' name='address' id='address' value='<?php echo $member['address'] ?>' size='54' />
</div>
<div class="element">
<label for='suite'>Suite/Apt.:</label>
<input type='text' name='suite' id='suite' value='<?php echo $member['suite'] ?>' size='54' />
</div>
<div class="element">
<label for='country'>Country:</label>
<input type='text' name='country' id='country' value='<?php echo $member['country'] ?>' size='54' />
</div>
<div class="element">
<label for='state'>State:</label>
<input type='text' name='state' id='state' value='<?php echo $member['state'] ?>' size='54' />
</div>
<div class="element">
<label for='city'>City:</label>
<input type='text' name='city' id='city' value='<?php echo $member['city'] ?>' size='54' />
</div>
<div class="element">
<label for='postal'>Postal Code:</label>
<input type='text' name='postal' id='postal' value='<?php echo $member['postal'] ?>' size='54' />
</div>
<?php
print"<dl class='submit'>
<input type='submit' name='submit' id='submit' value='Submit' />
</dl>
</form>
</div> ";
}
include("footer.php");
?>
On a side note I know that mysql_query and the likes are in the process of being deprecated, I want to note that I did not write this, just doing some editing for a client, and this part is happening to be a pain in the rear.
Also its only the query in if($_POST['pcheck']) that isn't working, the first query for if($_POST['subm'] works fine
First, you have an empty string at the end. This doesn't hurt, but it has no purpose either.
You redirect the page to edit.php?user=$memberon, but $memberon isn't set when you get a POST request. You can have either GET or POST, but not both.
I would guess, you must redirect to
edit.php?user=$username

Categories