I am trying to create three forms. The way it should work is a form should appear and the user is able to input their info. When the submit button is pressed an email should be sent to the supervisor and the supervisor should click on a link and another form should appear. When the supervisor fills the form and then clicks submit an email should be submitted to the client. the client will click on the link and fill the form out. The client should be then able to send an email to the employee and the both the supervisor and the original user should be able to get the response. However when I keep creating the form the php keeps breaking after the second form. I cant seem to figure out why it keeps breaking in the third form.
here is a snippit of the php code for the second form:
if ($_POST['token'] == "2") {
$m = new mysql($connection_information);
$m->update('hello',array('approval'=>$_POST['approval'],
'comment'=>$_POST['comment'],
'approved_by'=>$_POST['approval_by'],
'approved_date'=>time()),'uid=\''.$_POST['uid'].'\'');
$records = $m->row(array('table' => 'hello','condition' => 'uid=\''.$_POST['uid'].'\''));
$eemail = records['email'];
$supemail = $records['supervemail'];
$clemail = $records['cemail'];
$approvaltime = date("m/d/y g:i a",$records['approved_date']);
$subject = " " . $clemail;
$headers = 'From: ' . $supemail . "\r\n" .
'Reply-To: ' . $supemail . "\r\n" .
'MIME-Version: 1.0' . "\r\n";
if($records['approval'] == 1){
$travel_action = 'approved';
}else{
$travel_action = 'rejected';
}
$message = " Travel Estimation ".$travel_action." on ".$approvaltime." by ".$records['approved_by']. "\r\n" . "Comment: " .$records['comment']. "\r\n";
mail($eemail, $subject, $message, $headers);
Here is my html portion:
<?php if ($_POST['token'] == "2") { ?>
<h1>Approval Decision Submited.</h1>
<?php } else if ($_POST['token'] == "1") {
echo "<h1>Form has been submitted</h1>";
} else {
if (isset($_GET['uid']) && isset($records)){
?>
<form id="approvalForm" name="form2" action="hello.php" method="POST">
<input type="hidden" name="token" value="2">
<input type="hidden" name="uid" value="<?php echo $_GET['uid'] ?>">
<fieldset>
<legend>Manager Approval Required</legend>
Submitted on: <?php echo date("m/d/y g:i a",$records['submitted']) ?><br/>
By: <?php echo $records['email'] ?><br/>
<label for="email">Supervisor's Email: </label>
<input type="text" name="email" title="Email" value="<?php echo $records['supervemail'] ?>"><br>
<label for="email">Client's Email: </label>
<input type="text" name="email" title="Email" value="<?php echo $records['supervemail'] ?>"><br>
<label for="email">Employee's Email: </label>
<input type="text" name="email" title="Email" value="<?php echo $records['supervemail'] ?>"><br>
<label for="approval_by">Please Enter your name for approval: </label>
<input type="text" name="approval_by" id="approval_by" title="Approved By" ><br>
<label for="approval">Please select appropriate action: </label>
<select name="approval" id="approval">
<option value="">Please Select Action</option>
<option value="1">Approval</option>
<option value="0">Rejection</option>
</select>
<label for="comment" >Comment: </label>
<input type="text" name="comment" id="comment" title="comment"><br>
<input class="submit" type="submit" value="Submit"/>
</fieldset>
</form>
In my third form I want the supervisor to send an email to the client so the that the client will receive the link and approve or disapprove in the third form. From there they can submit an email to the user if they agree or disagree. I made it so the third form looks almost identical to the second form. Is that where my fault lies?
I notice that the records array for the eemail variable does not have a dollar sign.
$eemail = records['email'];
Should be
$eemail = $records['email'];
Related
Complete newbie at PHP. help.
I have written a large "join the club" form with 15 fields. the first 10 fields are required. last 5 are optional.
Each field has ID and names. name="fname" name="lname", for each field. (see below)___
<!-- FORM STARTS HERE -->
<form id="appliform" name="applform" method="post"
action="joinformscripts/test11.php"
enctype="text/plain" >
<!-- php code still in progress. test memb.php --->
<label for="fname">*First Name:</label><br>
<input type="text" id="fname" name="fname" required><br>
<label for="lname">*Last Name:</label><br>
<input type="text" id="lname" name="lname" required><br>
<label for="bizname">*Business Name:</label><br>
<input type="text" id="bizname" name="biz" required><br>
<label for="bizadd">*Business Mailing Address:</label><br>
<input type="text" id="bizadd" name="bizadd" required> <br>
<label for="city">*City:</label><br>
<input type="text" id="city" name="city" required> <br>
<label for="state">*State:</label><br>
<input type="text" id="state" name="state" required> <br>
<label for="zip">Zip:</label><br>
<input type="text" id="zip" name="zip" required> <br>
<label for="bizphone">*Business Phone:</label><br>
<input type="text" id="bizphone" name="bizphone" required> <br>
<label for="celphone">Personal Phone:</label><br>
<input type="text" id="celphone" name="celphone"> <br>
<label for="email">*Email:</label><br>
<input type="email" id="email" name="email" required><br>
<hr>
<h5>Complete this information if you are also paying for an Associate Membership. </h5>
<label for="fname">Associate First Name:</label><br>
<input type="text" id="afname" name="afname"><br>
<label for="lname">Associate Last Name:</label><br>
<input type="text" id="alname" name="alname"><br>
<label for="bizphone">Associate Business Phone:</label><br>
<input type="text" id="abizphone" name="abizphone" > <br>
<label for="celphone">Associate Personal Phone:</label><br>
<input type="text" id="acelphone" name="acelphone"> <br>
<label for="aemail">Associate Email:</label><br>
<input type="aemail" id="aemail" name="aemail"><br>
<hr>
<p>test 11 # 6.00p</p>
<!-- SEND BUTTON Submit using secure POST DATA button
when sent, opens remit payment page (in script)-->
<input type="submit" value="submit application" ><br>
<input type="reset" value="clear form">
<br>
<br>
<p>Please remit payment on the next page.</p>
</form> <!-- END MEMBERSHIP FORM with script action -->
PHP script.
<?php
// test 11
// after submit, goes to Remit page for payment: yes. //
// receive email with content in body: NO //
$email_to = "membership#xxxx.org";
$email_from = "membership#xxxx.org";
$reply_to = $_POST["email"];
$headers = "submitted by: .$mailfrom .$fname .$lname ";
$email_subject = "New Member Application Form (phptest8) revised 6.00pm thursday dec 10";
$headers = "From: " . $email_from . "\n";
$headers .= "Reply-To: " . $reply_to . "\n";
// NOT CAPTURING form variables.
//This needs to send all the fields in the form on Join page.
if(isset($_POST['submit'])){
$to = "membership#efwba.org"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['fname'];
$last_name = $_POST['lname'];
$subject = "Membership Form submission";
$message = $first_name . " " . $last_name . "
wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "my information " . $fname . "\n\n" . $fname . $lname . $biz . $bizadd . $city . $state . $zip . $bizphone . $celphone . $email . $afname . $alname . $abizphone . $acelphone. $aemail. $_POST['message'];
}
//Send the email. If the email is sent we will go to a REMIT PAYMENT page, if there is an error we will display a brief message.
ini_set("sendmail_from", $email_from);
$sent = mail($email_to, $email_subject, $email_body, $headers, $email_from);
if ($sent)
{
header("Location:/joinformscripts/thank-you-for-joining.html");
} else {
echo "There has been an error submitting your application. Please go back one page to verify all data has been entered correctly.";
}
// Function to validate against any email injection attempts
function IsInjected($str)
{
___
The host server -goDaddy, Cpanel- processes the php file and sends the email to the "Membership#" account.
After the form submits, it redirects to the Payment page, that part works!
However, I am NOT getting the field data inside the body of the email.
I see the starter line, but not what the applicant entered for contact info.
I want the body/ data to be a simple format, so I can copy it all and drop into a spreadsheet (for club mail merge printing)
It does not need to show the data labels.
I want to see this data in the email body:
"I want to join your organization!"
fname lname
biz
bizaddress
city state zip
bizphone
celphone
bizemail
QUESTION: what is the simplest method to capture each field into email_body?
Thank you!
I have checked all the questions first. But non of them helped to solve my problem.
I have PHP E-mail responder connected to HTML contact form. I need to display selected checkbox value inside the email responder which is sent to customer.
PHP code
<?php
if(isset($_POST) && ($_POST['send'] == 1)){
$documents = array(
'document1' => 'http://www.example.com/document1.doc',
'document2' => 'http://www.example.com/document2.doc',
'document3' => 'http://www.example.com/document3.doc'
'document4' => 'http://www.example.com/document4.doc'
);
$to = 'lubosmasura#gmail.com';
$subject = 'Prihláška na školenie';
$name = $_POST['name'];
$email = $_POST['email'];
$document = implode(", ",$post['document']);
if(isset($_POST['document']) && count($_POST['document']) > 0){
foreach($_POST['document'] as $doc){
if(isset($documents[$doc])){
$document = implode(", ",$post['document']);
$message = "
ŠKOLENIE: $document
";
}
}
}
$headers = 'From: noreply#marcelaskolenia.sk' . "\r\n" .
'Reply-To: noreply#marcelaskolenia.sk' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
}
?>
HTML code
<form method="post" action="test.php">
<p class="center">Vyberte školenie</p>
<label class="container riadok"><p for="document" class="dolava">§20 Poučená osoba</p>
<input type="checkbox" name="document[]" value="document1" id="document">
<span class="checkmark"></span>
</label>
<label class="container riadok"><p for="document" class="dolava">Aktualizácia: §21 AŽ §24</p>
<input type="checkbox" name="document[]" value="document2" id="document">
<span class="checkmark"></span>
</label>
<label class="container riadok"><p for="document" class="dolava">§21 Elektrotechnik</p>
<input type="checkbox" name="document[]" value="document3" id="document">
<span class="checkmark"></span>
</label>
<label class="container riadok"><p for="document" class="dolava">§24 Revízny technik</p>
<input type="checkbox" name="document[]" value="document4" id="document">
<span class="checkmark"></span>
</label>
<p class="center">Vyplňte osobné údaje</p>
<input type="text" name="name" id="name" class="form-control" placeholder="Meno">
<input type="text" name="email" id="email" class="form-control" placeholder="Email">
<input type="tel" name="phone" id="phone" class="form-control" placeholder="Telefónne číslo" pattern="[0-9]+" title="Zadajte iba čísla." required="required">
<input type="hidden" name="send" value="1" />
<button type="submit" value="SEND" id="submit" class="btn btn-primary"> ODOSLAŤ PRIHLÁŠKU</button>
Email responder works but it does not display selected checkbox value from HTML form behaind message ŠKOLENIE: CHECKBOX HERE
Any ideas? Thank you
Should be
if(isset($_POST['document']) && count($_POST['document']) > 0) {
foreach($_POST['document'] as $doc){
if(isset($documents[$doc])){
$document = implode(", ",$_POST['document']);
$message = "
ŠKOLENIE: $document
";
}
}
}
You don't have such a variable as $post, but you try to use it twice. Replace it with $_POST and your form will work.
This:
$document = implode(", ",$post['document']);
Replace with this:
$document = implode(", ",$_POST['document']);
And it should work.
Some hints:
Properly configured IDE will let you know about such errors as an undeclared variable. Use PHPStorm (commercial) or VSCode (free).
Don't close php tag (?>) at the end of your file (PSR2):
The closing ?> tag MUST be omitted from files containing only PHP.
Don't use the same identifier (id) multiple times. The id should be unique in the entire HTML document.
Edit: // As someone has mentioned in the comments, you don't have a closing tag for <form> tag, but I assumed that you pasted only a part of your HTML document. Otherwise, you should correct that as well.
I am trying to add a form into my index page, so that when you click on submit it will automatically return to the form when the page reloads. Right now if there are any errors on the page it will display them right above the form as well as give a little thank you message.
I currently have the following for the index.html page:
<?php
include "check.php";
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name:<br/> <input type="text" name="name" value="<?php echo $_POST['name']; ?>" size="30" /><br/><br/>
Email Address:<br/> <input type="text" name="email" value="<?php echo $_POST['email']; ?>" size="30"/> <br/><br/>
Company Name:<br/> <input type="text" name="companyName" value="<?php echo $_POST['companyname']; ?>" size="30" /> <br/><br/>
Message:<br/>
<textarea style="resize: none;" name="message" rows="5" cols="30"><?php echo $_POST['message']; ?></textarea>
<br/>
<input type="submit" name="Submit" />
</form>
When I submit the page it will run through the check.php file and verify all the data is good. It should then return the following If/Then statement if all the conditions are met.
if (!$errors) {
$mail_to = 'test#test.com';
$subject = 'New Mail from Form Submission';
$message = 'From: ' . $_POST['name'] . "\n";
$message .= 'Email: ' . $_POST['email'] . "\n";
$message .= 'Company Name: ' . $_POST['companyname'] . "\n";
$message .= "Message:\n" . $_POST['message'] . "\n\n";
mail($mail_to, $subject, $message);
echo "Thank you for your email!<br/><br/>";
$_POST = array(); //Clear form after submit
} else {
echo '<div style="color: red">' . $errors . '<br/></div>';
}
Is there anyway to add an auto-function during the "thank you" or "error" echos that will automatically bring the person back down to the contact form?
I hope I explained what I wanted to do correctly. If not please let me know and I will try to clarify it a bit better.
Add an ID to the form and append the anchor onto the form action URL
<form method="post" id="myform" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>#myform">
I am trying to add a form into my index page, so that when you click on submit it will automatically return to the form when the page reloads. Right now if there are any errors on the page it will display them right above the form as well as give a little thank you message.
I currently have the following for the index.html page:
<?php
include "check.php";
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name:<br/> <input type="text" name="name" value="<?php echo $_POST['name']; ?>" size="30" /><br/><br/>
Email Address:<br/> <input type="text" name="email" value="<?php echo $_POST['email']; ?>" size="30"/> <br/><br/>
Company Name:<br/> <input type="text" name="companyName" value="<?php echo $_POST['companyname']; ?>" size="30" /> <br/><br/>
Message:<br/>
<textarea style="resize: none;" name="message" rows="5" cols="30"><?php echo $_POST['message']; ?></textarea>
<br/>
<input type="submit" name="Submit" />
</form>
When I submit the page it will run through the check.php file and verify all the data is good. It should then return the following If/Then statement if all the conditions are met.
if (!$errors) {
$mail_to = 'test#test.com';
$subject = 'New Mail from Form Submission';
$message = 'From: ' . $_POST['name'] . "\n";
$message .= 'Email: ' . $_POST['email'] . "\n";
$message .= 'Company Name: ' . $_POST['companyname'] . "\n";
$message .= "Message:\n" . $_POST['message'] . "\n\n";
mail($mail_to, $subject, $message);
echo "Thank you for your email!<br/><br/>";
$_POST = array(); //Clear form after submit
} else {
echo '<div style="color: red">' . $errors . '<br/></div>';
}
Is there anyway to add an auto-function during the "thank you" or "error" echos that will automatically bring the person back down to the contact form?
I hope I explained what I wanted to do correctly. If not please let me know and I will try to clarify it a bit better.
Add an ID to the form and append the anchor onto the form action URL
<form method="post" id="myform" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>#myform">
I'm trying to build a form for wordpress. I've used plugins in the past but I need maximum control for some specific styling. I'm not very good with PHP yet, so am struggling trying to add checkboxes to the script.. I've removed my attempts and left the checkboxes in the html, but not in the PHP - can someone advise me of the best way to make any selected checkboxes visible in the email that is sent? Everything else works at the moment.
the html:
<form method="post" action="<?php bloginfo('template_directory'); ?>/contact.php">
<h3>Your Details</h3>
<div class="formrow">
<input type="text" name="Name" maxlength="99" id="fullname" placeholder="Name" />
<input type="email" name="Email" maxlength="99"placeholder="Email Address" />
<input type="tel" name="Phone" maxlength="25" placeholder="Phone Number" />
</div>
<h3>Project Type</h3>
<div class="formrow">
<fieldset>
<input type="checkbox" name="project1" value="Web">
<label for="type1">Web</label>
<input type="checkbox" name="project2" value="Digital">
<label for="type2">Digital</label>
<input type="checkbox" name="project3" value="Consultancy">
<label for="type3">Consultancy</label>
</fieldset>
</div>
<table align=center>
<tr><td colspan=2><strong>Contact us using this form:</strong></td></tr>
<tr><td>Department:</td><td><select name="sendto"> <option value="general#mycompany.com">General</option> <option value="support#mycompany.com">Support</option> <option value="sales#mycompany.com">Sales</option> </select></td></tr>
<tr><td>Company:</td><td><input size=25 name="Company"></td></tr>
<tr><td>Subscribe to<br> mailing list:</td><td><input type="radio" name="list" value="No"> No Thanks<br> <input type="radio" name="list" value="Yes" checked> Yes, keep me informed<br></td></tr>
<tr><td colspan=2>Message:</td></tr>
<tr><td colspan=2 align=center><textarea name="Message" rows=5 cols=35></textarea></td></tr>
<tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr>
<tr><td colspan=2 align=center><small>A <font color=red>*</font> indicates a field is required</small></td></tr>
</table>
</form>
the PHP:
<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";
$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Mailing List";
$fields{"Message"} = "Message";
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: noreply#YourCompany.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{print "Success";}
else
{print "We encountered an error sending your mail, please notify webmaster#YourCompany.com"; }
}
}
?>
Thanks! MC
An array of checkboxes would be most appropriate. By using [] in the checkbox names, PHP will automatically parse them into a native array.
<input type="checkbox" name="projects[]" value="Web">
<label for="type1">Web</label>
<input type="checkbox" name="projects[]" value="Digital">
<label for="type2">Digital</label>
<input type="checkbox" name="projects[]" value="Consultancy">
<label for="type3">Consultancy</label>
On the PHP side:
$selectedProjects = 'None';
if(isset($_POST['projects']) && is_array($_POST['projects']) && count($_POST['projects']) > 0){
$selectedProjects = implode(', ', $_POST['projects']);
}
$body .= 'Selected Projects: ' . $selectedProjects;
Outputs (if all checked)
Selected Projects: Web, Digital, Consultancy