zoobzen Posted June 25, 2010 Share Posted June 25, 2010 Hello, I have an interesting problem to solve .. I am setting up a few radio buttons to establish a new or returning user. Using the below code I am getting the buttons to act the way I want them to, however, when no button is selected (I cannot have any "pre-selected" for this app) I get an "Undefined index: userType" error in addition to my own error message to the user. The "mUserTypes" array is what I am using to load the radio buttons, and my "selected" value is mNeworReturn[user_type]. Thanks for any help offered .. Frank $this->mNeworReturn = array('user_type' => ' '); $this->mUserTypes = array ('New' => 'I am a first time customer, 'Return' => 'I am a returning customer'); if (isset ($_POST['Login'])) { $this->mNeworReturn['user_type'] = $_POST['userType']; if (empty ($_POST['userType'])) { $this->mUserTypeError = 1; $this->_mErrors++ } } If needed to review this problem, the below is the whole constructor of the class .. Thanks class CheckoutStep1 { // Public stuff public $mErrorMessage; public $mLinkToLogin; public $mLinkToRegisterCustomer; public $mEmail = ''; public $mNeworReturn; public $mUserTypes; public $mUserTypeError; public $mUserError; private $_mErrors = 0; // Class constructor public function __construct() { if (USE_SSL == 'yes' && getenv('HTTPS') != 'on') $this->mLinkToLogin = Link::Build(str_replace(VIRTUAL_LOCATION, '', getenv('REQUEST_URI')), 'https'); else $this->mLinkToLogin = Link::Build(str_replace(VIRTUAL_LOCATION, '', getenv('REQUEST_URI'))); $this->mLinkToStep2 = Link::ToRegisterCustomer(); $this->mNeworReturn = array('user_type' => ''); $this->mUserTypes = array ('New' => 'I am a first time customer', 'Return' => 'I am a returning customer'); if (isset($_POST['Login'])) { $this->mNeworReturn['user_type'] = $_POST['userType']; if (empty ($_POST['userType'])) { $this->mUserTypeError = 1; $this->_mErrors++; } } } Link to comment https://forums.phpfreaks.com/topic/205815-undefined-index-problem/ Share on other sites More sharing options...
Andy-H Posted June 25, 2010 Share Posted June 25, 2010 $this->mNeworReturn = array('user_type' => ' '); $this->mUserTypes = array ('New' => 'I am a first time customer', 'Return' => 'I am a returning customer'); if (isset ($_POST['Login'])) { $this->mNeworReturn['user_type'] = isset($_POST['userType']) ? $_POST['userType'] : ''; if (empty ($this->mNeworReturn['user_type'])) { $this->mUserTypeError = 1; $this->_mErrors++; } } Link to comment https://forums.phpfreaks.com/topic/205815-undefined-index-problem/#findComment-1076994 Share on other sites More sharing options...
zoobzen Posted June 25, 2010 Author Share Posted June 25, 2010 Very nice Andy .. I tried both "isset" and "empty" by themselves .. so I guess I was on the right track .. but as usual the experts dialed right in .. Thanks Andy .. you da' man Respectfuly, Frank Link to comment https://forums.phpfreaks.com/topic/205815-undefined-index-problem/#findComment-1076997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.