I have an app, in which I have a button that opens a pop up window.
<li class="nav-item">
<a href="#" onclick="showSwal('addnotebook')" class="nav-link">
<i class="link-icon" data-feather="plus"></i>
<span class="link-title">
<p>Create notebook</p>
</span>
</a>
</li>
This then uses the sweet-alert js class to create the following pop-up form.
$(function() {
showSwal = function(type) {
'use strict';
if (type === 'addnotebook') {
swal.fire({
title: '<strong>Create a notebook</strong>',
html:
'<form class="forms-sample" method="post" action="/notebook/addnotebook">' +
'<div class="form-group">' +
'<input type="text" class="form-control" name="notebook_name" placeholder="Notebook name">' +
'</div>' +
'<div class="form-group">' +
'<button type="button" value="🍣" name="notebook_icon" class="btn btn-white btn-icon" onclick="🍣">' +
'<p>🍣</p>' +
'</button>' +
' ' +
'<button type="button" value="🍄" name="notebook_icon" class="btn btn-white btn-icon" onclick="🍄">' +
'<p>🍄</p>' +
'</button>' +
' ' +
'<button type="button" value="🈵" name="notebook_icon" class="btn btn-white btn-icon" onclick="🈵">' +
'<p>🈵</p>' +
'</button>' +
' ' +
'<button type="button" value="🍉" name="notebook_icon" class="btn btn-white btn-icon" onclick="🍉">' +
'<p>🍉</p>' +
'</button>' +
' ' +
'<button type="button" value="📕" name="notebook_icon" class="btn btn-white btn-icon" onclick="📕">' +
'<p>📕</p>' +
'</button>' +
' ' +
'<button type="button" value="📘" name="notebook_icon" class="btn btn-white btn-icon" onclick="📘">' +
'<p>📘</p>' +
'</button>' +
' ' +
'<button type="button" value="🔑" name="notebook_icon" class="btn btn-white btn-icon" onclick="🔑">' +
'<p>🔑</p>' +
'</button>' +
'<br>' +
'<button type="button" value="🥑" name="notebook_icon" class="btn btn-white btn-icon" onclick="🥑">' +
'<p>🥑</p>' +
'</button>' +
' ' +
'<button type="button" value="🍑" name="notebook_icon" class="btn btn-white btn-icon" onclick="🍑">' +
'<p>🍑</p>' +
'</button>' +
' ' +
'<button type="button" value="🌍" name="notebook_icon" class="btn btn-white btn-icon" onclick="🌍">' +
'<p>🌍</p>' +
'</button>' +
' ' +
'<button type="button" value="🍒" name="notebook_icon" class="btn btn-white btn-icon" onclick="🍒">' +
'<p>🍒</p>' +
'</button>' +
' ' +
'<button type="button" value="☕" name="notebook_icon" class="btn btn-white btn-icon" onclick="☕">' +
'<p>☕</p>' +
'</button>' +
' ' +
'<button type="button" value="🎓" name="notebook_icon" class="btn btn-white btn-icon" onclick="🎓">' +
'<p>🎓</p>' +
'</button>' +
' ' +
'<button type="button" value="👁" name="notebook_icon" class="btn btn-white btn-icon" onclick="👁">' +
'<p>👁</p>' +
'</button>' +
'</div>' +
'<button type="submit" class="btn btn-primary" autocomplete="off">Submit</button>' +
'</form>',
showCancelButton: true,
showConfirmButton: false,
cancelButtonText: 'Close',
})
}
The problem I am having is that when the form is submitted, the 4_POST value for 'notebook_icon' isn't submitted. Only the notebook name obtained from the input element.
I am presuming it is something to do with using a rather than a radio but I prefer the button option visually. I tried using the logic from this post: https://stackoverflow.com/a/5438236/6413592 but no luck as of yet.
If anyone could help me work out how to get the value of notebook_icon submitted with the form it would be appreciated.
Regards, Brad
This is my theory you may try this if it works. I assume you are using jquery because of $(function() {
. Insert this line in your html <input type="hidden" name="notebookIcon" value="" />
. Then create a function like
function selectIcon() {
$("input[name='notebookIcon']").val($(this).val());
}
Then on your button you may add the function on click
<button type="button" value="👁" name="notebook_icon" class="btn btn-white btn-icon" onclick="selectIcon">
Theoretically this is my approach. Hope this will guide you to your solution.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.