I am seeking some more advice on the way to handle this.
I have got one page with links to each admin member which when clicked takes their display name over. On the second page which is a form it takes that display names and populates the subject field with their display name. I need to grab the email address that is associated to that user too but use that as the email address the form on the second page gets sent to as currently my script can only send it to an email address I hard code into it.
So page one is:
<?php
$args1 = array(
'role' => 'committee',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$committee = get_users($args1);
foreach ($committee as $user) {
echo '
<a href="../contact-form?displayname=' . $user->display_name . '"><b style="font-size:18px;">
<tr>
<td style="padding: 10px;">' .$user->job_title .' - </td>
<td style="padding: 10px;">' .$user->display_name .'</td>
</tr></b></a><br><br>';
}
?>
Page two is:
<?php $displayname = $_GET['displayname'];?>
<form role="form" method="post" action="../mailuser.php">
<div class="form-group">
<input type="hidden" name="displayname" value="<?php echo $displayname ?>">
<input type="text" name="hp" class="hp" value="" alt="if you fill this field out then your email will not be sent">
</div>
<div class="form-group">
<label for="InputName">Your name</label>
<input type="name" class="form-control" id="InputName" placeholder="Enter your name" name="username">
</div>
<div class="form-group">
<label for="InputEmail">Email address</label>
<input type="email" class="form-control" id="InputEmail" placeholder="you#example.com" name="emailFrom">
</div>
<div class="form-group">
<label for="InputMsg">Message</label>
<textarea class="form-control" rows="8" id="InputMsg" placeholder="Please begin typing your message..." name="emailMessage"></textarea>
</div>
<button type="submit" class="btn btn-primary pull-right">Send</button>
</form>
And my send script has my email hard coded in as:
$mail->From = 'myemail#dummy.com';
So I need that be variable depending on which person you clicked on in the first place. It needs to be sent to both my hard coded email and also the persons email that is associated to them in the Wordpress user database.
Based on our comment discussion, you should be able to do something along the lines of the following on page two. Be sure to correct my email_address, I'm not sure if that's how get_users returns the email address or not.
<?php
$displayname = $_GET['displayname'];
$args1 = array(
'role' => 'committee',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$committee = get_users($args1);
$matchingEmail = false;
foreach ($committee as $user) {
if ( !$matchingEmail && $user->display_name == $displayname ) {
// great, we found our match
$matchingEmail = $user->email_address; // I don't know if email_address is right, double check this and modify if necessary
}
}
if ( $matchingEmail ) {
// only proceed if a matching email address is found
?>
<form role="form" method="post" action="../mailuser.php">
<div class="form-group">
<input type="hidden" name="displayname" value="<?php echo $displayname; ?>">
<input type="hidden" name="matchingEmail" value="<?php echo $matchingEmail; ?>">
<input type="text" name="hp" class="hp" value="" alt="if you fill this field out then your email will not be sent">
</div>
<div class="form-group">
<label for="InputName">Your name</label>
<input type="name" class="form-control" id="InputName" placeholder="Enter your name" name="username">
</div>
<div class="form-group">
<label for="InputEmail">Email address</label>
<input type="email" class="form-control" id="InputEmail" placeholder="you#example.com" name="emailFrom">
</div>
<div class="form-group">
<label for="InputMsg">Message</label>
<textarea class="form-control" rows="8" id="InputMsg" placeholder="Please begin typing your message..." name="emailMessage"></textarea>
</div>
<button type="submit" class="btn btn-primary pull-right">Send</button>
</form>
<?php
} else {
?>
<p>Something is wrong, I can't find your email address! Please try again.</p>
<?php
}
?>
Finally on page three, where you send the email, you can do something like:
<?php $mail->addAddress(stripslashes( $_POST["matchingEmail"] ) ); ?>
Related
I am getting this error,
A PHP Error was encountered
Severity: Notice
Message: Trying to get property 'post_title' of non-object.
I cannot get the form inputs to print on the page and cannot update. Please help!
So, I have tried to update each record and only artist users are able to do that. But I cannot figure out how to show the individual post on the form page. The records saves correctly and deletes but cannot update them.
Controller
function editpost($post_id)//Edit post page
{
if (!$this->session->Role =='member,artist')
{
redirect(base_url() . 'login');
}
$data['success'] = 0;
if( !empty($this->input->post('post_title')) ) {
$data['post_title'] = $this->input->post('post_title');
$data['post'] = $this->input->post('post');
$data['active'] = 1;
/* >> file attach */
View
<form action="<?= base_url()?>starter/editpost/" method="post" class="justify-
content-center" enctype='multipart/form-data'>
<div class="form-group">
<label class="sr-only">Title</label>
<input type="text" class="form-control" placeholder="Title"
name="post_title" value="<?php echo $post->post_title; ?>">
</div>
<div class="form-group">
<label class="sr-only">Description</label>
<textarea class="form-control" placeholder="Describe it" name="post" ><?
php echo $post->post; ?></textarea>
</div>
<div class="row py-4">
<div class="col-lg-6 mx-auto">
<!-- Upload image input-->
<!-- File Button -->
<div class="col-md-5">
<input name="main_img[]" type="file" accept="image/x-png,image/gif,image/jpeg">
</div>
<br>
<br>
<p style="padding-top: 15px"><span> </span><input class="submit" type="submit" name="update"
value="Publish" /></p>
</form>
use direct the variable because you are passing just values which you are posting from form.
//like :
//for post_title
<input type="text" class="form-control" placeholder="Title"
name="post_title" value="<?php echo $post_title; ?>">
// for description
textarea class="form-control" placeholder="Describe it" name="post" ><?
php echo $post; ?></textarea>
You don't need to pass the post data in controller you can get post data anywhere
<input type="text" class="form-control" placeholder="Title" name="post_title" value="<?php echo ($this->input->post('post_title')!='')?$this->input->post('post_title'):''; ?>">
I am having trouble integrating the "send OTP" function in my registration form. I was given an API from an SMS provider, but I do not know how to integrate it into my form. I need the user data to be recorded in my database after the verify the OTP. But how the verify process work? and how does the system would generate 6 digits random code to the user? I have been trying a different method and search online but none of that is working. Can anyone help?
Here is my form:
<div class="modal-body">
<form action="includes/signup.inc.php" method="POST" class="p-3">
<div class="form-group">
<label for="recipient-name" class="col-form-label">First Name</label>
<input type="text" class="form-control" placeholder="First Name" name="first" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Last Name</label>
<input type="text" class="form-control" placeholder="Last Name" name="last" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Username</label>
<input type="text" class="form-control" placeholder="Username" name="uid" required="" >
</div>
<div class="form-group">
<label for="recipient-name1" class="col-form-label">Date of Birth</label>
<input type="date" class="form-control" placeholder="dob" name="dob" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Email Address</label>
<input type="email" class="form-control" placeholder="Email" name="email" required="" >
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Password</label>
<input type="password" class="form-control" placeholder="Password" name="pass" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Confirm Password</label>
<input type="password" class="form-control" placeholder="Confirm Password" name="c_pass" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Are You Previously an Existing Member?</label>
<select class="form-control" id="recipient-name10" name="member">
<option>Yes</option>
<option>No</option>
</select>
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Where do you know about this membership?</label>
<select class="form-control" id="recipient-name11" name="outlet">
<option>The Metallic Kitchen # Golden Triangle Pelangi, JB</option>
<option>The Metallic Kitchen # Taman Mount Austin, JB</option>
<option>The Metallic Kitchen & Bar # Setapak Village, KL</option>
<option>None of the above</option>
</select>
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">OTP</label>
<input type="text" class="form-control" placeholder="OTP" name="otp" required="">
</div>
<div class="right-w3l mt-4 mb-3">
<input type="submit" class="form-control" value="Create account" name="submit">
</div>
</form>
</div>
and here is my sms provider API:
<?php
function sendSmsToEsms() {
$url = 'https://api.esms.com.my/sms/send';
// replace yourusername, yourpassword, and 60123456789 to suits your need
$data = array('user' => 'yourusername',
'pass' => 'yourpassword',
'to' => '60123456789',
'msg' => 'RM0.00 Hello from ESMS');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded; charset=utf-8",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
var_dump($result);
}
?>
here is my code for adding data into database:
<?php
if (isset($_POST['submit'])){
include_once 'db.php';
$first = mysqli_real_escape_string($conn,$_POST['first']);
$last = mysqli_real_escape_string($conn,$_POST['last']);
$uid = mysqli_real_escape_string($conn,$_POST['uid']);
$dob = mysqli_real_escape_string($conn,$_POST['dob']);
$email = mysqli_real_escape_string($conn,$_POST['email']);
$mobile = mysqli_real_escape_string($conn, $_POST['m_number']);
$pwd = mysqli_real_escape_string($conn,$_POST['pass']);
$member =mysqli_real_escape_string($conn, $_POST['member']);
$outlet = mysqli_real_escape_string($conn,$_POST['outlet']);
//ERROR HANDLERS
//CHECK FOR EMPTY FIELDS
//if(empty($first)||empty($last)||empty($uid)||empty($dob)||empty($email)||empty($mobile)||empty($pwd)||empty($member)||empty($outlet))
//{
//header("Location:../index.php?signup=empty");
//exit();
//}else{
//check if input characters are valid
//if(!preg_match("/^[a-zA-Z]*$/", $first)|| !preg_match("/^[a-zA-Z]*$/", $last)){
//header("Location:../signup.php?signup=invalid");
//exit();
//}else{
//check email
if(!filter_var($email,FILTER_VALIDATE_EMAIL)){
echo "<script>alert('Invalid Email,please register again.')</script>";
echo "<script>window.open('../index.php','_self')</script>";
exit();
}else{
//check if username is same
$sql = "SELECT * FROM users WHERE user_uid = '$uid'";
$result = mysqli_query ($conn,$sql);
$resultCheck = mysqli_num_rows ($result);
if ($resultCheck > 0) {
echo "<script>alert('Username has been taken, please register again.')</script>";
echo "<script>window.open('../index.php','_self')</script>";
exit();
}else{
//Hashing pwd
$hashedPwd = password_hash($pwd,PASSWORD_DEFAULT);
//INSERT THE USER INTO THE DATABASE
$sql = "INSERT INTO users (user_first,user_last,user_uid,user_dob,user_email,user_mobile,user_pwd,user_member,user_outlet) VALUES ('$first','$last','$uid','$dob','$email','$mobile','$hashedPwd','$member','$outlet');";
mysqli_query($conn,$sql);
echo "<script>alert('You have been Registered Successfully, Please login from our main page')</script>";
echo "<script>window.open('../index.php','_self')</script>";
exit();
}
}
}
else{
header("Location:../index.php");
exit();
}
?>
You should temporarily save user data into database as well as the generated OTP and also an extra column to indicate if user is validated. (I suggest to hash OTP before saving).
Later when the user tries the username and OTP for login, you should check entered data against the database. If user and OTP are correct, check that column to validate the registration. If OTP is incorrect you can leave that column for more tries (or delete user account or void the OTP or regenerate a new OTP bases on your opinion).
to generate a random number use mt_rand algorythm:
$password=mt_rand (10,100);
and use it in API as follow:
'pass' => $password,
I have an if isset statement that fires when my site receives approval from my merchant account api after a form is submitted. Everything seems to work except for the order details from the form getting written to my database. Here is the code for my form:
<form id="input-form" class="form-inline" action="" method="post">
<?php
if($error <> '') {
echo '<div class="alert alert-danger">',$error,'</div>';
}
?>
<div id="makepayment">
<div class="form-group">
<label for="order_fname">First Name</label>
<input class="form-control" style="width: 273px;" type="text" name="order_fname" id="order_fname" value="<?php echo $user['user_fname']; ?>" placeholder="First Name" />
</div>
<div class="form-group">
<label for="order_lname">Last Name</label>
<input class="form-control" style="width: 273px;" type="text" name="order_lname" id="order_lname" value="<?php echo $user['user_lname']; ?>" placeholder="Last Name" />
</div>
<div class="form-group">
<label for="order_phone">Primary Phone</label>
<input class="form-control" style="width: 273px;" type="text" name="order_phone" id="order_phone" value="<?php echo $user['user_phone']; ?>" placeholder="Phone Number" />
</div>
<div class="form-group">
<label for="order_cell">Cell Phone</label>
<input class="form-control" style="width: 273px;" type="text" name="order_cell" id="order_cell" value="<?php echo $user['user_cell']; ?>" placeholder="Cell Phone" />
</div>
<div class="form-group">
<label for="order_email">Email</label>
<input class="form-control" style="width: 273px;" type="text" name="order_email" id="order_email" value="<?php echo $user['user_email']; ?>" placeholder="Email Address" />
</div><br/>
<div class="clear"></div>
<div class="form-group" style="width:100% !important">
<label for="company_id">Property Information</label><br/>
<br/>
<input id="company_id" type="hidden" id="company_id" name="company_id" value="<?php echo $company['company_id']; ?>" />
<input id="company_name" type="hidden" id="company_name" name="company_name" value="<?php echo $company['company_name']; ?>" />
<div class="property">
<strong><?php echo $company['company_name']; ?></strong><br/>
<?php echo $company['company_street']; ?><br/>
<?php echo $company['company_city']; ?>, <?php echo $company['company_state']; ?> <?php echo $company['company_zip']; ?>
</div>
<div class="clear"></div>
</div><br/>
<div class="clear"></div>
<div class="form-group">
<label for="order_cc">Card Number</label>
<input class="form-control" type="text" name="ssl_card_number" id="ssl_card_number" style="width:100% !important" />
</div><br/>
<div class="clear"></div>
<div class="form-group">
<label for="order_code">Security Code</label>
<input class="form-control" style="width: 75px;" type="text" name="order_code" id="order_code" placeholder="ex:123" />
</div>
<div class="form-group">
<label for="order_customernumber">Customer Number</label>
<input class="form-control" type="text" style="width: 75px;" name="order_customernumber" id="order_customernumber" />
</div>
<div class="form-group">
<label for="order_invoicenumber">Invoice Number</label>
<input class="form-control" type="text" style="width: 75px;" name="order_invoicenumber" id="order_invoicenumber" />
</div>
<div class="form-group">
<label for="order_amount">Payment Amount</label>
$ <input class="form-control" type="text" style="width: 100px" name="ssl_amount" id="ssl_amount" />
</div>
<div class="form-group" style="width:100% !important">
<input class="btn btn-primary" type="submit" name="submit" value="Submit" />
</div>
</div>
</form>
Here is my if isset statement that fires if the api sends back an approval code. I know that part works because it does this action when I put in my card info and throws the proper error when I put in fake info.
if(isset($response['ssl_result_message']) && $response['ssl_result_message'] == "APPROVAL") {
//If transaction successful write to database
$userid = $session['user_id'];
$addOrderSQL = "
INSERT INTO orders (
user_id,
company_id,
order_fname,
order_lname,
order_phone,
order_cell,
order_email,
company_name,
order_customernumber,
order_invoicenumber,
order_amount
)
VALUES (
'$userid',
'$_POST[company_id]',
'$_POST[order_fname]',
'$_POST[order_lname]',
'$_POST[order_phone]',
'$_POST[order_cell]',
'$_POST[order_email]',
'$_POST[company_name]',
'$_POST[order_customernumber]',
'$_POST[order_invoicenumber]',
'$_POST[ssl_amount]'
)";
$firstname= $_POST['order_fname'];
$lastname = $_POST['order_lname'];
$invoice = $_POST['order_invoicenumber'];
$customernum = $_POST['order_customernumber'];
$property = $_POST['company_name'];
$ordertotal = $_POST['ssl_amount'];
/* -------------------------------------------------
Send Email to Administrator
------------------------------------------------- */
$to = "web#abcprintingink.com";
$subject = "Payment for Customer # ". $customernum;
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: webmaster#turfmastersct.com" . "\r\n" .
"Reply-To: webmaster#example.com" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
$message = "<p>A customer has completed a payment. Here are the payment details:</p>
Customer Name: ". $firstname ." ". $lastname ."<br/>
Customer #: ". $customernum ."<br/>
Invoice #: ". $invoice ."<br/>
Property: ". $property ."<br/>
Payment Amount: $". $ordertotal;
// Send it.
mail($to, $subject, $message, $headers);
//once executed queries redirect user
header('Location: /payments/orders.php');
exit;
}
elseif(isset($response['errorCode'])) {
$error = 'Your credit card has been declined';
}
else {
$error = 'Failed to process your payment';
}
The form is communicating with the api, I get a response from it and I can see the payment details post to my demo account. The isset statement fires, I get the email that it sends and it redirects me to the orders.php page like it's supposed to. It just doesn't write to the database. You can see my form and you can see the fields I am writing to my database. All those fields exist in the database itself. Am I missing something here?
You never run the $addOrderSQL query.
See mysqli_query() to do this.
Currently trying to modify a PHP contact form plugin. I need for users to be able to select which office department they'd like to send their email to, and have the contact info. go to that specific email address.
This plugin has an array in the PHP that allows for sending the contact form info. to multiple email addresses. The problem is that it sends the info. to EVERY email address in the array, and I need for users to be able to select just one address in the array to send the info. to.
Here is the array in the PHP:
$recipients = true;
if($recipients == true){
$recipients = array(
'Select department you are trying to reach*' => '',
"example1#gmail.com" => "Parts",
"example2#gmail.com" => "Sales",
"example3#gmail.com" => "Service",
);
foreach($recipients as $email => $name){
$mail->AddBCC($email, $name);
}
}
Here is the contact form's setup:
<form method="post" action="php/smartprocess.php" id="smart-form">
<div class="form-body">
<label class="field prepend-icon">
<input type="text" name="sendername" id="sendername" class="gui-input" placeholder="Enter name">
</label>
<label class="field prepend-icon">
<input type="email" name="emailaddress" id="emailaddress" class="gui-input" placeholder="Email address">
</label>
<label class="field">
<input type="text" name="captcha" id="captcha" class="gui-input sfcode" maxlength="6" placeholder="Enter CAPTCHA">
</label>
<label class="button captcode">
<img src="php/captcha/captcha.php?<?php echo time();?>" id="captchax" alt="captcha">
<span class="refresh-captcha"><i class="fa fa-refresh"></i></span>
</label>
<div class="result"></div>
<button type="submit" data-btntext-sending="Sending..." class="button btn-primary">Submit</button>
<button type="reset" class="button"> Cancel </button>
</form>
How would I add a dropdown form to this contact form, so someone could specifically choose the department (and coinciding email address from the array) they'd like to send the email to?
Help is much appreciated. I'm completely stumped about how to achieve this. For anyone curious, the plugin I'm using is called "Smart Forms", and they have a demo here: http://codecanyon.net/item/smart-forms/full_screen_preview/7254656.
Loop through your possible recipients on your form like this:
<?php
$recipients = array(
'' => 'Select department you are trying to reach*',
"example1#gmail.com" => "Parts",
"example2#gmail.com" => "Sales",
"example3#gmail.com" => "Service",
);
?>
<form method="post" action="php/smartprocess.php" id="smart-form">
<div class="form-body">
<label class="field prepend-icon">
<input type="text" name="sendername" id="sendername" class="gui-input" placeholder="Enter name">
</label>
<label class="field prepend-icon">
<input type="email" name="emailaddress" id="emailaddress" class="gui-input" placeholder="Email address">
</label>
<label class="field select-to-email">
<select name="to-emailaddress" id="toemailaddress" class="gui-input" placeholder="To Email address">
<?php foreach($recipients as $email => $name) : ?>
<option value="<?php echo $email; ?>"><?php echo $name; ?></option>
<?php endforeach; ?>
</select>
</label>
<label class="field">
<input type="text" name="captcha" id="captcha" class="gui-input sfcode" maxlength="6" placeholder="Enter CAPTCHA">
</label>
<label class="button captcode">
<img src="php/captcha/captcha.php?<?php echo time();?>" id="captchax" alt="captcha">
<span class="refresh-captcha"><i class="fa fa-refresh"></i></span>
</label>
<div class="result"></div>
<button type="submit" data-btntext-sending="Sending..." class="button btn-primary">Submit</button>
<button type="reset" class="button"> Cancel </button>
</form>
And then in the submission script smartprocess.php check and see if the submitted email address matches one of your recipients :
<?php
$recipients = array(
'' => 'Select department you are trying to reach*',
"example1#gmail.com" => "Parts",
"example2#gmail.com" => "Sales",
"example3#gmail.com" => "Service",
);
if( $_POST['to-emailaddress'] && $recipients[$_POST['to-emailaddress']]){
$name = $recipients[$_POST['to-emailaddress']];
$email = $_POST['to-emailaddress'];
$mail->AddBCC($email, $name);
}
?>
I am using wordpress and have created a list of users which are all links. Once clicked I need to carry the person email address over to a form where you can send an email to them directly. So it automatically populates to send with their email address. Currently I have looped through the users I want to send to but stuck on where to go from here:
<?php
$args1 = array(
'role' => 'committee',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$committee = get_users($args1);
foreach ($committee as $user) {
echo '
<a href="../contact-form?email=' . $user->user_email . '"><b style="font-size:18px;">
<tr>
<td style="padding: 10px;">' .$user->job_title .' - </td>
<td style="padding: 10px;">' .$user->display_name .'</td>
</tr></b></a><br><br>';
}
?>
I then need to send the persons email address who the user clicked on to this send page:
<form role="form" method="post" action="">
<div class="form-group">
<label for="InputName">Your name</label>
<input type="name" class="form-control" id="InputName" placeholder="Enter your name">
</div>
<div class="form-group">
<label for="InputEmail">Email address</label>
<input type="email" class="form-control" id="InputEmail" placeholder="you#example.com">
</div>
<div class="form-group">
<label for="InputMsg">Message</label>
<textarea class="form-control" rows="8" id="InputMsg" placeholder="Please begin typing your message..."></textarea>
</div>
<button type="submit" class="btn btn-primary pull-right">Send</button>
</form>
So if you click on a persons name it will take the user to a new page with a contact form, the person who they clicked on will then receive an email once the form is submitted. I just need some advice really on where to begin?
Just do this...
<td style="padding: 10px;">
<a href="urlwheretogetform?email=<?php echo $user->user_email;?>">
<?php echo $user->display_name;?>
</a>
</td>
Then on your other page...
if(isset($_GET['email'])){
$email = $_GET['email'];
}
// Do wahtever afterwards
In more detail
<?php if(isset($_GET)){
$email = $_GET['email'];
} else {$email='';};?>
<form role="form" method="post" action="">
//Your other fields
<div class="form-group">
<label for="InputEmail">Email address</label>
<input type="email" class="form-control" id="InputEmail" placeholder="you#example.com" value="<?php echo $email;?>">
</div>
<button type="submit" class="btn btn-primary pull-right">Send</button>
</form>