How to send link with data flash message in codeigniter - html

I am new in codeigniter, I want to send link with data flash message in codeiniter how can I send the link?
this is my session message.
$this->session->set_flashdata('message', '<div id="message" class="alert alert-error">Your account is not active yet. Please activate your account.</div>');
I want to send link like that
<a href="<?php site_url().'/home/link';?></a>
how can I send, please help me to to this thanks in advance

In the controller create a link and assign it in a variable like this
function index(){
$link = site_url('home/link');
//Now assign this variable in flash and redirect
$this->session->set_flashdata('message', '<div id="message" class="alert alert- error">Your account is not active yet. Please activate your account.</div>');
$this->session->set_flashdata('link', $link);
redirect('othercontroller/method');
}

Related

"Send" Button linked to contact form

I have a contact form in my webpage with 3 areas of name, e-mail and text (no subject), and a send button underneath the form. What should I do to make the button work? I want the user to write their Name (which would eventually become the subject of the e-mail), their e-mail and the text they want to send and I want to receive the e-mail from them with their name as a subject, their e-mail and the text they would have written as the body of the e-mail. Plus, I don't want the button to open the users e-mail, like outlook etc. I want it to happent silently. So the outcome would be the user writes the text in the contact form, presses send and then I get the e-mail.
Thank you a lot, in advance!!!
Rafael.
First you have to learn php to make it work. You can not send mail using only form design.
Also, you have to upload your files on the server. Sending mail requires SMTP, which will not work on localhost.
HTML:
<form action="mail_handler.php" method="
FullName: <input type="text" name="full_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
mail_handler.php
<?php
if(isset($_POST['submit'])){
$to = "email#example.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$full_name = $_POST['full_name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $full_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $full_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $full_name . ", we will contact you";
}
?>
I suggest you to watch some tutorial before implementing it. You need to understand php before implementing it.

How do I submit a form without refreshing the current page?

I have a fairly basic email form
<form name="contactform" method="post" action="send_email.php" id="email_form">
<div class="ContactHeaders">Name</div>
<input type="text" name="Name" class="ContactBoxes" id="name"/><br/><br/>
<div class="ContactHeaders">Email</div>
<input type="email" name="Email" class="ContactBoxes"/><br/><br/>
<div class="ContactHeaders">Message</div>
<div style="width:100%">
<textarea name="Message" maxlength="1000"></textarea><br/>
</div>
<div style="width: 100%">
<input type="submit" class="Submitbtn" value="Submit">
</div>
</form>
Here's 'send_email.php'
<?php
ob_start();
include 'navbar.php';
ob_end_clean();
if(isset($_POST['Email'])) {
//declare variables
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Message = $_POST['Message'];
$complete = 0;
$email_to = "someone#example.com";
$email_subject = "Website Contact";
//check all forms are filled in correctly
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(preg_match($email_exp,$Email)) {
$complete++;
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(preg_match($string_exp,$Name)) {
$complete++;
}
if(strlen($Message) > 20) {
$complete++;
}
//send email if $complete = 4
if ($complete == 3){
if (get_magic_quotes_gpc()) {
$Message = stripslashes($Message);
}
$Message = $Message . "\n\n" . "From " . $Name;
$headers = 'From: '.$Email."\r\n".
'Reply-To: '.$Email."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $Message, $headers);
echo '<script>
alert("Thank you for contacting me. I will be in touch shortly");
top.location="index.php";
</script>';
}
else {
echo '<script>
alert("The form you submitted is invalid. Please ensure the following: \n You have provided a valid email address. \n Your phone number is entered correctly. \n The message box contains at least 20 characters.")
history.go(-1)
</script>';
}
}
?>
So my problem is that when the form submits to the php file, the browser loads the php file, runs the code and returns the result (It's not really a problem but it's something I don't want) It is then up to java to display the alert and go back one (in my code anyway). Is there a way to make it run the code in the background so the form runs the php file without having to go to it (if that makes sense) and return the result in the same window. I've obviously looked around and found loads of things about AJAX but I didn't really understand it and couldn't get it to work for me.
The reason for doing this is a little complicated but would make things much easier as far as user-friendliness goes for my site, as well as looking cleaner (going to a blank page and displaying an alert doesn't look very good).
Thanks in advance for any help you can offer me:)
$('.Submitbtn').click(function(e) {
e.preventDefault();
// do some form validation here
if form is valid { // from validation above
var formData = $('#email_form').serialize();
$.post('send_email.php',{data:formData});
} else {
alert('Form no good - fix it!');
return false;
}
});
Here's something you can start with. This is very basic but supplies the necessary foundation for beginning your AJAX adventure.
50 Excellent AJAX Tutorials

PHP Mail() Function Issue - Message field not getting sent (WordPress)

I know there are thousands and thousands of ways to utilize the PHP mail() function, but I am fairly new to PHP and could use some pointers to get me set in the right direction. I have a PHP mail function written into my WordPress driven site and it emails all the information (name, email, & phone) except for the message field. I've done my research on here as well as every PHP related site, but I would prefer to understand my specific issue so I can better understand what I'm writing. So with that said...here's the code:
<?php
function spamcheck($field)
{
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (isset($_POST['email']))
{
$mailcheck = spamcheck($_POST['email']);
if ($mailcheck==FALSE)
{
$submit_message = "Please input your information again.";
}
else
{
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
mail("emailaddress#gmail.com", "From: $name", "Email: $email", "Phone Number: $phone", "Message: $message");
$submit_message = "Thank you for your message";
}
}
?>
And the HTML...
<form name="message-me" id="contact-form" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST" enctype="multipart/form-data">
<div class="field-group">
<label>Name:</label><input type="text" name="name" id="form_name" />
</div>
<div class="field-group">
<label>Email:</label><input type="text" name="email" id="form_email" />
</div>
<div class="field-group">
<label>Phone:</label><input type="text" name="phone" id="form_phone" />
</div>
<div class="field-group">
<label>Message:</label><textarea rows="4" cols="31" name="message" id="form_message"></textarea>
</div>
<div class="field-group">
<input type="image" src="<?php bloginfo('template_directory'); ?>/images/Send-Message-Arrow.png" width="90" height="72" class="form-button" />
</div>
</form>
Any information would be greatly appreciated. As I mentioned, I'm still learning PHP and I really want to understand what I'm writing - not just blindly copying & pasting code all the time. Thanks!
Your SMTP want to be configured, first check up that
and
//Header Information for mail
$headers = "YOUR HEADERS INFORMATION HERE";
$msg="Email: $email<br/>Phone Number: $phone<br/>Message: $message";
mail("emailaddress#example.com", $subject, $msg, $headers);
Please have look at Documentation.
You need to provide parameters as
mail($to, $subject, $message, $headers);
Here you have provided "to" email address right.
So this might help you:
$message = $_POST['message'];
//Give mail a subject
$subject = "YOUR SUBJECT HERE";
//Header Information for mail
$headers = "YOUR HEADERS INFORMATION HERE";
mail("emailaddress#gmail.com", $subject, $message, $headers);
$submit_message = "Thank you for your message";
Enjoy!
Kindly read this manual with the directives and examples on it and you'll understand well what you are doing. Just take your time to read and understand well then start asking your questions from that point. Right now, you don't seem to understand even how the PHP mail() works. Read then get back so together you'll understand any solutions pointed out to you and you won't just copy and paste the solution without being able to solve it tomorrow.
http://php.net/manual/en/function.mail.php

Call controller from submit button with CodeIgniter

I'm loading a view and I'm passing 2 arguments from a controller like this:
$this->load->view('confirm_data_v', $data);
In confirm_data_v view I'm receiving $data that is an array. In confirm_data_v I have a Submit button, but I want to call another controller when I click on it. The code of the button in confirm_data_v is:
<div class = "container">
<div class="form-actions">
<button type="submit" class="btn btn-success">Save</button>
</div>
</div>
confirm_data_v is a view to confirm to the user the information that he gave, so when he clicks "Save" button, it calls the controller to save it to the database.
You cant normally call a controller directly from a view - but you dont need to just make the button redirect to or ajax call any url you like (mysite.com/myurl in this example) on the button click and then route that to your controller:
$route['myurl'] = 'mycontroller';
Your main options for storing the data between the two pages are either storing in a session or a cookie or echoing all their data into hidden form fields and re-posting it (if it's sensative data - go with the session option):
http://ellislab.com/codeigniter/user-guide/libraries/sessions.html
If for whatever you really do want to call a controller from a view you ca do it using wiredesigns modular codeigniter : https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc
But generally speaking this flies in the face of the mvc architecture and there is no need to do it.
What i have get from your question that you want to submit data to controller n#1 from the view after loading it from a controller n#2
if this is the case you can do
Method # 1
<?php echo form_open('controller/function'); ?>
<div class = "container">
<div class="form-actions">
<button type="submit" class="btn btn-success">Save</button>
</div>
</div>
<?php echo form_close(); ?>
and you can access any other value with $this->post->input('input_name')
Method # 2
use Anchor instead of submit button
<div class = "container">
<div class="form-actions">
<?php echo anchor('controller/function/parm','Save',array('class'=>'btn btn-success')); ?>
</div>
</div>
and in your controller for example
function confirm_save($parm)
{
//save to database
//redirect back to the next controller you want with success message for example using session flash data
//or load another view but URL will be still the same whatever suits your case
}

hyperlink to submit form on a different page

Is there a way how link can post data to a form on different page?
I imagine something like this, but this only open the requested page in new window (which is fine), but leaves the form on that page unfilled and also unsubmitted.
<?php echo '
<form action="http://www.someweb.cz/info2/dochazka/dochazka.php" method="post">
<input name="obdobi" type="hidden" value="'.$obdobi[Obdobi].'" />
<input name="kurs" type="hidden" value="'.$kurz_vybrany.'" />
<a target="_blank" style="text-decoration:none;"
href="http://www.someweb.cz/info2/dochazka/dochazka.php?doc=start.htm"
onclick="this.form.submit();">'.$pocet_lidi.'</a>
</form>'; ?>
I can slightly modify the "action" page code, but I'd like to keep the POST method.
This is easy to accomplish via cURL. See Example #2 on the manual page:
$ch = curl_init();
$data = array('obdobi' => $obdobi[Obdobi],
'kurs' => $kurz_vybrany);
curl_setopt($ch, CURLOPT_URL, 'http://www.someweb.cz/info2/dochazka/dochazka.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
You can change your javascript a bit, since the use of this is actually referring to the anchor itself and not the window, the form, etc. (thus calling this.form isn't actually capturing the form, it's giving an undefined error).
<form action="http://www.google.com" method="GET">
<input type="text" name="q" />
Submit
</form>
Note the parentNode reference after this. Note this demo.
I could not get either of suggested working. And because this was only a part of bigger project with deadline closing I decided to solve this by removing form, updating anchor to
<a target="_blank" style="text-decoration:none;"
href="http://www.someweb.cz/info2/dochazka/dochazka.php
?doc=start.htm&obdobi='.$obdobi[Obdobi].'&kurs='.$kurz_vybrany.'">'.$pocet_lidi.'</a>
and adding
<?php
if (isset($_GET[kurs])) $kurs = $_GET[kurs];
if (isset($_GET[obdobi])) $obdobi = $_GET[obdobi];
?>
to dochazka.php