This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
LilEssam
Hi I would like to make a form in front-end that allows the visitor to create a new section I have this form:
<form data-request="onAdd" data-request-update="result: '#result'">
<div class="input-group">
<label for="name">Section name: </label>
<input class="form-control" name="name" placeholder="test section" />
</div>
<div class="input-group">
<br>
<button class="btn btn-primary">Add</button>
</div>
</form>
and here's my function:
use Essam\News\Models\Section;
use Essam\News\Models\Post;
function onAdd()
{
$name = post('name');
$check = Section::where('name', $name)->first();
if($check){
$this['result'] = "Error";
}else{
$section = new Section;
$section->name = $name;
$section->save();
$this['result'] = "Added";
}
}
and my result partial is very simple:
{{ result }}
Now the script works correctly but when I add a new record using this form sometimes it inserts two records and other times it inserts only one record.
1-1 of 1