From f28353f4e1c573a33dc1c3375585ab040f8be2fc Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 7 Sep 2009 21:01:51 -0700 Subject: Add the 'Internet Address' field to all items, along with proper validation for the fields. --- modules/gallery/helpers/album.php | 17 ++++++++++++++--- modules/gallery/helpers/photo.php | 16 +++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index d995b6ad..bae480b7 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -97,10 +97,14 @@ class album_Core { ->label(t("Add an album to %album_title", array("album_title" => $parent->title))); $group->input("title")->label(t("Title")); $group->textarea("description")->label(t("Description")); - $group->input("name")->label(t("Directory Name")) + $group->input("name")->label(t("Directory name")) ->callback("item::validate_no_slashes") ->error_messages("no_slashes", t("The directory name can't contain the \"/\" character")); - $group->input("slug")->label(t("Internet Address")); + $group->input("slug")->label(t("Internet Address")) + ->callback("item::validate_url_safe") + ->error_messages( + "not_url_safe", + t("The internet address should contain only letters, numbers, hyphens and underscores")); $group->hidden("type")->value("album"); $group->submit("")->value(t("Create")); $form->add_rules_from(ORM::factory("item")); @@ -119,11 +123,18 @@ class album_Core { if ($parent->id != 1) { $group->input("dirname")->label(t("Directory Name"))->value($parent->name) ->rules("required") + ->error_messages("name_conflict", t("There is already a photo or album with this name")) ->callback("item::validate_no_slashes") ->error_messages("no_slashes", t("The directory name can't contain a \"/\"")) ->callback("item::validate_no_trailing_period") ->error_messages("no_trailing_period", t("The directory name can't end in \".\"")); - $group->input("slug")->label(t("Internet Address"))->value($parent->slug); + $group->input("slug")->label(t("Internet Address"))->value($parent->slug) + ->error_messages( + "slug_conflict", t("There is already a photo or album with this internet address")) + ->callback("item::validate_url_safe") + ->error_messages( + "not_url_safe", + t("The internet address should contain only letters, numbers, hyphens and underscores")); } $sort_order = $group->group("sort_order", array("id" => "gAlbumSortOrder")) diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index 12515330..a56c7e3c 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -144,7 +144,11 @@ class photo_Core { $group->input("title")->label(t("Title")); $group->textarea("description")->label(t("Description")); $group->input("name")->label(t("Filename")); - $group->input("slug")->label(t("Internet Address"))->value($photo->slug); + $group->input("slug")->label(t("Internet Address"))->value($photo->slug) + ->callback("item::validate_url_safe") + ->error_messages( + "not_url_safe", + t("The internet address should contain only letters, numbers, hyphens and underscores")); $group->upload("file")->label(t("File"))->rules("required|allow[jpg,png,gif,flv,mp4]"); $group->hidden("type")->value("photo"); $group->submit("")->value(t("Upload")); @@ -159,12 +163,18 @@ class photo_Core { $group->input("title")->label(t("Title"))->value($photo->title); $group->textarea("description")->label(t("Description"))->value($photo->description); $group->input("filename")->label(t("Filename"))->value($photo->name) - ->error_messages("conflict", t("There is already a file with this name")) + ->error_messages("name_conflict", t("There is already a photo or album with this name")) ->callback("item::validate_no_slashes") ->error_messages("no_slashes", t("The photo name can't contain a \"/\"")) ->callback("item::validate_no_trailing_period") ->error_messages("no_trailing_period", t("The photo name can't end in \".\"")); - $group->input("slug")->label(t("Internet Address"))->value($photo->slug); + $group->input("slug")->label(t("Internet Address"))->value($photo->slug) + ->callback("item::validate_url_safe") + ->error_messages( + "slug_conflict", t("There is already a photo or album with this internet address")) + ->error_messages( + "not_url_safe", + t("The internet address should contain only letters, numbers, hyphens and underscores")); module::event("item_edit_form", $photo, $form); -- cgit v1.2.3