Jump to content

[SOLVED] Check Radio Button


flamtech

Recommended Posts

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

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";
}

?>

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.

Archived

This topic is now archived and is closed to further replies.

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