Captain Salad Posted March 23, 2006 Share Posted March 23, 2006 Hi, would it be possible for one of you geniuses to give me a little hand with this script, this is my fist PHP script and am really stuck on the radio and tick box parts, if I don’t click on the tick boxes or radio buttons the script goes no where, I would like my user to have the option of NOT clicking the radio or check box if the so decide and the form to go through fine, could anyone amend the below script so I can see where I was going wrong?Thank you for your time and god bless$creditcard is the one which uses a tick box and $transfer is the one which uses radio button, the rest are just normal form fields<? $transfer = $_REQUEST['transfer'] ; $email = $_REQUEST['email'] ; $existingnumber = $_REQUEST['existingnumber'] ; $pacnumber = $_REQUEST['pacnumber'] ; $title = $_REQUEST['title'] ; $firstname = $_REQUEST['firstname'] ; $middleinitial = $_REQUEST['middleinitial'] ; $lastname = $_REQUEST['lastname'] ; $dob = $_REQUEST['dob'] ; $currentaddress = $_REQUEST['currentaddress'] ; $town = $_REQUEST['town'] ; $postcode = $_REQUEST['postcode'] ; $residentialstatus = $_REQUEST['residentialstatus'] ; $yearsataddress = $_REQUEST['yearsataddress'] ; $monthsataddress = $_REQUEST['monthsataddress'] ; $previousaddress = $_REQUEST['previousaddress'] ; $previoustowm = $_REQUEST['previoustown'] ; $previouspostcode = $_REQUEST['previouspostcode'] ; $hometel = $_REQUEST['hometel'] ; $daytimetel = $_REQUEST['daytimetel'] ; $bankaccountyears = $_REQUEST['bankaccountyears'] ; $bankaccountmonths = $_REQUEST['bankaccountmonths'] ; $creditcard = $_POST ['creditcard'] ; if (!isset($_REQUEST['email'])) { header( "Location: [a href=\"http://www.brittalk.com/brittalk/Templates/contactUs.htm"\" target=\"_blank\"]http://www.brittalk.com/brittalk/Templates...actUs.htm"[/a] ); } elseif (empty($email) || empty($transfer) || empty($title) || empty($firstname) || empty($middleinitial) || empty($lastname) || empty($dob) || empty($currentaddress) || empty($town) || empty($postcode) || empty($residentialstatus) || empty($yearsataddress) || empty($monthsataddress) || empty($hometel) || empty($daytimetel) || empty($bankaccountyears) || empty($bankaccountmonths)) { header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" ); header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" ); header( "Cache-Control: no-cache, must-revalidate" ); header( "Pragma: no-cache" ); ?> <html> <head><title>Error</title></head> <body> <h1>Error</h1> <p> Oops, it appears you forgot to enter some information into the required fields. The required fields are identified by a red star preceding them. Please press the BACK button on your browser and try again. </p> </body> </html> <? } else { mail( "bukem_1@tiscali.co.uk" , "Unlock Customer Phone.", "Transfer an existing mobile number from another network: $transfer Existing Number: $existingnumber Pac Number: $pacnumber Name: $title $firstname $middleinitial $lastname Date Of Birth: $dob Current Address: $currentaddress $town $postcode Residential Status: $residentialstatus Years At Current Address: $yearsataddress Months At Current Address: $monthsataddress Previous Address: $previousaddress $previoustown $previouspostcode Home Telephone Number: $hometel Day Time Telephone Number: $daytimetel Had Bank Account for: $bankaccountyears $bankaccountmonths Own A Credit Card?: $creditcard ", "From: $email"); header("Location: [a href=\"http://www.mysite.com");\" target=\"_blank\"]http://www.mysite.com");[/a] }?> Quote Link to comment https://forums.phpfreaks.com/topic/5627-anyone-so-kind-as-to-help/ Share on other sites More sharing options...
Barand Posted March 23, 2006 Share Posted March 23, 2006 A couple of techniques for youIf you have radio buttons, either set one of them 'checked' by default[code]<INPUT TYPE='RADIO' name='rb' value='1' checked> 1<INPUT TYPE='RADIO' name='rb' value='2'> 2<INPUT TYPE='RADIO' name='rb' value='3'> 3[/code]or add a hidden field with same name and value=0 before the buttons[code]<INPUT TYPE='HIDDEN' name='rb' value='0'><INPUT TYPE='RADIO' name='rb' value='1'> 1<INPUT TYPE='RADIO' name='rb' value='2'> 2<INPUT TYPE='RADIO' name='rb' value='3'> 3[/code]then you still gat a value for 'rb' even if no button is selected.With checkboxes, only checked ones are posted so if you have checkbox named creditcard[code]$creditcard = isset($_POST['creditcard']) ? $_POST['creditcard'] : 0;[/code]Now you have a 0 value for creditcard if it isn't checked.hth Quote Link to comment https://forums.phpfreaks.com/topic/5627-anyone-so-kind-as-to-help/#findComment-20124 Share on other sites More sharing options...
Captain Salad Posted March 24, 2006 Author Share Posted March 24, 2006 Hi, thank you very much for trying to help me, I edited the code for the check box but now get this message Parse error: parse error, unexpected '?', expecting ',' or ')' in W:\Webspace\resadmin\ajsimpson\simputers.co.uk\www\brittalk\Templates\Scripts\tmobilecontract.php on line 24here is the script:, any ideas?<? $transfer = $_REQUEST['transfer'] ; $email = $_REQUEST['email'] ; $existingnumber = $_REQUEST['existingnumber'] ; $pacnumber = $_REQUEST['pacnumber'] ; $title = $_REQUEST['title'] ; $firstname = $_REQUEST['firstname'] ; $middleinitial = $_REQUEST['middleinitial'] ; $lastname = $_REQUEST['lastname'] ; $dob = $_REQUEST['dob'] ; $currentaddress = $_REQUEST['currentaddress'] ; $town = $_REQUEST['town'] ; $postcode = $_REQUEST['postcode'] ; $residentialstatus = $_REQUEST['residentialstatus'] ; $yearsataddress = $_REQUEST['yearsataddress'] ; $monthsataddress = $_REQUEST['monthsataddress'] ; $previousaddress = $_REQUEST['previousaddress'] ; $previoustowm = $_REQUEST['previoustown'] ; $previouspostcode = $_REQUEST['previouspostcode'] ; $hometel = $_REQUEST['hometel'] ; $daytimetel = $_REQUEST['daytimetel'] ; $bankaccountyears = $_REQUEST['bankaccountyears'] ; $bankaccountmonths = $_REQUEST['bankaccountmonths'] ; $creditcard = isset($_POST['creditcard'] ? $_POST['creditcard'] : 0; if (!isset($_REQUEST['email'])) { header( "Location: [a href=\"http://www.brittalk.com/brittalk/Templates/contactUs.htm"\" target=\"_blank\"]http://www.brittalk.com/brittalk/Templates...actUs.htm"[/a] ); } elseif (empty($email) || empty($transfer) || empty($title) || empty($firstname) || empty($middleinitial) || empty($lastname) || empty($dob) || empty($currentaddress) || empty($town) || empty($postcode) || empty($residentialstatus) || empty($yearsataddress) || empty($monthsataddress) || empty($hometel) || empty($daytimetel) || empty($bankaccountyears) || empty($bankaccountmonths)) { header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" ); header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" ); header( "Cache-Control: no-cache, must-revalidate" ); header( "Pragma: no-cache" ); ?> <html> <head><title>Error</title></head> <body> <h1>Error</h1> <p> Oops, it appears you forgot to enter some information into the required fields. The required fields are identified by a red star preceding them. Please press the BACK button on your browser and try again. </p> </body> </html> <? } else { mail( "bukem_1@tiscali.co.uk" , "Unlock Customer Phone.", "Transfer an existing mobile number from another network: $transfer Existing Number: $existingnumber Pac Number: $pacnumber Name: $title $firstname $middleinitial $lastname Date Of Birth: $dob Current Address: $currentaddress $town $postcode Residential Status: $residentialstatus Years At Current Address: $yearsataddress Months At Current Address: $monthsataddress Previous Address: $previousaddress $previoustown $previouspostcode Home Telephone Number: $hometel Day Time Telephone Number: $daytimetel Had Bank Account for: $bankaccountyears $bankaccountmonths Own A Credit Card?: $creditcard ", "From: $email"); header("Location: [a href=\"http://www.brittalk.com/brittalk/Templates/thankyou.htm");\" target=\"_blank\"]http://www.brittalk.com/brittalk/Templates...you.htm");[/a] }?>thank you and god bless Quote Link to comment https://forums.phpfreaks.com/topic/5627-anyone-so-kind-as-to-help/#findComment-20205 Share on other sites More sharing options...
Barand Posted March 24, 2006 Share Posted March 24, 2006 Sorry, I omitted closing ")" on the isset() function$creditcard = isset($_POST['creditcard'][!--sizeo:3--][span style=\"font-size:12pt;line-height:100%\"][!--/sizeo--][!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--])[!--colorc--][/span][!--/colorc--][!--sizec--][/span][!--/sizec--] ? $_POST['creditcard'] : 0; Quote Link to comment https://forums.phpfreaks.com/topic/5627-anyone-so-kind-as-to-help/#findComment-20207 Share on other sites More sharing options...
Captain Salad Posted March 24, 2006 Author Share Posted March 24, 2006 Wow, works like a charm, thank you sincerely for you help and patience with me, it is very appreciated!Could I pick your knowledgeable brain on one more bug?Using my current script I want to make the $transfer radio buttons a require field, when I try this with the current code, when filling out the form, if I miss the $transfer radio buttons out the browser displays an error message. Any help on this other bug?Thank you again for your time and help!!God bless Quote Link to comment https://forums.phpfreaks.com/topic/5627-anyone-so-kind-as-to-help/#findComment-20230 Share on other sites More sharing options...
Barand Posted March 24, 2006 Share Posted March 24, 2006 Have you used one the methods for radiobuttons that I gave in my first post? Quote Link to comment https://forums.phpfreaks.com/topic/5627-anyone-so-kind-as-to-help/#findComment-20232 Share on other sites More sharing options...
Captain Salad Posted March 24, 2006 Author Share Posted March 24, 2006 Have now, again works like a charm ;) thanks very much. Just so I know how would the same work for checkboxs? Put in a hidden checkbox perhaps? Quote Link to comment https://forums.phpfreaks.com/topic/5627-anyone-so-kind-as-to-help/#findComment-20260 Share on other sites More sharing options...
Barand Posted March 24, 2006 Share Posted March 24, 2006 Radiobuttons and checkboxes are different animals. Radio buttons only ever have a single value. With checkboxes you can have multiple values so it isn't going to work in quite the same way. Quote Link to comment https://forums.phpfreaks.com/topic/5627-anyone-so-kind-as-to-help/#findComment-20358 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.