Hi All,
I am trying to validate a form and having some issues with it. When I use the page, I get "Property "AuthorizeForm.zip" is not defined.
With this section of code shown:
/var/www/html/yii/framework/validators/CNumberValidator.php(56)
00044: */
00045: public $tooSmall;
00046:
00047:
00048: /**
00049: * Validates the attribute of the object.
00050: * If there is any error, the error message is added to the object.
00051: * @param CModel the object being validated
00052: * @param string the attribute being validated
00053: */
00054: protected function validateAttribute($object,$attribute)
00055: {
00056: $value=$object->$attribute;
00057: if($this->allowEmpty && $this->isEmpty($value))
00058: return;
00059: if($this->integerOnly)
00060: {
00061: if(!preg_match('/^\s*[+-]?\d+\s*$/',"$value"))
00062: {
00063: $message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be an integer.');
00064: $this->addError($object,$attribute,$message);
00065: }
00066: }
00067: else
00068: {
I have no idea where .zip is coming from. I have traced the stack, it gets the AuthorizeForm from the controller, which is expected, but I don’t have .zip listed anywhere. The stack is listed below:
#0 /var/www/html/yii/framework/validators/CNumberValidator.php(56): CComponent->__get(‘zip’)
#1 /var/www/html/yii/framework/validators/CValidator.php(168): CNumberValidator->validateAttribute(Object(AuthorizeForm), ‘zip’)
#2 /var/www/html/yii/framework/base/CModel.php(150): CValidator->validate(Object(AuthorizeForm), NULL)
#3 /var/www/html/gogriffin.org/protected/controllers/AuthorizeController.php(23): CModel->validate()
#4 /var/www/html/yii/framework/web/actions/CInlineAction.php(32): AuthorizeController->actionPayment()
#5 /var/www/html/yii/framework/web/CController.php(300): CInlineAction->run()
#6 /var/www/html/yii/framework/web/CController.php(278): CController->runAction(Object(CInlineAction))
#7 /var/www/html/yii/framework/web/CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)
#8 /var/www/html/yii/framework/web/CWebApplication.php(320): CController->run(‘payment’)
#9 /var/www/html/yii/framework/web/CWebApplication.php(120): CWebApplication->runController(‘authorize/payme…’)
#10 /var/www/html/yii/framework/base/CApplication.php(135): CWebApplication->processRequest()
#11 /var/www/html/gogriffin.org/index.php(11): CApplication->run()
#12 {main}
If anyone has any ideas, I would apreaciate it. This is driving me nuts.
My controller is
public function actionPayment()
{
$Authorize = new AuthorizePayments;
$model = new AuthorizeForm;
if(isset($_POST['AuthorizeForm']))
{
$model->attributes=$_POST['AuthorizeForm'];
if($model->validate())
{
$Authorize->attributes = $_POST['AuthorizeForm'];
if($Authorize->save())
{
// By default, this sample code is designed to post to our test server for
// developer accounts: https://test.authorize.net/gateway/transact.dll
// for real accounts (even in test mode), please make sure that you are
// posting to: https://secure.authorize.net/gateway/transact.dll
$post_url = "https://test.authorize.net/gateway/transact.dll";
$post_values = array(
"x_login" => "",
"x_tran_key" => "",
"x_version" => "3.1",
"x_delim_data" => "TRUE",
"x_delim_char" => "|",
"x_relay_response" => "FALSE",
"x_type" => "AUTH_CAPTURE",
"x_method" => "CC",
"x_card_num" => $Authorize->card_number,
"x_exp_date" => ($Authorize->card_exp_month.$Authorize->card_exp_year),
"x_amount" => "0.00",
"x_description" => $Authorize->item_description,
"x_first_name" => $Authorize->first_name,
"x_last_name" => $Authorize->last_name,
"x_address" => $Authorize->address_street,
"x_state" => $Authorize->address_state,
"x_zip" => $Authorize->address_zip
);
$post_string = "";
foreach( $post_values as $key => $value )
{
$post_string .= "$key=" . urlencode($value) . "&";
}
$post_string = rtrim ($post_string,"& ");
$request = curl_init($post_url);
curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data
$post_response = curl_exec($request); // execute curl post and store results in $post_response
curl_close ($request); // close curl object
// This line takes the response and breaks it into an array using the specified delimiting character
$response_array = explode($post_values["x_delim_char"],$post_response);
// The results are output to the screen in the form of an html numbered list.
echo "<OL>\n";
echo "<LI>" . $response_array[0] . "</LI>\n";
//echo "<LI>" . $response_array[2] . "</LI>\n";
foreach ($response_array as $value)
{
echo "<LI>" . $value . " </LI>\n";
}
echo "</OL>\n";
does some error handling stuff after that…
My model is:
<?php
class AuthorizeForm extends CFormModel
{
public $card_number;
public $card_exp_month;
public $card_exp_year;
public $first_name;
public $last_name;
public $address_street;
public $address_state;
public $address_zip;
public $amount;
public $item_description;
public function rules()
{
return array(
array('card_number,card_exp_month,card_exp_year,first_name,last_name,address_street,address_state,address_zip','required'),
array('card_number,card_exp_month,card_exp_year,zip','numerical','integerOnly'=>true),
array('first_name,last_name,address_street','length','max'=>20),
array('zip','length','max'=>5),
array('card_exp_month,address_state','length','max'=>2),
);
}
public function attributeLabels()
{
return array(
'card_number'=>'Card Number',
'card_exp_month'=>'Month',
'card_exp_year'=>'Year',
'first_name'=>'First Name',
'last_name'=>'Last Name',
'address_street'=>'Address',
'address_state'=>'State',
'address_zip'=>'Zip Code',
'card_exp_month'=>'Month',
'card_exp_year'=>'Year',
);
}
}
?>