Good Day everyone who has an idea on how to get the message and add address using input fields.
public function send()
{
$this->load->library('phpmailer_lib');
try
{
$mail=$this->phpmailer_lib->load();
$mail->setFrom('rayjayabejuela#gmail.com','Rayjay');
$mail->addAddress('flutterrun#gmail.com'); // I want the input data came from the input fields of email.
$mail->Subject="Subject Matter";
$mailContent=''; I want the input data came from the input fields came from the message.
$mail->Body=$mailContent;
if($mail->send()){
echo "Email has been set";
}
}
catch(Exception $e){
echo $mail->ErrorInfo;
}
}
This is my view page page
<form action="<?php echo base_url(); ?>email/send" method="post">
<br>
<input type="email" name="email" class="form-control" placeholder="Enter Email" required>
<br>
<textarea name="message" class="form-control" placeholder="Enter message here" required></textarea>
<br>
<button type="submit" class="btn btn-primary">Send Message</button>
</form>
public function send()
{
$this->load->library('phpmailer_lib');
try
{
$email = $this->input->post('email');
$message = $this->input->post('message');
$mail=$this->phpmailer_lib->load();
$mail->setFrom('rayjayabejuela#gmail.com','Rayjay');
$mail->addAddress($email); // I want the input data came from the input fields of email.
$mail->Subject="Subject Matter";
$mailContent=$message; I want the input data came from the input fields came from the message.
$mail->Body=$mailContent;
if($mail->send()){
echo "Email has been set";
}
}
catch(Exception $e){
echo $mail->ErrorInfo;
}
}
i'll try to help you.
You can make a change from :
$mail->addAddress('flutterrun#gmail.com');
to this :
$mail->addAddress($_POST['email']);
You can do this to mailcontent / messages too.
Related
I am working with code igniter and got stuck when i compare the user input with the already existing values in database. I have a form from where i get a user input. The form is as follows:
<form method="post" action="my_controller/my_method">
<label>Mark :</label>
<input type="text" name="avg_mark"><br>
<label> Message </label>
<input type="text" name = "message"><br>
<input type="submit" class="btn btn-info" value="send message">
</form>
In my_controller/my_method
function my_method{
$avg_mark =$this->input->post('avg_mark');
$message = $this->input->post('message');
echo $avg_mark;
}
when i echo $avg_mark iam getting the value. But problem arises when i take that value inside a foreach loop.
foreach($students as $row){
echo $avg_mark;
}
the page is blank and shows nothing which means iam not getting the input value inside the loop. And i tried this too inside the loop. Still the result is same.
foreach($students as $row){
echo $this->input->post('avg_mark');
}
What should i do to get the value inside a foreach loop.
First check that variable empty or not. Then you pass it in to foreach loop:-
if (!empty($students)) {
foreach($students as $row){
echo $avg_mark;
}
}
thank you in advance for any help given. I'm just learning jQuery and AJAX and would appreciate some help with the following code. All validation rules work, the form submits and the page does not refresh. The problem is that the form values are not clearing/resetting to default after the submit has triggered. Thoughts?
**********EDITED to include HTML markup*************
<div id="form">
<h1 class="title">Contact Us</h1><!-- title ends -->
<p class="contactUs">Ask about our services and request a quote today!</p><!-- contactUs ends -->
<div id="success"><p>Your message was sent successfully. Thank you.</p></div>
<p id="required">* All fields required.</p>
<form name="form" id="contactMe" method="post" action="process.php" onSubmit="return validateForm()" enctype="multipart/form-data">
<input class="txt" type="text" maxlength="50" size="50" required name="name" value="<?php echo $_GET['name'];?>" placeholder="Name" />
<div id="nameError"><p>Your name is required.</p></div>
<input class="txt" type="text" maxlength="50" size="50" required name="email" value="<?php echo $_GET['email'];?>" placeholder="Email Address" />
<div id="emailError"><p>A valid email address is required.</p></div>
<textarea name="message" rows="6" cols="40" required placeholder="Message"></textarea>
<div id="messageError"><p>A message is required.</p></div>
<input type="hidden" maxlength="80" size="50" id="complete" name="complete" placeholder="Please Keep This Field Empty" />
<input type="submit" value="SUBMIT" name="submit" />
<input type="reset" value="RESET" name="reset" />
</form>
</div><!-- form ends -->
//hide form submit success message by default. to be shown on successfull ajax submission only.
$(document).ready(function() {
if ($('#success').is(':visible')){
$(this).hide()
}
});
//form validation
function validateForm() {
//name
var a=document.forms["form"]["name"].value;
if (a==null || a=="")
{
$('#nameError').fadeIn(250);
return false;
}
//email address
var c=document.forms["form"]["email"].value;
var atpos=c.indexOf("#");
var dotpos=c.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=c.length)
{
$('#emailError').fadeIn(250);
return false;
}
//message
var e=document.forms["form"]["message"].value;
if (e==null || e=="")
{
$('#messageError').fadeIn(250);
return false;
}
}//javascript form validation ends
//ajax submit and clear form on success
$(function () {
$('form').on('submit', function (e) {
var myForm = validateForm();
if (myForm == false){
e.preventDefault();//stop submission for safari if fields empty
}
else{
$.ajax({
type: 'post',
url: 'process.php',
data: $('form').serialize(),
success: function () {
$('#success').fadeIn(250);
if ($('#nameError, #emailError, #messageError').is(':visible')) {
$('#nameError, #emailError, #messageError').fadeOut(250);
}
$('form')[0].reset();//clear form after submit success
}//success ends
});//ajax ends
e.preventDefault();//prevent default page refresh
}//else ends
});//submit ends
});//function ends
//if reset button is clicked AND messages displayed, remove all form html messages
$(document).ready(function() {
$('#form input[type="reset"]').click(function() {
if ($('#success, #nameError, #emailError, #messageError').is(':visible')) {
$('#success, #nameError, #emailError, #messageError').fadeOut(250);
}
});
});
By giving your input id="reset" and/or name="reset", you effectively overwrote the form.reset method of the form because by doing so you made form.reset target the reset button. Simply give it a different id and name value.
Never give elements name or id attributes that equal the name of a property of a dom node.
I want to know how I can upload an image and save its name in a database when using Codeigniter.
I am using a simple form tag for this, like:
<form action="./myaccount/index/" method="post" enctype="multipart/form-data">
<div>
<label for="pic">picture</label>
<input type="file" id="pic" name="pic" />
</div>
<input id="register-btn" name="register" type="submit" value="ok" class="input-text custom-btn">
</form>
Here's my controller:
public function index() {
$user = new User($_SESSION['user_id']);
if($this->input->post()){
$user->pic = $this->input->post('pic');
if($this->input->post('password') == $this->input->post('confirm')){
$user->password=md5(sha1(sha1($this->input->post('password'))));
$user->save();
$this->data['success'] = "done";
}else{
$this->errors[] = "error";
}
}
$this->data['user'] = $user;
$this->data['errors'] = $this->errors;
$this->template->set_layout('myaccount');
$this->template->build('profile',$this->data);
}
I checked the manual but I can't understand what they are doing.
Im' trying to make a controler function for this that will insert all the values in the database and also upload the image file.
i have a contact form on http://daniloportal.com/NPC2/contact.html
Now this ajax script works very well, but i have other contact forms that i would like to use the same script for. so when i tried to create mulitple instances of the script, i noticed it stopped working because the ID name is not specifically ajax-contact-form. take a look at the code:
<form id="ajax-contact-form" action="">
<input type="text" name="name" value="Name *" title="Name *" />
<input type="text" name="email" value="Email " title="Email *" />
<input type="text" name="email" value="Email *" title="Email *" />
<textarea name="message" id="message" title="Message *">Message *</textarea>
<div class="clear"></div>
<input type="reset" class="btn btn_clear" value="Clear form" />
<input type="submit" class="btn btn_blue btn_send" value="Send message!" />
<div class="clear"></div>
</form>
and heres the JS
$("#ajax-contact-form").submit(function() {
var str = $(this).serialize();
$.ajax({
type: "POST",
url: "contact_form/contact_process.php",
data: str,
success: function(msg) {
// Message Sent - Show the 'Thank You' message and hide the form
if(msg == 'OK') {
result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
$("#fields").hide();
} else {
result = msg;
}
$('#note').html(result);
}
});
return false;
});
Now if i were to switch that ID name on both and MATCH them, the script stops working- Theoretically it should work- not sure whats wrong with this.
as always any help is appreciated, thanks!
If you are trying to access two elements with the same id with jQuery - nothing gonna happen. Each element must have a unique identifier, otherwise you should use classes.
However, can you give us the markup of another form?
I have to build a custom module in which i have added a custom fields on to the customer registration page a fields like alternate mail id,mobile number & etc which is successfully getting saved in my database & here i have to implement a one more feature that is
on registration page when user enters his email id that should check for the domain name.
Ex: my domain name is abc & the users mail address will be user#abc.com
& the users of "abc.com" should only has to get register into my online store
How do i restrict the users of other domain apart from abc.com
Please help me in doing this.....
You can use regular expression for this. Just use the below function:
function checkEmail($email) {
if(preg_match("/^([a-zA-Z0-9\._-])*#abc.com$/",$email)){
return true;
}
return false;
}
Code Edited
<script type="text/javascript">
function validateEmail(elementValue){
var emailPattern = /^[a-zA-Z0-9._-]+#abc.com$/;
return emailPattern.test(elementValue);
}
function checkForm(){
var emailId = document.getElementById('email_address').value;
if(! validateEmail(emailId)) {
alert("Email id is not valid");
}
}
</script>
<div class="input-box"style="width: 550px;">
<input type="text" name="email" id="email_address" value="<?php echo $this->htmlEscape($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
<input type="submit" value="Click here" onclick="checkForm()" />(There will be be an submit button put the onclick event in it)
</div>