Laravel CRUD And CMS

Built Backend Administrator for real Internet / Intranet web application Easier , Faster , Proffessional

Showing posts with label LCRUD tips & Trick. Show all posts
Showing posts with label LCRUD tips & Trick. Show all posts

Contact Form in Laravel ( LCRUD V2 )

In this tutorial , we will trying to make contact form using default page CMS from LCRUD v2. and send message to email

Step 1 : Create new page

Next Go to : Tools -> PageCMS -> Create New
Copy following line code to your editor

<div class="page-content">

    <div class="page-header">
      <div class="page-title">
        <h3> Contact Us <small> Send any message to us </small></h3>
      </div>
    </div>

	
    <div class="breadcrumb-line">
      <ul class="breadcrumb">
        <li><a href="{{ URL::to('') }}">Home</a></li>
		<li><a href="{{ URL::to('?p=contactus') }}"> Contact Us </a></li>
        <li class="active"> Add </li>
      </ul>
	</div>  
	

{{ Form::open(array('url'=>'/saveContactForm', 'class'=>'form-vertical','parsley-validate'=>'','novalidate'=>' ')) }}
<div class="col-sm-6 well">
	@if(Session::has('message'))	  
		   {{ Session::get('message') }}
	@endif	
		
		<ul class="parsley-error-list">
			@foreach($errors->all() as $error)
				<li>{{ $error }}</li>
			@endforeach
		</ul>

		 <div class="form-group  ">
		<label for="ipt"> Your Name</label>
		  {{ Form::text('name', null,array('class'=>'form-control', 'placeholder'=>'', 'required'=>'Your Name'  )) }} 
		
	  </div> 			
						 					
	  <div class="form-group  ">
		<label for="ipt"> Your Email</label>
		
		  {{ Form::text('sender', null,array('class'=>'form-control', 'placeholder'=>'', 'required'=>'email'  )) }} 
		
	  </div> 					
	  <div class="form-group  ">
		<label for="ipt"> Subject </label>
		
		  {{ Form::text('subject', null,array('class'=>'form-control', 'placeholder'=>'Subject', 'required'=>'true'   )) }} 
		 
	  </div> 					
	  <div class="form-group  ">
		<label for="ipt"> Message </label>	
		{{ Form::textarea('message',null,array('class'=>'form-control', 'placeholder'=>'Type your message here', 'required'=>'true'   )) }}		 
	  </div>
	  <div class="form-group  ">
		<button type="submit" class="btn btn-primary ">  Send Form </button>		 
	  </div>	  
	  
</div>	   
{{ Form::close() }}

</div>
	  

Step 2 : Add Line code to routes

Next we need to create new routers to send data post from contact form

open your file protected/app/routes.php
copy this code :
Route::post('/saveContactForm',function()
{
	$this->beforeFilter('csrf', array('on'=>'post'));
	$rules = array(
			'name'		=>'required',
			'subject'	=>'required',
			'message'	=>'required|min:20',
			'sender'	=>'required|email'			
	);
	$validator = Validator::make(Input::all(), $rules);	
	if ($validator->passes()) 
	{
		
		$data = array('name'=>Input::get('name'),'sender'=>Input::get('sender'),'subject'=>Input::get('subject'),'notes'=>Input::get('message')); 
		Mail::send('emails.contact', $data, function($message) 
		{
			$message->to(CNF_EMAIL, CNF_APPNAME);
			$message->from(Input::get('sender'), Input::get('name'));
			$message->subject(Input::get('subject'));
		});	
		return Redirect::to('?p=contactus')->with('message', SiteHelpers::alert('success','Thank You , Your message has been sent !'));	
			
	} else {
		return Redirect::to('?p=contactus')->with('message', SiteHelpers::alert('error','The following errors occurred'))
		->withErrors($validator)->withInput();
	}	
});

Step 3 : Create mail template

Crete new file /protected/app/views/emails/contact.blade.php
Copy follwing code into new file

<!DOCTYPE html>
<html lang="en-US">
	<head>
		<meta charset="utf-8">
	</head>
	<body>
		<h2>Hello Admin , </h2>
		<p> You have new contact mail from  </p>
		<p>
			Email : {{ $sender }} <br />
			Name : {{ $name }}<br />
			Password : {{ $subject }}<br />
		</p>
		<p> Message : </p>
		<div>
			{{ $notes }}
		</div>
		
		<p> Thank You </p><br /><br />
		
		{{ CNF_APPNAME }} 
	</body>
</html>

Step 4 : Creating Menu

Now , you need create menu , so users will easy to accesss page contact .

Go To : Tools -> Menu
create new top menu named 'Contact Us ' and linked module to pages Contact
That's it guys , hopely this will help you .
GOOD LUCK !