-1

I have a set of checkboxes like these but was wondering how to approach checking them be default based on the values in the database.

<input type="checkbox" name = "others_post" id = "others_post" value="1"> Other's Posts <br/>
<input type="checkbox" name = "clients_post" id = "clients_post" value="1"> Cilent's Post <br/>
<input type="checkbox" name = "assigned_tasks" id = "assigned_tasks" value="1"> Task Assigned

This Perl script holds all the database values:

my $prefs = USystems::UserPrefs->new($user->userid);

I found something similar on a PHP thread which is exactly what I want but with Perl PHP checkbox set to check based on database value

I'm not very fimiliar with Perl so I dont know if there was syntax like the PHP example that you can insert into the checkboxes?

6
  • Where did you stuck, at retrieving data from database or adding checked into <input>? Commented Jul 1, 2014 at 15:05
  • I don't know how to check for a database entry and check the checkbox depending on the value in the database. I'm not sure if such a command exists like in PHP or what it looks like Commented Jul 1, 2014 at 15:06
  • First you'll need some database model and be familiar with it. Commented Jul 1, 2014 at 15:08
  • I added the Perl script that has all the information for the checkboxes from the database Commented Jul 1, 2014 at 15:09
  • Are you familiar with your framework and database model? Commented Jul 1, 2014 at 15:09

1 Answer 1

1

I think what you're looking for is something like this:

<input type="checkbox" name = "others_post" id = "others_post" value="1" <% if ($prefs->{OTHERS_POST} == 1){print 'checked'} %>> Other's Posts <br/>
<input type="checkbox" name = "clients_post" id = "clients_post" value="1" <% if ($prefs->{CLIENTS_POST} == 1){print 'checked'} %>> Cilent's Post <br/>
<input type="checkbox" name = "assigned_tasks" id = "assigned_tasks" value="1" <% if ($prefs->{ASSIGNED_TASKS} == 1){print 'checked'} %>> Task Assigned

Assuming that your $prefs has all the information you needed stored in it. Just put in an Perl if statement that checks to see if the database value is 1. If it is than print checked which will give the checkbox the checked attribute and check it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.