Ion_Cannon Posted August 23, 2009 Share Posted August 23, 2009 This has to be another fairly simple one that I am just brain-dead with. I have a form that is basically a checkout process, on the screen there is a check box that says "Please Agree to Terms and Conditions" or whatever, another section allows the user to choose a shipping method. when they choose a shipping method it calls a procedure that recalcs shipping without problems, only thing is, if the check box is marked, when the screen refreshes it is now unmarked, doesn't keep the value. How do I make it so on refresh or redirect, it keeps the value if it was previously checked? Anyone got any examples? thanks a million. -ic Quote Link to comment https://forums.phpfreaks.com/topic/171560-checkbox-values-disappear/ Share on other sites More sharing options...
Ion_Cannon Posted August 24, 2009 Author Share Posted August 24, 2009 bumb. anyone got an idea? Quote Link to comment https://forums.phpfreaks.com/topic/171560-checkbox-values-disappear/#findComment-904994 Share on other sites More sharing options...
sawade Posted August 24, 2009 Share Posted August 24, 2009 <td> <input type="checkbox" name="array[]" id="checkboxid" multiple="multiple" value="VALUE" <?php if (isset ($_POST[array]) && in_array ("VALUE", $_POST[array])) echo ' checked="checked"'; ?> /> <label for="checkboxid">VALUE</label> </td> Give this a try. It's what I use in my forms. Quote Link to comment https://forums.phpfreaks.com/topic/171560-checkbox-values-disappear/#findComment-905096 Share on other sites More sharing options...
Ion_Cannon Posted August 24, 2009 Author Share Posted August 24, 2009 <td> <input type="checkbox" name="array[]" id="checkboxid" multiple="multiple" value="VALUE" <?php if (isset ($_POST[array]) && in_array ("VALUE", $_POST[array])) echo ' checked="checked"'; ?> /> <label for="checkboxid">VALUE</label> </td> Give this a try. It's what I use in my forms. Thank you much, but when i do a refresh it is still clearing out. Do I need to do something with session managment for the form? Quote Link to comment https://forums.phpfreaks.com/topic/171560-checkbox-values-disappear/#findComment-905332 Share on other sites More sharing options...
mikesta707 Posted August 24, 2009 Share Posted August 24, 2009 that would only work if you were to submit that to itself, and not on refresh. How exactly does your recalculation work? what makes your page refresh? try posting some code? also I you have to surround indexes of associative arrays with single quotes so the above code should be <td> <input type="checkbox" name="array[]" id="checkboxid" multiple="multiple" value="VALUE" <?php if (isset ($_POST['array']) && in_array ("VALUE", $_POST['array'])) echo ' checked="checked"'; ?> /> <label for="checkboxid">VALUE</label> </td> Idk if that makes a different though Quote Link to comment https://forums.phpfreaks.com/topic/171560-checkbox-values-disappear/#findComment-905336 Share on other sites More sharing options...
sawade Posted August 24, 2009 Share Posted August 24, 2009 also I you have to surround indexes of associative arrays with single quotes so the above code should be <td> <input type="checkbox" name="array[]" id="checkboxid" multiple="multiple" value="VALUE" <?php if (isset ($_POST['array']) && in_array ("VALUE", $_POST['array'])) echo ' checked="checked"'; ?> /> <label for="checkboxid">VALUE</label> </td> Idk if that makes a different though That is correct. The quotes got cut off during editting for the post. As for the value staying during a refresh, as long as the form as been submitted once, you can refresh the page and they hold. Quote Link to comment https://forums.phpfreaks.com/topic/171560-checkbox-values-disappear/#findComment-905340 Share on other sites More sharing options...
Ion_Cannon Posted August 24, 2009 Author Share Posted August 24, 2009 that would only work if you were to submit that to itself, and not on refresh. How exactly does your recalculation work? what makes your page refresh? try posting some code? also I you have to surround indexes of associative arrays with single quotes so the above code should be <td> <input type="checkbox" name="array[]" id="checkboxid" multiple="multiple" value="VALUE" <?php if (isset ($_POST['array']) && in_array ("VALUE", $_POST['array'])) echo ' checked="checked"'; ?> /> <label for="checkboxid">VALUE</label> </td> Idk if that makes a different though miketa, i am using radio boxes to select a shipping carrier like so: <tbody> {foreach from=$carriers item=carrier name=myLoop} <tr class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{/if} {if $smarty.foreach.myLoop.index % 2}alternate_item{else}item{/if}"> <td class="carrier_action radio"> <input type="hidden" name="step" value="2" /> <input type="radio" name="id_carrier" value="{$carrier.id_carrier|intval}" id="id_carrier{$carrier.id_carrier|intval}" {if $carrier.id_carrier == $checked || ($checked == 0 && $i == 0) || ($carriers|@sizeof == 1)}checked="checked"{/if} onclick="this.form.submit();" /> </td> <td class="carrier_name"> <label for="id_carrier{$carrier.id_carrier|intval}"> {if $carrier.img}<img src="{$carrier.img|escape:'htmlall':'UTF-8'}" alt="{$carrier.name|escape:'htmlall':'UTF-8'}" />{else}{$carrier.name|escape:'htmlall':'UTF-8'}{/if} </label> </td> <td class="carrier_infos">{$carrier.delay|escape:'htmlall':'UTF-8'}</td> <td class="carrier_price">{if $carrier.price}<span class="price">{convertPrice price=$carrier.price}</span>{else}{l s='Free!'}{/if}</td> </tr> {/foreach} </tbody> The step value calls a function that changes the shipping carrier and redirects the page back to step 1 with the new carrier selected changing the values of the cart totals and shipping price but if a customer checks a box that is available for terms of service or "make it a gift", the check box disappears. Quote Link to comment https://forums.phpfreaks.com/topic/171560-checkbox-values-disappear/#findComment-905341 Share on other sites More sharing options...
Ion_Cannon Posted August 26, 2009 Author Share Posted August 26, 2009 Still looking for help. I guess this is a tougher one! Any other ideas anyone? Quote Link to comment https://forums.phpfreaks.com/topic/171560-checkbox-values-disappear/#findComment-907148 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.