Contact us page receive information but not getting message - laravel

See the contact us page here.
This is view file of contact page.
<div class="section-title">
<h2>Contact</h2>
<h3><span>Contact Us</span></h3>
</div>
<div class="row" data-aos="fade-up" data-aos-delay="100">
</div>
<div class="row justify-content-center" data-aos="fade-up" data-aos-delay="100">
<div class="col-lg-9">
<form action="{{route('contact.store')}}" method="post" role="form" class="php-email-form">
#csrf
<div class="form-row">
<div class="col form-group">
<input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validate"></div>
</div>
<div class="col form-group">
<input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
<div class="validate"></div>
</div>
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" />
<div class="validate"></div>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
<div class="validate"></div>
</div>
<div class="mb-3">
<div class="loading">Loading</div>
<div class="sent-message">Your message has been sent. Thank you!</div>
</div>
<div class="text-center"><button type="submit">Send Message</button></div>
</form>
</div>
</div>
</div>
</section><!-- End Contact Section -->
This is Controller code of contact us page.
public function store(Request $request)
{
Contact::create([
'name' => $request->name,
'email' => $request->email,
'subject' => $request->subject,
'message' => $request->message,
]);
\Session::flash('flash_message','successfully saved.');
return redirect()->back();
}
Problem is i have a one page theme so i redirect same page after contact us details fill. But contact details here stay , not blank....what is it solution?

don't use return back try by using return view
return view('viewName');

Because your browser will do "back" when you use your code:
return redirect()->back();
Change to use this:
return redirect()->route('your_back_route_name');
I think that will work as reload page.
When it's not work, i think it is about your browser auto fill.
So, set you input value is empty when load.
<input value="" />

Related

Comment Store in Laravel Redirecting to Home Page

I have a comment form in a page when I submit this form it's redirecting to the home page.
Routes
Route::get('/post/{slug}', 'API\PostController#show')->name('post.show');
Route::post('/post/{slug}', 'API\PostController#addComment')->name('post.comment');
Route::get('{path}',"HomeController#index")->where( 'path', '([A-z\d-\/_.]+)?' );
Blade
<form action="{{route('post.comment',$currentPost->slug)}}" method="POST">
<div class=" row blog-form">
{{csrf_field()}}
<div class="frm_grp col-md-6">
<input type="text" name="name" placeholder="Name"/>
</div>
<div class="frm_grp col-md-6">
<input type="text" name="email" placeholder="Email"/>
</div>
<div class="frm_grp col-md-12">
<input type="text" name="website" placeholder="Website"/>
</div>
<div class="frm_grp col-md-12">
<textarea name="message" placeholder="Message"></textarea>
</div>
<div class="frm_grp col-md-12">
<input type="submit" value="Post Comment"/>
</div>
</div>
</form>

What are all the steps I have to do to get my bootstrap email form working?

What should I do to get my form working? My website and everything is set up. I just can't get my form working. Can I do it from rdp? or firezila server?
<form>
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Name">
</div>
</div>
<div class="col-md-6 col-sm-6">
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Email address">
</div>
</div>
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="form-group">
<textarea name="message" id="message" required="required" class="form-control" rows="3" placeholder="Message"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Submit Request</button>
</div>
</div>
</div>
</div>
</form>
Submit your form to php and send the mail, ulter the code as below and consider adding a subject field too:
<form name="nameforform" action="thephpfilename.php" method="POST">
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Name" name="name">
</div>
</div>
<div class="col-md-6 col-sm-6">
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Email address" name="email">
</div>
</div>
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="form-group">
<textarea name="message" id="message" required="required" class="form-control" rows="3" placeholder="Message" name="message"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Submit Request</button>
</div>
</div>
</div>
</div>
</form>
Then create a php file (eg: thefilename.php) [besure to change the action attribute of the form element to that of the created php file's name.
The php file should have the following code:
<?php
$to = $_POST['email'];
$subject = '';
$message = $_POST['message'];
$headers = 'From:'. $_POST['name'] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
It would work, be sure to tweak your server's settings and also specify more info in the question next time.
Lastly how it works,
On submitting the form the browser sends a get/post request to the file specified on the action attribute of the form element. The php
file handles the request and does the needy. The data is stored with
reference to the name attribute of the input and textarea elements.
The data can be stored as arrays too. Here we use the php's mail()
function to send the mail using appropriate headers. HTML or bootstrap
cannot send mail independently without server intervention.
Be sure to comment for more info and other help, enjoy out there.

Octobercms successful mail send returns empty alert

I am a newbie to Laravel and OctoberCMS.
I have successfully set up an info request form that sends me an email via Mailgun when submitted. Submission is handled by an AJAX handler.
The problem I have is that the process opens an alert box with an empty array on the form page.
Here is the page: http://imageweaversmarketing.com/
Click on 'CONTACT' in the top-right to move to the form.
Here is the partial with the form:
<div class="row">
<div class="col-lg-12">
<form data-request="onInfoRequest" name="sentMessage" id="contactForm" novalidate="">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" required="" data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" required="" data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required="" data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" id="message" required="" data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" class="btn btn-xl">
Send Message
</button>
</div>
</div>
</form>
</div>
Here is the PHP AJAX:
use Illuminate\Support\Facades\Mail;
public function onInfoRequest() {
$data = ['name' => 'test from function'];
Mail::send('mail.inforequest', $data, function ($message) {
$message->to('fake#hidden.com', 'Roger Creasy');
});
}
I appreciate any help.
I see you haven't used the data-request-success handler. That's necessary to show the output when mail is successful. Here's how I do it
function onSend()
{
// Collect input
$name = post('name');
$email = post('email');
// Form Validation
$validator = Validator::make(
[
'name' => $name,
'email' => $email
],
[
'name' => 'required',
'email' => 'required|email'
]
);
if ($validator->fails())
{
$messages = $validator->messages();
throw new ApplicationException($messages->first());
}
// All is well -- Submit form
$to = System\Models\MailSettings::get('sender_email');
$params = compact('name','email');
Mail::sendTo($to, 'temp.website::mail.newrequest', $params);
return true;
}
And on the form side I used
<form class="form-horizontal" data-request="onSend" data-request-success="alert('We have recieved your email.. we\'ll get back to you shortly')">
<div class="form-group">
<label class="col-md-4 control-label" for="name">Name</label>
<div class="col-md-5">
<input id="name" name="name" type="text" placeholder="Name" class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="email">Email</label>
<div class="col-md-5">
<input id="email" name="email" type="text" placeholder="Email ID" class="form-control input-md" required="">
</div>
</div>
</form>
So basically all you need is to add a data-request-success for it to work. Enjoy!
I had to get this completed. So, I gave up on a solution within October.
I am posting what I did as a workaround, in case it is helpful to someone else.
What I did is create a route resource, and direct it to a controller to handle the form. basically I went to the Laravel base structure and handled the form through its MVC.

Stripe form not submitting

My stripe form is not submitting. When I press submit it goes to page cannot be displayed. I replaced the route code to resolve to an echo "test"; and the post request shows the echo. Any help would be appreciated. This code is from a tutorial http://www.sitepoint.com/selling-downloads-stripe-laravel/
Route
Route::get('/buy/{id}', function($id)
{
$download = Download::find($id);
return View::make('buy', array('download' => $download));
});
Route::post('/buy/{id}', function($id)
{
Stripe::setApiKey(Config::get('laravel-stripe::stripe.sk_test_aaaaaaaaaaaaaaaaaaaaaaaa'));
$download = Download::find($id);
$token = Input::get('stripeToken');
// Charge the card
try {
$charge = Stripe_Charge::create(array(
"amount" => $download->price,
"currency" => "gbp",
"card" => $token,
"description" => 'Order: ' . $download->name)
);
// If we get this far, we've charged the user successfully
Session::put('purchased_download_id', $download->id);
return Redirect::to('confirmed');
} catch(Stripe_CardError $e) {
// Payment failed
return Redirect::to('buy/'.$id)->with('message', 'Your payment has failed.');
}
});
View
#extends('layouts.default')
#section('content')
<h1>Your Order</h1>
<h2>{{ $download->name }}</h2>
<p>£{{ ($download->price/100) }}</p>
<form action="" method="POST" id="payment-form" role="form">
<input type="hidden" name="did" value="{{ $download->id }}" />
<div class="payment-errors alert alert-danger" style="display:none;"></div>
<div class="form-group">
<label>
<span>Card Number</span>
<input type="text" size="20" data-stripe="number" class="form-control input-lg" />
</label>
</div>
<div class="form-group">
<label>
<span>CVC</span>
<input type="text" size="4" data-stripe="cvc" class="form-control input-lg" />
</label>
</div>
<div class="form-group">
<label>
<span>Expires</span>
</label>
<div class="row">
<div class="col-lg-1 col-md-1 col-sm-2 col-xs-3">
<input type="text" size="2" data-stripe="exp-month" class="input-lg" placeholder="MM" />
</div>
<div class="col-lg-1 col-md-1 col-sm-2 col-xs-3">
<input type="text" size="4" data-stripe="exp-year" class="input-lg" placeholder="YYYY" />
</div>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg">Submit Payment</button>
</div>
</form>
#stop

How to fill out login form with mechanize in Ruby?

Below the form that I wish to fill with Mechanize; already tried the model commonly used (example there: Using Ruby and Mechanize to fill in a remote login form mystery); but didn't succeed.
<form method="post" action="/sso/login.php" id="form-login-page">
<div id="form-login-container-page" style="color:red;text-align:center;width:100%;margin:10px 0"></div>
<input type="hidden" name="minimalist" value="1">
<input type="hidden" name="SSO_Context" value="/pdf/telecharger2.php?pdfpf=&pdfg=%2Fpdf%2Ftelecharger.php%3Fdir%3DJOURNAL%26file%3D20140603.pdf">
<div class="clear"> </div>
<label>Email<span>*</span></label>
<div class="insc-saisie">
<input class="insc-saisie-champ" type="text" id="login-page" name="login" value="">
</div>
<div class="clear"> </div>
<label>Mot de passe<span>*</span></label>
<div class="insc-saisie">
<input class="insc-saisie-champ" type="password" id="password-page" name="password" value="">
</div>
<div class="clear"> </div>
<label><input type="checkbox" unchecked=""></label>
<div class="insc-saisie">Se souvenir</div>
<div class="clear"> </div>
<label> </label>
<div class="insc-saisie">
Mot de passe oublié ?
</div>
<div class="clear"> </div>
<label> </label>
<div class="insc-saisie">
<input class="b-connexion" type="image" src="/img/trans.gif">
</div>
<div class="clear"> </div>
<div class="clear"> </div>
<label><span>*</span></label>
<div class="insc-saisie">Saisie obligatoire</div>
<div class="clear"> </div>
</form>
Here my attempt
form = agent.page.parser.css('form')[1]
agent.page.forms[1]["login"] = "my_login"
agent.page.forms[1]["password"] = "my_password"
agent.page.forms[1].submit
The following code should work:
page = agent.get("your_page_url")
form = page.form_with(:id => 'form-login-page')
form.login = "my_login"
form.password = "my_password"
form.submit

Resources