what is the best way to validate a user is entering in a string that should look like this.
http://domain.com/path/file.mp3
I really just want to make sure that the string ends in .mp3
it looks like the built in validation doesn't have that option, but I know I am missing something because I'm aware it can be done.
Aaron
http://domain.com/path/file.mp3
I really just want to make sure that the string ends in .mp3
it looks like the built in validation doesn't have that option, but I know I am missing something because I'm aware it can be done.
Aaron
Hi Aaron,
You an add a Custom Validation in ChronoForms v3.2 - it takes a bit of JavaScript coding*.
Probably easier to handle this in the Server Side validation.
Bob
*I have a Custom Validation tutorial for sale here .
You an add a Custom Validation in ChronoForms v3.2 - it takes a bit of JavaScript coding*.
Probably easier to handle this in the Server Side validation.
<?php
$link = JRequest::getString('input_name', '', 'post');
if ( strtolower(substr($link, -4)) != '.mp3' ) {
return 'The file name must end in .mp3';
}
?>
Bob
*I have a Custom Validation tutorial for sale here .
do I have to replace anything of what you wrote with the field name that is capturing the data?
Aaron
Aaron
I guess you don't. It's working right away. How does the code that you showed me know to run on that particular field?
Aaron
Aaron
Hi Aaron,
You need to replace input_name with the name of the input you want to validate.
Bob
You need to replace input_name with the name of the input you want to validate.
Bob
Thanks for the help Bob. I'm going to buy the cook book(s) anyway as I have been building up a legitimate library lately and these will be a great addition.
The validation is working like I said the first time, however I haven't replaced the variable with the name of the field that I am checking.
if I leave that field blank when submitting the form, a message is displayed saying it is required. If I fill that field in and do it incorrectly, the warning is displayed about how the string must end in .mp3
here is the form code of that input field
and I left your code exactly as is. How the heck is this working?
Aaron
The validation is working like I said the first time, however I haven't replaced the variable with the name of the field that I am checking.
if I leave that field blank when submitting the form, a message is displayed saying it is required. If I fill that field in and do it incorrectly, the warning is displayed about how the string must end in .mp3
here is the form code of that input field
<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">URL to .mp3:</label>
<input class="cf_inputbox required validate-url" maxlength="150" size="30" id="text_8" name="urls" type="text" />
<a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" src="components/com_chronocontact/css/images/tooltip.png"/></a>
<div class="tooltipdiv">URL to .mp3 :: Direct URL to the .mp3 file. (host.com/mix.mp3)</div>
</div>
<div class="clear"> </div>
</div>
and I left your code exactly as is. How the heck is this working?
<?php
$link = JRequest::getString('input_name', '', 'post');
if ( strtolower(substr($link, -4)) != '.mp3' ) {
return 'The file name must end in .mp3';
}
?>
Aaron
Hi Aaron,
You need to replace 'input_name' with the name of the input i.e. 'urls'. There's also a bit missing from my code - it's not checking for an empty input. Try this version:
Bob
You need to replace 'input_name' with the name of the input i.e. 'urls'. There's also a bit missing from my code - it's not checking for an empty input. Try this version:
<?php
$link = JRequest::getString('urls', '', 'post');
if ( $link && strtolower(substr($link, -4)) != '.mp3' ) {
return 'The file name must end in .mp3';
}
?>
Bob
There error message that is displayed in the UI after completing the form is
1.
and I've tested it. I put .mp3 at the end of the string in the field and I get the above error. I have replaced the code with your update also.
thanks,
Aaron
1.
and I've tested it. I put .mp3 at the end of the string in the field and I get the above error. I have replaced the code with your update also.
thanks,
Aaron
Hi Aaron,
Is this the latest ChronoForms version 3.2?
If so there's a bug in the File upload code. Please see this post.
Bob
Is this the latest ChronoForms version 3.2?
If so there's a bug in the File upload code. Please see this post.
Bob
Interesting. File uploads of ~ 80 MB fail, but file uploads of ~ 50 MB are okay. Also, regarding my other post (1 above this one)... I'm not receiving that error from an upload... the error is from the server side validation.
when I replaced your code, it returned the new error to the window. There is no file that is being uploaded. Just strings inside textboxes. Did you understand that from my other post?
and yes I am using 3.2 on J1.5
Thanks,
Aaron
when I replaced your code, it returned the new error to the window. There is no file that is being uploaded. Just strings inside textboxes. Did you understand that from my other post?
and yes I am using 3.2 on J1.5
Thanks,
Aaron
and in regards to change management... I've only changed the sever side validation code to produce this error on V3.2. Before the code was there for validation, all (ALL) form submissions were fine.
Aaron
Aaron
<?php
$link = JRequest::getString('urls', '', 'post');
if ( $link && strtolower(substr($link, -4)) != '.mp3' ) {
return 'The file name must end in .mp3';
}
?>
Hi Aaron,
That looks fine and I'm pretty certain it's not the cause of the error you are getting.
Bob
That looks fine and I'm pretty certain it's not the cause of the error you are getting.
Bob
Bob,
just to make sure that we are on the same form (i mean page - lol), what error are you talking about? Are you talking about the file not being uploaded when it is big ~ 80 MB?
Okay, is this because of using v3.2? I'll check your thread that you showed me earlier.
Aaron
just to make sure that we are on the same form (i mean page - lol), what error are you talking about? Are you talking about the file not being uploaded when it is big ~ 80 MB?
Okay, is this because of using v3.2? I'll check your thread that you showed me earlier.
Aaron
also, if this is a form level problem, (i.e. v3.2) then how come it isn't showing up in the other forms?
This topic is locked and no more replies can be posted.