Hi, I searched all over the net for a clear solution but what solutions i have found just leave me with more questions and answered.

I have a multi step form using IF statements such as:

if(isset($_POST['2']))
{
echo "step2 data";
}else if(isset($_POST['3']))
{
echo "step3 data with text/ checkboxes fields";
echo"<input type='submit' name= 'register' value='Register'>";
}else if(isset($_POST['register']))
{
echo "sql data";
}else{
echo "step 1 data";
}

So in my step 3 I have 8 check boxes, I want the check boxes to insert into my database.

I was thinking that if i want to retrieve the check boxes again to let the user edit them or to show them later on in my webpage to a viewer as just a value and not a check box value to just store them as an int with '1' or '0' in my sql db

i have tried making my check boxes arrays but in my DB it gets inserted as s5:"Array" (i did a serialized approach).

I'm just guessing that because I'm using a multi step form that my values aren't being stored correctly somewhere.

Member Avatar for diafol

I wouldn't use serialize here. Keep the data and array separate if possible. If you change your form, your previously stored data will become meaningless.
The checkboxes can stay separate - each with its own id/name.

The question is - if you are using mutli-step forms, how do you propagate data from the first and intermediate steps to the end (or make it all available if the user decides to go back to amend data)?

You have a few solutions.
1. Use $_SESSION variables or cookies to keep all form data.
2. Use hidden fields in forms to keep data form previous ones.
3. Use js to hide/show different forms on the same page - therefore no new page when going from form to form, just show a new form - the data from previous forms will still be on the page, just hidden.
4. Ajax can be used to add data 'piecemeal' to a DB - so benefits of [3] but saved data [safe] all along the forms.

I would imagine that there are many more ways to skin this particular cat. Each has its advantages and disadvantages.

Personally I would use a simple js solution - but there again, could be an issue for non-js users. I don't like using js, but it definitely has its uses.

I wouldn't use serialize here. Keep the data and array separate if possible. If you change your form, your previously stored data will become meaningless.
The checkboxes can stay separate - each with its own id/name.

The question is - if you are using mutli-step forms, how do you propagate data from the first and intermediate steps to the end (or make it all available if the user decides to go back to amend data)?

You have a few solutions.
1. Use $_SESSION variables or cookies to keep all form data.
2. Use hidden fields in forms to keep data form previous ones.
3. Use js to hide/show different forms on the same page - therefore no new page when going from form to form, just show a new form - the data from previous forms will still be on the page, just hidden.
4. Ajax can be used to add data 'piecemeal' to a DB - so benefits of [3] but saved data [safe] all along the forms.

I would imagine that there are many more ways to skin this particular cat. Each has its advantages and disadvantages.

Personally I would use a simple js solution - but there again, could be an issue for non-js users. I don't like using js, but it definitely has its uses.

Ah right, i forgot to mention i used a hidden field in each step to carry over the data from previous steps.

So in yours solution I should not use an Array but individualize each checkbox item. So now my question is how or what code would be useful to me to ask distinguish if the item is checked or not checked, if checked to insert 1 into the db field or a 0 if not checked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.