Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/171560-checkbox-values-disappear/
Share on other sites

<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.

<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?

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

 

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.

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. 

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.