Jump to content

CRUD Update page with Checkboxes


matthewlevering

Recommended Posts

Greetings All,

This place is always so gracious in assisting help to struggling noob developers, I thought i would give this a try. I ran into a wall with my first intranet application. We have a forms library. Which is a basic CRUD set up. A user logs into creates a form. Other users go to edit it. I can't seem to figure out how to have checkboxes/radio buttons populate with the data from my database and be editable. I have each of these checkboxes going in as an array[]. I cant seem to be able to figure out how to see if the option is selected and then show as checked. And if not checked have it appear not checked. I want the update form to appear exactly as the create form but populated with data it was populated with previously.

I think half my problem is being able to articulate the issue because google isn't yielding any good results. I would be extremely thankful and grateful to anyone who could point me in the right direction or send me to a good resource. Thank you for your Time.

 

Link to comment
Share on other sites

From a high-level view, it is usually helpful to parse a form first with javascript and make any adjustments you need to. This will help the PHP script that will process the form to enter the correct data. Usually if I have a series of radio buttons or a checkbox, I will have the javascript create a delimited list or set 1/0 values, respectively, in hidden form fields if necessary, before submitting the form.

 

Once you get the right data going to the PHP and it is able to insert the form data in the database, the other half is displaying that data. When the page that will display the form data loads, in some cases you load all the data with 1 SQL statement, or possibly more than one depending on the complexity of the data and how it is structured. If you store true/false values in your database as 1/0, then when PHP is building the page it needs to look for 1/0. It all depends on how you decide to store it. If you have a series of radio buttons, you would usually have a loop to create the HTML. It would set the id (<input type="radio" id="rad_0"... >, <input type="radio" id="rad_1"... >, etc.) of each <input> and as it's looping through, look for the selected value from the database. How you store that is your choice.

 

I hope this helps.

Edited by raphael75
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.