Added save function to save button
This commit also improves how forms are parsed by PHP by passing them as arrays, therefore making them easier to process. Note: One of the files contains a debug statement that will be removed in the next commit
This commit is contained in:
parent
dd3213e918
commit
2df5bf144d
|
@ -12,4 +12,9 @@ class FormController extends Controller
|
|||
return view('dashboard.administration.forms');
|
||||
}
|
||||
|
||||
public function saveForm(Request $request)
|
||||
{
|
||||
dd($request->all());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ $(document).ready(function() {
|
|||
var intId = (lastField && lastField.length && lastField.data("idx") + 1) || 1;
|
||||
var fieldWrapper = $("<div class=\"fieldwrapper mb-5\" id=\"field" + intId + "\"/>");
|
||||
fieldWrapper.data("idx", intId);
|
||||
var fName = $("<input name=\"fieldNameID" + intId + "\" type=\"text\" class=\"fieldname form-control\" placeholder=\"Field name...\" />");
|
||||
var fType = $("<select name=\"fieldTypeID" + intId + "\" class=\"fieldtype custom-select\"><option value=\"nil\" disabled>Field type</option></option><option value=\"checkbox\">Checkbox</option><option value=\"textbox\">Textbox</option><option value=\"textarea\">Multi-line answer</option></select>");
|
||||
var fName = $("<input name=\"fieldID" + intId + "[]\" type=\"text\" class=\"fieldname form-control\" placeholder=\"Field name...\" />");
|
||||
var fType = $("<select name=\"fieldID" + intId + "[]\" class=\"fieldtype custom-select\"><option value=\"nil\" disabled>Field type</option></option><option value=\"checkbox\">Checkbox</option><option value=\"textbox\">Textbox</option><option value=\"textarea\">Multi-line answer</option></select>");
|
||||
var removeButton = $("<button type=\"button\" class=\"btn btn-sm btn-danger mt-3\"><i class=\"fa fa-minus\"></i></button>");
|
||||
removeButton.click(function() {
|
||||
$(this).parent().remove();
|
||||
|
@ -16,3 +16,7 @@ $(document).ready(function() {
|
|||
$("#buildyourform").append(fieldWrapper);
|
||||
});
|
||||
});
|
||||
|
||||
function save() {
|
||||
document.getElementById('formbuilder').submit();
|
||||
}
|
||||
|
|
|
@ -18,9 +18,15 @@
|
|||
|
||||
<div class="card-body">
|
||||
|
||||
<fieldset id="buildyourform">
|
||||
<legend>Form Builder</legend>
|
||||
</fieldset>
|
||||
<form id="formbuilder" action="{{route('saveForm')}}" method="POST">
|
||||
|
||||
@csrf
|
||||
|
||||
<fieldset id="buildyourform">
|
||||
<legend>Form Builder</legend>
|
||||
</fieldset>
|
||||
|
||||
</form>
|
||||
|
||||
<div class="mt-4">
|
||||
<input type="button" value="New Field" class="add btn btn-success" id="add" />
|
||||
|
@ -31,7 +37,7 @@
|
|||
|
||||
<div class="card-footer text-center">
|
||||
|
||||
<button type="button" class="btn btn-success">Save Form</button>
|
||||
<button onclick="save()" type="button" class="btn btn-success">Save Form</button>
|
||||
|
||||
</div>
|
||||
|
||||
|
|
|
@ -67,7 +67,11 @@ Route::group(['middleware' => 'auth'], function(){
|
|||
|
||||
Route::resource('positions', 'VacancyController');
|
||||
|
||||
Route::resource('forms', 'FormController');
|
||||
Route::get('forms', 'FormController@index')
|
||||
->name('showFormBuilder');
|
||||
|
||||
Route::post('forms/save', 'FormController@saveForm')
|
||||
->name('saveForm');
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue