How to properly structure this multi step form? - php

I have a page create_conference.blade.php to create new confereces. In this page there is a multi step form:
in the 1st step asks the user for general conference information
in the 2nd asks for a description for the conference creator
in the 3rd aks the user for the registration types for the conference
The way the form should work is: the user enter the information for the first step then click “go to step 2”, then in step 2, the user enters that step 2 specific information and click “go to step 3”. Finally, in step 3, the user enter that step 3 specific information and also clicks in “Store” to submit the information and so the conference is created.
Do you know how to properly handle this multi step form logic with laravel? Im not having success in structuring this.
HTML:
<!-- So, the page has 3 step: General Info, Conference Creator Info and Registration Types) -->
#extends('app')
#section('content')
<div class="container nopadding py-4">
<h1 class="h5 text-center">Create Conference</h1>
<div class="row">
<div class="col-12">
<ul class="nav nav-pills registration_form_list" role="tablist">
<li class="">
<a class="nav-link active" href="#step1" data-toggle="tab" role="tab">
Step1<br><small>General Information</small></a>
</li>
<li class="disabled">
<a class="nav-link" href="#step2" data-toggle="tab" role="tab">
Step 2<br><small>Conference Creator Info</small></a>
</li>
<li class="disabled">
<a class="nav-link" href="#step3" data-toggle="tab" role="tab">
Step 3<br><small>Registration Types</small></a>
</li>
</ul>
<!-- STEP 1 - General Confenrece Information-->
<form method="post" class="clearfix" action="conference/store">
{{csrc_field()}}
<div class="tab-content registration_body bg-white" id="myTabContent">
<div class="tab-pane fade show active clearfix" id="step1" role="tabpanel" aria-labelledby="home-tab">
<form method="post" class="clearfix">
<div class="form-group">
<label for="conference_name" class="text-heading h6 font-weight-semi-bold">Conference Name </label>
<input type="text" name="conference_name" class="form-control" id="conference_name">
</div>
<div class="form-row">
<div class="form-group col-lg-6">
<label for="conference_categories" class="text-heading h6 font-weight-semi-bold">Conference Categories</label>
<select id="tag_list" name="conference_categories" multiple class="form-control" id="conference_categories">
<option>IT</option>
</select>
</div>
</div>
<div class="form-group">
<label for="address" class="text-heading h6 font-weight-semi-bold">Address</label>
<input type="text" name="conference_address" class="form-control" >
</div>
<div>
<button type="button" href="#step2" data-toggle="tab" role="tab"
class="btn mr-2 btn-primary btn next-step">
Go To Step 2
</button>
</div>
</form>
</div>
<!-- STEP 2 - Conference creator Information-->
<div class="tab-pane fade clearfix" id="step2" role="tabpanel" aria-labelledby="profile-tab">
<form method="post" class="clearfix">
<div class="form-row">
<div class="form-group">
<label for="conference_creator_description" class="text-heading h6 font-weight-semi-bold">Description</label>
<textarea name="conference_creator_description" id="conference_creator_description" class="form-control" rows="3"></textarea>
</div>
<button type="button" href="#step1" data-toggle="tab" role="tab"
class="btn mr-2 btn-primary btn next-step">
Go Back To Step 1
</button>
<button type="button" href="#step3" data-toggle="tab" role="tab"
class="btn mr-2 btn-primary btn next-step">
Go To Step 3
</button>
</form>
</div>
<!-- STEP 3 - Registration Types-->
<div class="tab-pane clearfix fade" id="step3" role="tabpanel" aria-labelledby="contact-tab">
<form method="post" class="clearfix">
<div class="form-group">
<label for="registration_type_name" class="text-heading h6 font-weight-semi-bold">Registration Type Name</label>
<input type="text" name="registration_type_name" class="form-control" id="registration_type_name">
</div>
<div class="form-group col-md-6">
<label for="registration_type_capacity" class="text-heading h6 font-weight-semi-bold">Capacity</label>
<input type="text" class="form-control" name="registration_type_name" id="registration_type_capacity">
</div>
<div class="form-group">
<button type="button" href="#step2" data-toggle="tab" role="tab"
class="btn mr-2 btn-primary btn next-step">
Go Back To Step 2
</button>
<button type="submit" data-toggle="tab" role="tab"
class="btn mr-2 btn-primary btn next-step">
Store
</button>
</div>
</form>
</div>
</div>
</form>
</div>
</div>
</div>
Laravel:
I created a ConferenceController
Then add to the form an action (action="conference/store")
Then I also created a route:
Route::post(‘/createConference, [
‘uses’ => ‘ConferenceController#store’
‘as’ => conference.store’
]
But when I enter some info and submit the form it appears:
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message.

Wrong action url
Route::post(‘/createConference,[‘uses’=>‘ConferenceController#store’,‘as’=>conference.store’]);
Set form's action to route's name and add crsf field
<form action="{{route('conference.store')}}" method="post">
{{ csrf_field() }}

Related

Show content for an specific item in Laravel

I have a list of Pipelines and their stages, I need tho show the stages of each pipelines when these are clicked. The thing is that I don't want to show them all, just the ones that are clicked...
I have this code on my project, the thing is that with this it shows all of the stages of all of the pipelines, and I need just show the stages of the clicked pipeline. How can I dynamically link each other
<div class="panel-body" id="body-pipelines">
#foreach($pipelines as $key => $pipeline)
<div class="pipelines">
<div class="col-md-3 row">
<div class="col-md-12 col-sm-12 col-xs-12 p-t-10 p-b-10" id="pipelines-sidebar">
<i class="fas fa-lg fa-fw m-r-10 fa-{{$pipeline->icon}}"></i>
<span>{{$pipeline->name}}</span>
</div>
</div>
<div class="col-md-8">
<div class="row float-right">
<button class="btn"><i class="fas fa-plus-circle" id="agregar"></i></button>
</div>
<div class="sortable box row">
#foreach ($pipeline->stages as $stage)
<div class="stages txt username m-b-10" id="stages-{{$stage->id}}" style="background: {{$stage->color}}" onclick="javascript:;" data-type="text">{{$stage->name}} <div class="delete-stage float-right"><button class="btn btn-danger"><i class="fas fa-trash" id="eliminar"></i></button></div></div>
#endforeach
</div>
</div>
</div>
#endforeach
</div>

Form is not being posted back

I am currently working on create-post view of dashboard of my blogging site. I have used Aero template.
#extends('Dashboard.Layout.master')
#section('content')
<section class="content blog-page">
<div class="body_scroll">
<div class="block-header">
<div class="row">
<div class="col-lg-7 col-md-6 col-sm-12">
<ul class="breadcrumb">
<li class="breadcrumb-item"><i class="zmdi zmdi-home"></i>Computer Bitches</li>
<li class="breadcrumb-item">Blog</li>
<li class="breadcrumb-item active"> New Post</li>
</ul>
<button class="btn btn-primary btn-icon mobile_menu" type="button"><i class="zmdi zmdi-sort-amount-desc"></i></button>
</div>
<div class="col-lg-5 col-md-6 col-sm-12">
<button class="btn btn-primary btn-icon float-right right_icon_toggle_btn" type="button"><i class="zmdi zmdi-arrow-right"></i></button>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<form method="post" action="{{route('dashboard.store.post')}}">
#method('post')
#csrf
<div class="card">
<div class="body">
<div class="form-group">
<input type="text" class="form-control" placeholder="Enter Blog title" />
</div>
<div class="form-group">
<select class="mdb-select md-form form-control" multiple searchable="Search here..">
<option>LARAVEL</option>
<option>GIT</option>
<option>AWS</option>
<option>REACT</option>
<option>PHP</option>
<option>JAVASCRIPT</option>
<option>CSS3</option>
<option>HTML5</option>
<option>WEB TECHNOLOGIES</option>
<option>JQUERY</option>
</select>
</div>
<div class="form-group">
<textarea id="editor" name="editor " class="form-control" rows="10" placeholder="Enter your Content">
</textarea>
</div>
</div>
</div>
<input type="submit" class="btn btn-success" value="Save"/>
</form>
</div>
</div>
</div>
</div>
</section>
#endsection
#section('scripts')
ClassicEditor
.create( document.querySelector( '#editor' ) )
.then(editor => {
document.getElementById('editor').innerHTML = editor.getData();
})
.catch( error => {
console.error( error );
} );
#endsection
I have tried all the possible ways, from posting back throuh jquery to removing elements and putting them back but no lock yet. It's been 10 hours still trying but I don't think I will find the solution. Thank you guys in advance for any leads.

How to submit my form without reloading with ajax?

I would like to submit my form without reloading the page after pressing the submit button.But everything I have tried doesn't worked.Can you give me some help with ajax code please?
My view:
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header" style="border-bottom: none;padding: 0px 0px;right: 15px;top: 10px;position:relative">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="container">
<div class="row">
<section>
<div class="wizard col-md-6" >
<div class="wizard-inner">
<div class="connecting-line"></div>
<ul style="border:none !important" class="nav nav-tabs" role="tablist" style="margin: 0px auto">
<li role="presentation" class="active">
<a href="#step1" data-toggle="tab" aria-controls="step1" role="tab" title="Step 1">
<span class="round-tab">
<i class="icon-pencil"></i>
</span>
</a>
</li>
<li role="presentation" class="disabled">
<a href="#step2" data-toggle="tab" aria-controls="step2" role="tab" title="Step 2">
<span class="round-tab">
<i class="icon-note"></i>
</span>
</a>
</li>
<li role="presentation" class="disabled">
<a href="#step3" data-toggle="tab" aria-controls="step3" role="tab" title="Step 3">
<span class="round-tab">
<i class="icon-check"></i>
</span>
</a>
</li>
</ul>
</div>
<form role="form" action="/career_report" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
#if(Sentinel::check())
<input type="hidden" name="user_id" value="{{ Sentinel::check()->id }}">
<input type="hidden" name="username" value="{{ Sentinel::check()->username }}">
#endif
<input type="hidden" name="subject" value="{{url()->current()}}">
<input type="hidden" name="user_id_posted" value="{{ $event->user->id }}">
<input type="hidden" name="username_posted" value="{{ $event->user->username }}">
<input type="hidden" name="career_solution_id" value="{{ $event->id}} ">
<div class="tab-content">
<div class="tab-pane active" role="tabpanel" id="step1">
<h3 style="text-align: center">Why are you reporting this content :</h3>
<ul style="list-style: none">
<li>
<input type="radio" id="box-9" name="why_reporting" value="Spam">
<label for="box-9">Spam</label>
<div class="check"></div>
<small id="box-9-s" style="display: none">I consider this content irrelevant and annoying.</small>
</li>
<li>
<input type="radio" id="box-10" name="why_reporting" value="Fake Profile">
<label for="box-10">Fake Profile</label>
<div class="check"><div class="inside"></div></div>
<small id="box-10-s" style="display: none">This content was posted by way of a profile that clearly doesn't represent a real person.
</small>
</li>
<li>
<input type="radio" id="box-11" name="why_reporting" value="Advertising">
<label for="box-11">Advertising</label>
<div class="check"><div class="inside"></div></div>
<small id="box-11-s" style="display: none">This content is or contains advertising.
</small>
</li>
<li>
<input type="radio" id="box-12" name="why_reporting" value="Untrustworthy source">
<label for="box-12">Untrustworthy source</label>
<div class="check"><div class="inside"></div></div>
<small id="box-12-s" style="display: none">This content is from an untrustworthy source and contains unverifiable statements.
</small>
</li>
<li>
<input type="radio" id="box-13" name="why_reporting" value="Defamatory">
<label for="box-13">Defamatory</label>
<div class="check"><div class="inside"></div></div>
<small id="box-13-s" style="display: none">The reported content is insulting or defamatory to me or other people.
</small>
</li>
<li>
<input type="radio" id="box-14" name="why_reporting" value="Violence or pornography">
<label for="box-14">Violence or pornography</label>
<div class="check"><div class="inside"></div></div>
<small id="box-14-s" style="display: none">This content contains violence or pornography.
</small>
</li>
<li>
<input type="radio" id="box-15" name="why_reporting" value="Violates IP rights">
<label for="box-15">Violates IP rights</label>
<div class="check"><div class="inside"></div></div>
<small id="box-15-s" style="display: none">This content includes third-party content (e.g. an image) posted under their own name.
</small>
</li>
<li>
<input type="radio" id="box-16" name="why_reporting" value="Promotes structural distribution measures">
<label for="box-16">Promotes structural distribution measures</label>
<div class="check"><div class="inside"></div></div>
<small id="box-16-s" style="display: none">This content promotes a chain distribution system, multilevel selling or pyramid sales.
</small>
</li>
<li >
<input type="radio" id="box-17" name="why_reporting" value="Other">
<label for="box-17" id="other">Other</label>
<div class="check"><div class="inside"></div></div>
<div class="form-group" id="mydiv" style="display: none">
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3" placeholder="Please let us know why you're reporting this content:
" style="resize: none" name="why_reporting_message"></textarea>
</div>
</li>
</ul>
<ul class="list-inline pull-right">
<li><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></li>
<li><button style="background-color: #18ba9b;border-color: white" type="button" class="btn btn-primary next-step">Save and continue</button></li>
</ul>
</div>
<div class="tab-pane" role="tabpanel" id="step2">
<h3>Why would you like to report this?</h3>
<div class="form-group">
<textarea class="form-control" id="exampleFormControlTextarea1" rows="5" style="resize: none" placeholder="
Please let us know why you're reporting this content:" name="additional_message"></textarea>
</div>
<ul class="list-inline pull-right">
<li><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></li>
<li><button type="button" class="btn btn-default prev-step">Previous</button></li>
<li><button style="background-color: #18ba9b;border-color: white" type="submit" class="btn btn-primary btn-info-full next-step" id="save">Submit your report</button></li>
</ul>
</div>
<div class="tab-pane" role="tabpanel" id="step3">
<h2 class="title-box-v2" style="font-size: 17px !important;line-height: 35px">We'll look into this as soon as possible. Thanks for helping us improve the quality of content on Workstickers.</h2>
<p style="text-align: center">You have successfully completed all steps.Flagged content and users are reviewed by Workstickers staff 24 hours a day, seven days a week to determine whether they violate Community Guidelines. Accounts are penalized for Community Guidelines violations, and serious or repeated violations can lead to account termination.
</p>
<div style="text-align: center;margin-top: 50px">If you've changed your mind - Cancel report</div>
</div>
<div class="clearfix"></div>
</div>
</form>
</div>
</section>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- END MY MODAL -->
<script>
$(document).on("click",".save",function(){
e.preventDefault(); //Prevent page from submiting
$(document).on("click", ".save", function() {
$.ajax({
type: "post",
url: 'career_report',
data: $(".why_reporting").serialize(),
success: function(store) {
},
error: function() {
}
});
});
});
</script>
My route
Route::post('career_report', 'CareerSolutionController#careerReport');
My controller
public function careerReport(requ $request)
{
$report = \App\Reports::create([
'user_id' => $request['user_id'],
'username' => $request['username'],
'user_id_posted' => $request['user_id_posted'],
'username_posted' => $request['username_posted'],
'career_solution_id' =>$request['career_solution_id'],
'subject' =>$request['subject'],
'why_reporting' =>$request['why_reporting'],
'why_reporting_message' =>$request['why_reporting_message'],
'additional_message' =>$request['additional_message'],
]);
if($report != ""){
flash('Career solution report submited', 'success');
}else{
flash('Career solution report', 'warning');
}
return Redirect::back();
}
What I have tried:
I tried to adapt this to my code, but without success. Trying to submit my laravel form without the page refreshing
you can use Jquery Ajax .
$('#yourFormId').submit(function(e){
e.preventDefault();
var data = $(this).serialize();
$.ajax({
method:'POST',
url:'your process file URL',
data:data,
success: function (result) {
// do something with result
}
});
});
in this example i have used $.Ajax method
when you use e.preventDefault(); your form will not be submitted . so you can manually submit it in Javascript . in the submit event , you use Ajax and it sends your form data to your process file and then returns the result . without refreshing page or redirecting .

How to remember last tab used with PHP form submit?

I have a form inside one of many tabs, but when it submits it goes back to the first one.
<div class="panel panel-primary">
<div class="panel-heading">
<div class="panel-control">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#tab" aria-expanded="true">Tab1</a></li>
<li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">Tab2</a></li>
</ul>
</div>
<h3 class="panel-title">Text</h3>
</div>
<div class="panel-body">
<div class="tab-content">
<div id="tab" class="tab-pane fade active in">
<form class="form-group" method="post" action="#" enctype="multipart/form-data">
<input class="form-control description" name="description[]" placeholder="Description here">
<input class="btn btn-primary btn-lg" name="update" type="submit" value="Save">
</form>
</div>
<div id="tab-2" class="tab-pane fade">
</div>
</div>
</div>
</div>
PHP fetches form and update database and redirects:
if(isset($_POST['update'])){
//database update
//current url + tab
header("Location: {$url->getCurentUrl()}#tab3");
}
The link is correct, but the tab won't update using the #tab in url, anyone have alternative methods to set active tab to last tab used?
Use this below code ...might be helpful to you as it's for me so...
$('a[data-toggle="tab"]').on('show.bs.tab', function(e) {
localStorage.setItem('activeTab', $(e.target).attr('href'));
});
var activeTab = localStorage.getItem('activeTab');
if(activeTab){
$('#action-tab a[href="' + activeTab + '"]').tab('show');
}

Unable to post value from bootstrap-wysiwyg text editor in codeigniter

I am using bootstrap-wysiwyg text editor in my form, and I am not able to post value in controller
View :
<form id="demo-form2" action="<?php echo base_url();?>admin/post/add" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="middle-name" class="control-label col-md-3 col-sm-3 col-xs-12">Post Details<span style="color:red"> <?php echo form_error('details'); ?></span></label>
<div class="col-md-8 col-sm-8 col-xs-12">
<div id="alerts"></div>
<div class="btn-toolbar editor" data-role="editor-toolbar" data-target="#editor">
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" title="Font"><i class="fa fa-font"></i><b class="caret"></b></a>
<ul class="dropdown-menu">
</ul>
</div>
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" title="Font Size"><i class="fa fa-text-height"></i> <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a data-edit="fontSize 5">
<p style="font-size:17px">Huge</p>
</a>
</li>
<li>
<a data-edit="fontSize 3">
<p style="font-size:14px">Normal</p>
</a>
</li>
<li>
<a data-edit="fontSize 1">
<p style="font-size:11px">Small</p>
</a>
</li>
</ul>
</div>
</div>
<div id="editor" class="editor-wrapper"></div>
<textarea id="descr" name="descr" style="display:none;"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-sm-8 col-xs-12 col-md-offset-3"> <button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
And my controller
print_r($_POST); exit;
On searching, I have founded answers like
Solution for this issue
But I don't know how to implement this in my condition. I am getting all the other values expect value in text-area.
Thanks in advance
This will get the editor contents and replace the value of editor_contents on the submit.
<form name="your_form" method="post" onSubmit="document.your_form.editor_contents.value = $('#editor').html()">
<textarea name="editor_contents" style="display:none;"></textarea>
<input type="submit" name="submit">
</form>
And you can access it on PHP like $_POST['editor_contents']
This like passing your data on hidden fields.
Try this
<script type="text/javascript">
$(document).on('submit','#demo-form2',function(){
var editor = CKEDITOR.instances['descr'];
document.getElementById('descr').value = editor.getData();
})
</script>

Categories