Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Trying to grab value from a checkbox Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
tsignadze
Posts: 43
Joined: Tue Feb 21, 2023 12:14 am
Has thanked: 22 times
Been thanked: 1 time

Trying to grab value from a checkbox

Unread post by tsignadze »

Hi, I have an input field on a form and it is a checkbox, I am trying to run two different queries depending on if checkbox is ticked or not,
basically I want to input two different values into a table. I have tried with this method:

Code: Select all

$integrated = isset($_POST['Integrated']) ? 'Integrated' : 'NonIntegrated';

// Construct the SQL statement
$sql = "INSERT INTO your_table (Integrated) VALUES (?)";
did not work, I was trying to use nuGetValue, did not manage to grab it either.

Please someone help :) Thanks in advance!
tsignadze
Posts: 43
Joined: Tue Feb 21, 2023 12:14 am
Has thanked: 22 times
Been thanked: 1 time

Re: Trying to grab value from a checkbox

Unread post by tsignadze »

EDIT

got it working but there must be an easier and more elegant way

Code: Select all

define("checkboxChecked", 100);

$checkboxChecked = isset($_POST['Integrated']) && $_POST['Integrated'] == 'on';

if (checkboxChecked) {
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Trying to grab value from a checkbox

Unread post by kev1n »

Like this?

Code: Select all

$checkboxChecked = isset($_POST['Integrated']) && $_POST['Integrated'] === 'on';

if ($checkboxChecked) {

// ...
}
tsignadze
Posts: 43
Joined: Tue Feb 21, 2023 12:14 am
Has thanked: 22 times
Been thanked: 1 time

Re: Trying to grab value from a checkbox

Unread post by tsignadze »

Thanks for answer Kev1n.
Here is a video of my case:
https://streamable.com/a1jpji
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Trying to grab value from a checkbox

Unread post by kev1n »

Your code doesn't appear to match my suggestion.
tsignadze
Posts: 43
Joined: Tue Feb 21, 2023 12:14 am
Has thanked: 22 times
Been thanked: 1 time

Re: Trying to grab value from a checkbox

Unread post by tsignadze »

Sorry, missed $.

I have copy pasted your code now and it looks like this:
Also attached my object
Issue still remains. Always says Not ticked.

Code: Select all

define("checkboxChecked", 100);

$checkboxChecked = isset($_POST['Integrated']) && $_POST['Integrated'] === 'on';

if ($checkboxChecked) {
 $js = "nuMessage('Ticked');";
} else {
$js = "nuMessage('Not Ticked');";
}
nuJavaScriptCallback($js);
Screenshot 2023-04-25 120602.png
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Trying to grab value from a checkbox

Unread post by kev1n »

To pass values from JS to PHP, use nuSetProperty() in JS and nuGetProperty() in PHP.
If you use nuBuilder objects, just retrieve the value of a checkbox using the object id.

E.g.

Code: Select all

if ('#checkboxId#' == '1') {
  // checkbox checked
}
or

Code: Select all

if (nuGetProperty('checkboxId') == '1') {
  // checkbox checked
}
tsignadze
Posts: 43
Joined: Tue Feb 21, 2023 12:14 am
Has thanked: 22 times
Been thanked: 1 time

Re: Trying to grab value from a checkbox

Unread post by tsignadze »

THANK YOU! That was what I was trying to do :D

I will retry to run my queries but I think there is some other problem I have described in my other post and can not seem to understand. Hopefully I will be able to trace it, if not, will continue in other post.

Thank you very much!
Post Reply