mardi 28 mars 2017

Getting laravel to scroll down after submit

I've created a contact form and I would like my page to scroll down to display my function.

My getContactUsForm function

public function getContactUsForm(){

    $menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
    $menu = Menu::where('id', 1)->orWhere('title', 'home')->firstOrFail(); // 30 is the home id
    $layout = $menu->type;

    $content = Content::where('id', 1)->orWhere('title', 'home')->firstOrFail();

    $main_menu = Menu::all();
    $contact_bottom = Contact::all();
    $social_media = SocialMedia::all();
    $seo = Seo::all();


    //Get all the data and store it inside Store Variable
    $data = Input::all();

    //Validation rules
    $rules = array (
        'name' => 'required|alpha',
        'email' => 'required|email',
        'message' => 'required'
    );

    //Validate data
    $validator = Validator::make ($data, $rules);

    //If everything is correct than run passes.
    if ($validator -> passes()){

        //Send email using Laravel send function
        Mail::send('templates::emails.contact', $data, function($message) use ($data)
        {
        //email 'From' field: Get users email add and name
        $message->from($data['email'] , $data['name']);
        //email 'To' field: cahnge this to emails that you want to be notified.
        $message->to('info@webkrunch.co.za', 'Webkrunch Info')->subject('contact request');

        });
        return redirect()->back()->with('success', '<b>Thank you!</b> Your message has been sent successfully');
    }else{
        //return contact form with errors
        return view('open::index', compact('menus_child', 'main_menu', 'content', 'contact_bottom', 'social_media', 'seo'))->with('menu', $menu, $main_menu, $content, $contact_bottom, $social_media)->withErrors($validator);
    }
}

and I've done a redirect back with a success message.

my js

$('#contact_form').submit(function(){
  $('html, body').stop().animate({
        scrollTop: $("#contact").offset().top

    }, 600);
});

but my js doesn't work after the page was submitted.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire