Inserting new record stripping ampersand

Hello, whenever I try to create a new item from a particular form, when I enter an ampersand or a string that contains one it doesn’t work.




$item = new Item;

$item->name = "&";

$item->save();



It just fails, I thought Yii handled cases like this. What is the best way to be able to add ampersands? Thanks.

Does anyone have an answer for this? I’m having a problem as well. Whenever there’s an ampersand in a string of text I save, it strips the ampersand and everything to the right of it in the string, and just saves the first part.




$item = new Item;

$item->attribute = "Blah & Blah";

$item->save(); //Stores "Blah " in the database



Here’s my rules function. I’m attempting to store the string in the “title” field.




public function rules()

{

	// NOTE: you should only define rules for those attributes that

	// will receive user inputs.

	return array(

		array('eq_id, wt_id, location_id, check_id, user_created, user_updated, user_completed, action_needed, action_complete', 'numerical', 'integerOnly'=>true),

		array('text, time_created, time_updated, time_completed', 'safe'),

		// The following rule is used by search().

		// Please remove those attributes that should not be searched.

		array('id, eq_id, wt_id, location_id, check_id, user_created, user_updated, user_completed, text, action_needed, action_complete, time_created, time_updated, time_completed, title', 'safe', 'on'=>'search'),

		array('title', 'length', 'max'=>64),

		array('title, text', 'required')

	);

}



Can anyone say whether you can insert ampersands into your db without this happening?

Did some more troubleshooting. It boiled down to a jQuery problem, nothing to do with Yii.

Formerly I had:




var formData = $("#note-form").serialize();


$.ajax({

	url: "myurl",

	global: false,

	type: "POST",

	async: false,

	data: formData

});



This ended up leaving the & in the POST string instead of encoding it to &.

Here’s the fix:




$.ajax({

	url: "myurl",

	global: false,

	type: "POST",

	async: false,

	data: $("#note-form").serialize()

});



More efficient anyway, I suppose.