Guest
18 May 2013 05:46

is there any way I can automatically verify that the text inserted is a correct URL format like http://google.com ?

I know I could use URL field instead, but I am building a "bookmarks" section and URL field is not the best choiche for now, I am building it manually witha custom template using separate text fields for "website name" and "website url"

then using "composite title" type parameter and a custom list template to

make "website title" text field as the record title, linked directly to the website URL

the code to achieve this is something like this

<h2>

  <a rel="nofollow" target="blank" title="<?php echo $item->title?>" href="/<?php echo $item->fields_by_id[34]->result; ?>">

<?php echo $item->title?>

</a>

<?php echo CEventsHelper::showNum('record', $item->id);?>

                </h2>

were title?>

is the "website name" text field output

and fields_by_id[34]->result; ?>

is "website URL" text field output

Last Modified: 02 Mar 2014


Sackgesicht VIP
Total posts: 1,636
18 May 2013 06:37

To verify an url, you could use a regex expression.

See here

I remember we did a text validation field for mighty resources --> here

It might help a little as a guideline.


Guest
18 May 2013 06:41

thank for the hints!

but I don't see an option to enter validation code in cobalt text field, I see "mask" option, but I guess that is for a different purpose


Sergey
Total posts: 13,748
20 May 2013 02:24

To validate string

if (filter_var($url, FILTER_VALIDATE_URL)) {

echo "This (URL) is considered valid.";

}

To sanitize

$sanitized_url = filter_var($url, FILTER_SANITIZE_URL);

And I have added parameter for Regex validation. You will have to use something like ершы

(http:\/\/[a-z0-9_-.]*.[a-z]{2,3})

Or you can find any other good regex url validation.


pepperstreet VIP
Total posts: 3,837
20 May 2013 09:40

And I have added parameter for Regex validation.

BTW, does Joomla come with a form validation that should be utilized? Or should Cobalt ship a script for all applicable fields?

FYI - Nod!, a frontend validation jQuery plugin - jqBootstrapValidation, a JQuery validation plugin for bootstrap forms - jQuery Live Form Validation for Bootstrap


Sergey
Total posts: 13,748
21 May 2013 05:22

Cobalt has its own validation system/ Joomla has validation class for every form field element. But it works only on the level of server. And to have to files one element and validation not very practical in case of Cobalt. So we created our own system.

Note that Joomla do not have strong validation tools rather validation technique. But we have changed that as we need strong JS validation before even submit form. And we wanted to highlight fields with errors. And even scroll page to those fields.

Unfortunately we cannot incorporate any other validation tool now only develop our own which is not hard. Just tell your ideas how it could be improved.

Powered by Cobalt