I am working on a comment section for a project.
I have the following php code:
<?php
echo "<form method='POST' action='".setComments($conn)."'>
<input type='hidden' name='uID' value='Anonymous'>
<input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'>
<textarea name='message'></textarea><br>
<button class='submit-button' type='submit' name='commentSubmit'>Comment</button>
</form>";
getComments($conn);
?>
The setComments() and getComments() are here:
function setComments($conn) {
if(isset($_POST['commentSubmit'])){
$uID = $_POST['uID'];
$date = $_POST['date'];
$message = $_POST['message'];
$sql = "INSERT INTO commentSection (uID, date, message)
VALUES ('$uID', '$date', '$message')";
$result = $conn->query($sql);
}
}
function getComments($conn){
$sql = "SELECT * FROM commentSection";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()){
echo "<div class='comment-box'><p>";
echo $row['uID']."<br>";
echo $row['date']."<br>";
echo nl2br($row['message']);
echo "</p>
<form class='delete-form' method='POST' action='deleteComments.php'>
<input type='hidden' name='commentID' value='".$row['commentID']."'>
<button type='submit' name='commentDelete'>Delete</button>
</form>
<form class='edit-form' method='POST' action='editComment.php'>
<input type='hidden' name='commentID' value='".$row['commentID']."'>
<input type='hidden' name='uID' value='".$row['uID']."'>
<input type='hidden' name='date' value='".$row['date']."'>
<input type='hidden' name='message' value='".$row['message']."'>
<button>Edit</button>
</form>
</div>";
}
}
Now, I have created the following form element using bootstrap:
<form>
<div class="row">
<div class="col">
<input type="text" class="form-control" placeholder="First name">
</div>
</div>
</form>
How can I make it so that this form input, or the first name, value shows up here:
<input type='hidden' name='uID' value='Anonymous'>
instead of the default 'Anonymous' value?
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>
Ive been searching for an answer, with no luck. There is one possible related post, but there is no answer avail.
Im posting form data to itself via the post action. Im then retreiving all the posted values, before sending them into a mysql table.
<?php
require_once 'config.php';
$gemBarcode = $gemSpec = $gemVar = $gemWeigh = $gemShape = $gemCut = $gemCol = $gemBrill = $gemClear = $gemTreat = $gemCertNum = $gemLWarehouse="";
$gemDesc="";
$createdDate = $modifiedDate = $gemChecked ="";
$gemW = $gemH = $gemCert =0;
$gemlength = 0;
//if form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST") {
//form actions once submitted (Ie: Check the validity, and if all ok submit to server) - I will complete this later
$gemBarcode = $_POST['gemBarcode'];
$gemSpec = $_POST['gemSpec'];
$gemVar = $_POST['gemVar'];
$gemWeigh = $_POST['gemWeigh'];
$gemShape = $_POST['gemShape'];
$gemCut = $_POST['gemCut'];
$gemCol = $_POST['gemCol'];
$gemBrill = $_POST['gemBrill'];
$gemClear = $_POST['gemClear'];
$gemTreat = $_POST['gemTreat'];
$gemCertNum = $_POST['gemCertNum'];
$gemLWarehouse= $_POST['gemLWarehouse'];
$gemDesc = $_POST['gemDesc'];
$createdDate = date("Y-m-d");
$modifiedDate = date("Y-m-d");
$gemChecked = date("Y-m-d");
$gemW = $_POST['gemW'];
$gemH = $_POST['gemH'];
$gemlength = $_POST['gemlength'];
$gemCert = $_POST['gemCert'];
// $sqlstatement=$mysqli->prepare();
$sql = "INSERT INTO stockitems (gemBarcode, gemSpec, gemVar, gemWeigh, gemShape, gemCut, gemClear, gemW, gemH, gemL, gemCol, gemBrill, gemTreat, gemCert, gemCertNum, gemLWarehouse, createdDate, modifiedDate, gemChecked, gemDesc) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
if($stmt=$mysqli->prepare($sql)){
$stmt->bind_param("sssssssdddsssissssss",$Para_gemBarcode, $Para_gemSpec, $Para_gemVar, $Para_gemWeigh, $Para_gemShape, $Para_gemCut, $Para_gemClear, $Para_gemW, $Para_gemH, $Para_gemLen, $Para_gemCol, $Para_gemBrill, $Para_gemTreat, $Para_gemCert, $Para_gemCertNum, $Para_gemLWarehouse, $Para_createdDate, $Para_modifiedDate, $Para_gemChecked, $Para_gemDesc);
$Para_gemBarcode = $gemBarcode;
$Para_gemSpec = $gemSpec;
$Para_gemVar = $gemVar;
$Para_gemWeigh = $gemWeigh;
$Para_gemShape = $gemShape;
$Para_gemCut = $gemCut;
$Para_gemCol = $gemCol;
$Para_gemBrill = $gemBrill;
$Para_gemClear = $gemClear;
$Para_gemTreat = $gemTreat;
$Para_gemCertNum = $gemCertNum;
$Para_gemLWarehouse =$gemLWarehouse;
$Para_gemDesc = $gemDesc;
$Para_createdDate = $createdDate;
$Para_modifiedDate = $modifiedDate;
$Para_gemChecked = $gemChecked;
$Para_gemW = $gemW;
$Para_gemH = $gemH;
$Para_gemLen = $gemlength;
$Para_gemCert = $gemCert;
if ($stmt->execute()){
echo "Successfully executed <br>";
//WILL REDIRECT
} else {
echo "Execution Failed: <br> ".$mysqli->errno.": ".$mysqli->error;
}
}
//$stmt->close(); - any idea why this is throwing an error?
$mysqli->close();
}
?>
<!DOCTYPE HTML>
<html lang="eng">
<head>
<meta charset="UTF-8">
<title>Add New Gemstone</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">
* { font-family: "arial"; }
.wrapper {
width: 90%;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
<form class='form-inline' action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class='row'>
<label class='col-md-2' for='gemBarcode'>Barcode</label>
<input type='number' class='form-control col-md-2' name='gemBarcode' placeholder='Barcode' required value='<?php echo $gemBarcode;?>'>
</div>
<div class='row'>
<label class='col-md-2' for='gemSpec'>Species</label>
<input type='text' class='form-control col-md-2' name='gemSpec' placeholder='Species' value='<?php echo $gemSpec;?>'>
<label class='col-md-2' for='gemVar'>Variant</label>
<input type='text' class='form-control com-md-3' name='gemVar' placeholder='Variant' value='<?php echo $gemVar;?>'>
</div>
<div class='row'>
<label class='col-md-2' for='gemWeigh'>Weight</label>
<input type='text' class='form-control col-md-2' name='gemWeigh' placeholder='Gem Weight (ct/g)' value='<?php echo $gemWeigh;?>'>
<label class='col-md-2' for='gemShape'>Shape</label>
<input type='text' class='form-control col-md-2' name='gemShape' placeholder='Shape' value='<?php echo $gemShape;?>'>
<label class='col-md-2' for='gemCut'>Cut</label>
<input type='text' class='form-control col-md-2' name='gemCut' placeholder='Cut' value='<?php echo $gemCut;?>'>
</div>
<div class='row'>
<label class='col-md-2' for='gemW'>Width</label>
<input type='number' class='form-control col-md-2' name='gemW' placeholder='Width (mm)' step='Any' value='<?php echo $gemW;?>'>
<label class='col-md-2' for='gemH'>Height</label>
<input type='number' class='form-control col-md-2' name='gemH' placeholder='Height (mm)' step='any' value='<?php echo $gemH;?>'>
<label class='col-md-2' for='gemlength'>Length</label>
<input type='number' class='form-control col-md-2' name='gemlength' placeholder='Length (mm)' step='any' value='<?php echo $gemlength; ?>'>
</div>
<div class='row'>
<label class='col-md-2' for='gemCol'>Colour</label>
<input type='text' class='form-control col-md-2' name='gemCol' placeholder='Colour' value='<?php echo $gemCol;?>'>
<label class='col-md-2' for='gemBrill'>Brilliance</label>
<input type='text' class='form-control col-md-2' name='gemBrill' placeholder='Brilliance' value='<?php echo $gemBrill;?>'>
<label class='col-md-2' for='gemClear'>Clarity</label>
<input type='text' class='form-control col-md-2' name='gemClear' placeholder='Clarity' value='<?php echo $gemClear;?>'>
</div>
<div class='row'>
<label class='col-md-2' for='gemTreat'>Enhancement</label>
<input type='text' class='form-control col-md-2' name='gemTreat' placeholder='Enhanced' value='<?php echo $gemTreat;?>'>
<div class='col'>
<label class='col-md-2' for='gemCert'>Certified</label>
<select class='form-control col-md-2' style='width=auto !important;' name='gemCert'>
<option></option>
<option value=1>Yes</option>
<option value=2>No</option>
</select>
</div>
<label class='col-md-2' for='gemCertNum'>Certificate Number</label>
<input type='text' class='form-control col-md-2' name='gemCertNum' placeholder='Certificate Number' value='<?php echo $gemCertNum;?>'>
</div>
<div class='row'>
<label class='col-md-2' for='gemLWarehouse'>Warehouse</label>
<input type='text' class='form-control col-md-2' name='gemLWarehouse' placeholder='Gem Location' value='<?php echo $gemLWarehouse;?>'>
<label class='col-md-2' for='gemDesc'>Description</label>
<input type='text' class='form-control col-md-7' name='gemDesc' placeholder='' value='<?php echo $gemDesc;?>'>
</div>
<div class='row'>
<label class='col-md-2' for='createdDate'>Created</label>
<input type='date' class='form-control col-md-2' name='createdDate' placeholder='Date Loaded' value='<?php echo $createdDate;?>'>
<label class='col-md-2' for='modifiedDate'>Modified</label>
<input type='date' class='form-control col-md-2' name='modifiedDate' placeholder='Date last Changed' value='<?php echo $modifiedDate;?>'>
<label class='col-md-2' for='gemChecked'>Checked</label>
<input type='date' class='form-control col-md-2' name='gemChecked' placeholder='Date last Checked' value='<?php echo $gemChecked;?>'>
</div>
<div class='row'>
<input type='submit' class='btn btn-primary' value='submit'>
<a href='index.php' class='btn btn-defaul'>Cancel</a>
</div>
</form>
</div>
</body>
</html>
Notes: - Please excuse the spelling - dyslexia. I had a lot of trouble with the word length, (spelling it lenght at times) but i redone these and they are all consistent. Also note: Colour is spelt right here in South Africa, Color in USA.
EDIT: The error is picked up on this line:
$gemlength = $_POST['gemlength'];
Its not a problem with my spelling, I've checked and rechecked.
I'm not sure why, but all of a sudden it started to work again, and I hadnt changed anything. Oh well, thanks anyway!
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!
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