1

SOLVED: Just need to add autocomplete="off" to the radio buttons.

EDIT: I was incorrect in my original assessment of what's causing the error. It is not dependent on whether or not the user makes a selection. It's when I use Chrome's autofill feature for the rest of the form. If I use the autofill then no value gets passed through :-/

EDIT2: Looks like it's a known bug. Chrome autofill unfills radio buttons http://productforums.google.com/forum/#!topic/chrome/WNBd8p6q7YQ

I have a form where the recommended postage options are pre-selected using "checked":

<fieldset class="outwardpostage">

<legend>Outward postage</legend>

<label for="outwardpostageeconomy">Economy<br><span class="greenprice">£3.95</span></label>
<input type="radio" name="outwardpostage" value="3.95" id="outwardpostageeconomy" checked>

<label for="outwardpostagestandard">Standard<br><span class="greenprice">£7.95</span></label>
<input name="outwardpostage" type="radio" id="outwardpostagestandard" value="7.95">

<label for="outwardpostagepremium">Premium<br><span class="greenprice">£11.95</span></label>
<input type="radio" name="outwardpostage" value="11.95" id="outwardpostagepremium">

<label for="outwardpostagepostyourself">I will post myself using my own preferred delivery service</label>
<input type="radio" name="outwardpostage" value="0" id="outwardpostagepostyourself">

</fieldset>

The problem is the value doesn't get passed through the php form processor unless the user has clicked on the radio button. If they have just left the recommended option then the field is left as blank.

How can I fix this?

$outwardpostage = $_POST['outwardpostage'];
Shoaib Sayyad
  • 123
  • 1
  • 2
  • 10
Chris
  • 431
  • 5
  • 11
  • 18
  • use the HTML5 attribute: `required = "required"`, this wont submit the form until the user has clicked/inputted required fields – stackErr Jul 11 '13 at 15:02
  • @stackErr I think he wants his already checked radio buttons to get posted without letting the user to be clicked – Mohammad Areeb Siddiqui Jul 11 '13 at 15:05
  • Sorry I probably should have been clearer. The radio buttons have a defualt selection (one is already checked when the page loads). This selection should be passed through the php form processor if the user doesn't change it. But it isn't. A value is only passed through if the user has changed the radio button selection. – Chris Jul 11 '13 at 15:06
  • How are you submitting those values? I tested it and it's passing the value with the recommended option. – Luigi Siri Jul 11 '13 at 15:14
  • Ok I just tested it with ie, safair and firefox and its working fine, but chrome won't send the default selection :-/ – Chris Jul 11 '13 at 15:23
  • I'm going to try clearing the cache – Chris Jul 11 '13 at 15:24
  • Go ahead and do that. I tested it in chrome btw. This is how I did it: [phpfiddle.org/bjf-pih](http://phpfiddle.org/main/code/bjf-pih). Note: in SO comments, use an @(user-name) to notify the user you are replying to. @Chris – Luigi Siri Jul 11 '13 at 15:51

1 Answers1

0

Can't you do something like:

if( !isset($_POST['outwardpostage']) ) { $_POST['outwardpostage'] = 3.99; }

To get round it not picking up the default?

Ashley Banks
  • 528
  • 5
  • 16