Coder Social home page Coder Social logo

Post back fields about validation HOT 4 CLOSED

siriusphp avatar siriusphp commented on July 22, 2024
Post back fields

from validation.

Comments (4)

adrianmiu avatar adrianmiu commented on July 22, 2024

@tmblog Sorry but this is something that you have to implement in your application and it depends on how the data flows. Some applications redirects to the previous URL and store the form values in session. Others don't redirect and show the same form on the same request

from validation.

tmblog avatar tmblog commented on July 22, 2024

Thanks for the reply. The documentation seems to be down now and again. I am trying to figure out how to validate a pair of radion buttons e.g. one must be required then one of them has a dependents:

cash-payment or card-payment is required if card-payment is selected then:

'card-number:Card' => 'requiredWith(card-payment)',
'card-expiry:Expiry' => 'requiredWith(card-payment)',
'card-cvc:CVC' => 'requiredWith(card-payment)',

Can you help?
Thanks again.

from validation.

adrianmiu avatar adrianmiu commented on July 22, 2024

@tmblog Thanks for reporting the documentation issue. It's fixed now

Regarding your question, there are 2 ways to do it. One that works 100% is a hack

if ($_POST['payment'] == 'card_payment') {
    $validator->add([
       'card-number:Card' => 'required'
   ]);
}

The other involves using the requiredWhen (ie: make a field required when some other conditions is met) and it is more complex than what I've used for testing so it might not work

$requiredWhenCardPaymentOptions = [
   'item' => 'payment',
   'rule' => 'equal',
   'rule_options' => ['value' => 'card-payment']
];
$validator->add('card-number:Card', 'requiredWhen', $requiredWhenCardPaymentOptions);

The shorter version should be

$validator->add('card-number:Card', 'requiredWhen({"item":"payment","rule":"equal","rule_options":{"value":"card-payment"}})');

from validation.

tmblog avatar tmblog commented on July 22, 2024

This is perfect, they both work thank you! And thanks for sorting docs out.

from validation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.