flamtech Posted May 21, 2008 Share Posted May 21, 2008 I have a form on my site that I have created with thesitewizard, but now I want to add radio buttons. This first piece is the HTML part. <tr> <td><span style="font-family: Verdana; color: black">Message Format</span></td> <td><input type="radio" name="mformat" value="TIFF"> TIFF<br> <input type="radio" name="mformat" value="PDF"> PDF<br> </td> </tr> And this is feedback.php where I inserted the "mformat" statements, but I dont know what to do in the if statements. Can you please help me. http://www.thesitewizard.com/ */ // ------------- CONFIGURABLE SECTION ------------------------ // $mailto - set to the email address you want the form // sent to, eg //$mailto = "[email protected]" ; $mailto = '[email protected]' ; // $subject - set to the Subject line of the email, eg //$subject = "Feedback Form" ; $subject = "GratisFax" ; // the pages to be displayed, eg //$formurl = "http://www.example.com/feedback.html" ; //$errorurl = "http://www.example.com/error.html" ; //$thankyouurl = "http://www.example.com/thankyou.html" ; $formurl = "http://www.tsw.gratisfax.co.za" ; $errorurl = "http://www.tsw.gratisfax.co.za/oops.htm" ; $thankyouurl = "http://www.tsw.gratisfax.co.za/thanks.htm" ; $uself = 0; $email_is_required = 1; $name_is_required = 1; $mformat_is_required = 1; // -------------------- END OF CONFIGURABLE SECTION --------------- $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; $email_required = (!isset( $email_is_required ) || ($email_is_required == 0)) ? 0 : 1 ; $name_required = (!isset( $name_is_required ) || ($name_is_required == 0)) ? 0 : 1 ; $mformat_required = (!isset( $mformat_is_required ) || ($mformat_is_required == 0)) ? 0 : 1 ; $name = $_POST['name'] ; $email = $_POST['email'] ; $mformat = $_POST['mformat'] ; $comments = $_POST['comments'] ; $http_referrer = getenv( "HTTP_REFERER" ); if (!isset($_POST['email'])) { header( "Location: $formurl" ); exit ; } if (($email_required && (empty($email) || !ereg("@", $email))) || ($name_required && empty($name))) { header( "Location: $errorurl" ); exit ; } if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) { header( "Location: $errorurl" ); exit ; } if (empty($email)) { $email = $mailto ; } if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments ); } $messageproper = "This message was sent from:\n" . "$http_referrer\n" . "------------------------------------------------------------\n" . "Name of sender: $name\n" . "Email of sender: $email\n" . "------------------------- COMMENTS -------------------------\n\n" . $comments . "\n\n------------------------------------------------------------\n" ; mail($mailto, $subject, $messageproper, "From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.10.0" ); header( "Location: $thankyouurl" ); exit ; ?> Link to comment https://forums.phpfreaks.com/topic/106681-solved-check-radio-button/ Share on other sites More sharing options...
Psycho Posted May 21, 2008 Share Posted May 21, 2008 I'm not sure I follow you. Are you trying to figure out how to validate the value? For radio buttons I typically create an array of valid values and check if the post'ed value is in the array: <?php $mformat = $_POST['mformat']; $valid_formats = array('TIFF', 'PDF'); if (!in_array($mformat, $valid_formats)) { echo "ERROR: Format '$mformat' is NOT valid"; } else { echo "OK: Format '$mformat' is valid"; } ?> Link to comment https://forums.phpfreaks.com/topic/106681-solved-check-radio-button/#findComment-546877 Share on other sites More sharing options...
flamtech Posted May 22, 2008 Author Share Posted May 22, 2008 I have inserted the following code; <?php $uself = 0; $email_is_required = 1; $name_is_required = 1; $mformat_is_required = 1; //inserted by me ?> and <?php $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; $email_required = (!isset( $email_is_required ) || ($email_is_required == 0)) ? 0 : 1 ; $name_required = (!isset( $name_is_required ) || ($name_is_required == 0)) ? 0 : 1 ; $mformat_required = (!isset( $mformat_is_required ) || ($mformat_is_required == 0)) ? 0 : 1 ; // inserted by me $name = $_POST['name'] ; $email = $_POST['email'] ; $mformat = $_POST['mformat'] ; //inserted by me $comments = $_POST['comments'] ; $http_referrer = getenv( "HTTP_REFERER" ); ?> I would like to know what I must insert here <?php if (!isset($_POST['email'])) { header( "Location: $formurl" ); exit ; } if (($email_required && (empty($email) || !ereg("@", $email))) || ($name_required && empty($name))) { header( "Location: $errorurl" ); exit ; } if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) { header( "Location: $errorurl" ); exit ; } if (empty($email)) { $email = $mailto ; } if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments ); } ?> I did try to adapt and use the part $name, but I cant get it to work. Any help will be appreciated. Link to comment https://forums.phpfreaks.com/topic/106681-solved-check-radio-button/#findComment-547164 Share on other sites More sharing options...
flamtech Posted May 22, 2008 Author Share Posted May 22, 2008 Problem solved. Thanks Link to comment https://forums.phpfreaks.com/topic/106681-solved-check-radio-button/#findComment-547289 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.