Conditional Validation will not allow form to submit - cakephp-3.0

I have the below Conditional Validation, this validation only check the cc_number when the payment_method_id is 1, so it should not validate when there is other payment_method_id being used, but problem in my view page, even if I dont select the payment method, the form will not submit to the controller, unless the cc_number is filled, is there anyway to disable this cc_number check ? thank you
$validator->creditCard ( 'cc_number', [ 'mc','visa' ], __ ( 'invalid card number' ), function ($context)
{
if ($context ['data'] ['payment_method_id'] == 1)
return true;
} );

sorry for wasting space in this area, i just code cakephp3.5 recently, seems that this problem can be easily solve by putting ,'novalidate' => true at the $this->Form->create method

Related

Is it possible to inspect the values entered in the Adyen payment widget and run validations against those values? And give error states?

I'm looking to set my own validations on my Adyen payment module. Specifically I want to eliminate people's ability to insert incorrect characters in card holder name field (like emojis, etc).
You are able to customize the validation logic implementing one of the handlers
onChange: (state, component) => {
// triggered at every change
console.error("onChange " + JSON.stringify(state.data));
},
onSubmit: (state, component) => {
// triggered upon submit
console.error("onSubmit " + JSON.stringify(state.data));
// grab holderName
var holderName = state.data.paymentMethod.holderName;
// apply your validation...
if(validationOk) {
makePayment(state.data)
// etc etc
}
}
Check Web Dropin integration guide. Make sure to check which version you are using (to refer to the relevant documentation), however the workflow is similar.

How to limit sign up emails to just .edu?

I'm currently creating a site that I would like to have users only be able to sign up to with just emails that end in .edu. As in, in order to sign up for this site, you need to have a .edu email. How would I be able to create that limitation?
Thank you!
The standard way to solve this in a Rails app would be to add a simple format validator to your User model that allows only addresses with a specific pattern:
# in your user model
validates :email, format: { with: /\.edu\z/, message: "only allows .org addresses" }
Use regular expressions. You can easily check to make sure it's a valid email and it's only a .edu email using regular expressions.
use the include? method
email = "test.test#email.edu"
if email.include? ".edu"
// do something in here
end
If you have a form, make a function that executes on form submit.
<form id="email" onsubmit="checkEmail()">
<input type="text" name="email" id="email-input"/>
</form>
For the script:
function checkEmail(){
var text = document.getElementById('email').value;
if(text.indexOf('.edu') === text.length-4){
return true;
}else{
return false;
}
}
The script checks if the email contains .edu at the very end of the input. If so, it returns true to carry on with submission. Otherwise, it returns false, and the form does not submit.
EDIT Case was given of throwaway.edu#gmail.com, as well as .edu.com, etc. Can handle this now.

html search form, how do i reduce the URL

I am creating a search for using the GET method at the moment, the problem is even if values are not selected and left at there default value they are sent and visible in the url.
I want to only have values selected in the url rather than every current value of the form, including default of 0.
the url ends up long and nasty:
search.php?search_shop_name=mcdonalds&search_shop_address=&search_total_rating=0&search_shop_comfort=0&search_shop_service=2&search_shop_ambience=0&search_shop_friendliness=0&search_shop_spacious=0&search_shop_experience=0&submit=#legend_total_results
I basically want to tidy up the url, am not actually sure if removing unwanted data is a good process or not, any possible advice on this situation? not sure if am being OCD with the visuals
Thanks
I would do the following. Using JavaScript or jQuery, create a submit function, in that function do a validate search with all fields if they = null then don't include them.
For e.g
var search;
function search(){
if(input[name=search].val() != null)
{
search = "q="+input[name=search].val();
}
if(input[name=search_shop_experience].val() != null)
{
search += "search_shop_experience="+input[name=ssearch_shop_experience].val();
}
}
I think you do .= or its += .

How to: Update jQuery dialog div with new content from json

I am attempting to update the div of my dialog with new content from a json array and am encountering issues and am requesting some guidance.
I output a json array which has labels for a 'Name' and a 'Definition'. A user is presented with a list of radio buttons. When a user clicks a radio button which has the following structure:
<input type="radio" value="23" name="statistic" id="stat-23" />
I take the value of the radio button and use this to identify which 'Name' 'Definition' pair I am referring to from my json array.
I then use the 'Name' 'Definition' pair to populate a div which typically updates dynamically. To accomplish this I use the following code:
$('input[type=radio]').live( 'change', function(){
if ( ! $(this).is(':checked') )
return false;
var stat_id = $(this).attr( 'id' ).replace( /stat-/, '' );
refreshDefinition( stat_id );
} );
function refreshDefinition( stat_id ) {
var definition = definitions[ stat_id ];
var div = $("<div id='definition'>"+definition.name+": "+definition.definition+"</div>");
$('#definition').replaceWith( div );
}
This works fine without a dialog (it updates just fine as is), however, it would look a lot better if there were some way to incorporate a dialog so that when a user clicks a button, the dialog will appear and they can see the 'Name' 'Definition' pair and then can exit out of it when they are satisfied.
$('#definition').dialog();
I would like the above code to show the updated data, but it does not appear to allow it.
If you have any guidance on how I could go about solving this problem or any alternative approaches, I would really appreciate it!
Thanks.
Have you tried updating the dialogs content?
$('#definition').html(definition.name+": "+definition.definition);
Here's an example.
EDIT:
unnecessary .dialog('widget') made this answer wrong.

MediaWiki Extension question / suggestion

Complete beginner here. I want to create a new tab on each page that has a custom action. When clicked, it takes you to a new page which has custom HTML on it along with the text or the original article.
So far I could create a new Tab and could give a custom action mycustomaction to it. I am pasting what I did so far here. Please let me know if I am using the correct hooks etc. and what is a better way to achieve this basic functionality.
So far with their docs I have done this:
#Hook for Tab
$wgHooks['SkinTemplateContentActions'][] = 'myTab';
#Callback
function myTab( $content_actions) {
global $wgTitle;
$content_actions['0'] = array(
'text' => 'my custom label',
'href' => $wgTitle->getFullURL( 'action=mycustomaction' ),
);
return true;
}
#new action hook
$wgHooks['UnknownAction'][] = 'mycustomaction';
#callback
function mycustomaction($action, $article) {
echo $action;
return true;
}
This gives me error:
No such action
The action specified by the URL is invalid. You might have mistyped the URL, or followed an incorrect link. This might also indicate a bug in the software used by yourplugin
What I was doing wrong:
$content_actions[‘0’] should simply be $content_actions[] (minor nitpick)
$content_actions is passed-by-reference, it should be function myTab( &$content_actions ) {}
mycustomaction() should do something along the lines of
if ( $action == ‘mycustomaction’ ) {
do stuff; return false;
}
else {
return true;
}
It should use $wgOut->addHTML() instead of echo
Thanks a lot everyone for your help!