Multiple Form Validation - Laravel - php

I am trying to validate a form field in laravel mb_plans based on 2 others form fields activity and options, if both activity and options have there respective value then validate mb_plans
I've tried required_if and required_with, but can't able to use AND condition.
'mb_plans' => 'required_if:activity,MB|required_with:options,0',

if you want to validate when activity value is MB and options is 0 then use :
'mb_plans' => 'required_if:activity,==,MB|required_if:options,==,0',

try below:
'mb_plans' => 'required_with_all:activity,options',

Related

My Laravel required_without_all validation is not working as expected

I am working on a project, where I have three fields 1. csv file upload(email) 2. comma separated string(emails) 3. dynamic input field(email), any one of these fields is required.
My approach for validation:
'comma_separated' => ['nullable','required_without_all:email.*,file'],
'file' => ['nullable','required_without_all:email.*,comma_separated', 'mimes:csv'],
'email.*' => ['nullable','required_without_all:comma_separated,file','email'],
If I enter email in dynamic field, its asking me for file and comma_separated fields.
Any help will be appriciated.
Thank You.
It seems that there's an issue with the validation rules you've defined. The 'required_without_all' validation rule is used to check if a given input field is required if all other specified fields are not present.
In your case, it seems like you want to validate that at least one of the three fields is present, not that all of the fields are absent. To achieve this, you can use the 'required_with' validation rule instead.
Try the following validation rules:
'comma_separated' => ['nullable','required_with:email.*,file'],
'file' => ['nullable','required_with:email.*,comma_separated', 'mimes:csv'],
'email.*' => ['nullable','required_with:comma_separated,file','email'],
This should validate that at least one of the fields is present, and the other fields can be left empty.

Infusionsoft retrieve all custom fields value for specific contact

I've been searching for this solution but haven't found one! I'm using Novak solution's Infusionsoft API.
What I'm trying to do is to get value of a custom field for specific contact. Lets say, I've a custom fields named _myCustomField with Yes/No value. I've 200 contacts in my list but only 15 contact has value 'Yes' for _myCustomField. Lets say I've another custom field _myCustomField2. If I run following query:
$contacts = Infusionsoft_DataService::query( new Infusionsoft_Contact(), array('_myCustomField' => '1') );
I get an array of 15 records, BUT if I print $contacts array then I don't see _myCustomField or _myCustomField2 there.
So, how do I get value for those two custom field inside my loop? Can someone help me with this?
Thanks!
The second parameter of the query method is only the filter and does not tell Infusionsoft that you also want to return any custom fields.
You will want to add the custom fields first:
$contact = new Infusionsoft_Contact();
$contact->addCustomField('_myCustomField');
$contact->addCustomField('_myCustomField2');
$contacts = Infusionsoft_DataService::query( $contact, array('_myCustomField' => '1') );

Onchange in Symfony2 form

This is my input type
->add(‘year’, ChoiceType::CLASS, array(‘choices’ => $array, ‘attr’ => array(‘onchange’ => ‘this.form.submit()’)));
Onchange page is reloading and data is submitted. Then in controller I can access value like this:
$_POST[‘year’].
The thing is I would like to get $_POST in symfony’s way:
$form[‘year’]->getData();
I don’t know why only $_POST[‘year’] works and no result with $form[‘year’]->getData().
You can use for POST request :
$request->request->get('year');
For GET request:
$request->query->get('year');
For FILE queries:
$request->files.
You can get a single item from the form data like;
$year = $form->get('year')->getData();
In this example 'year' is the name given to the field you are asking for (as per your form builder)

WordPress Gravity Form Field Validation

I have a WordPress sites using Gravity Forms, and within this form I have a field that requires a special 10 digit code to be input by the user that matches up with a database of codes (there are 20 of these codes). If the code that has been input matches one of the 20 codes, then they can proceed with submitting the form. If it doesn’t match then they cannot proceed.
Please advise on how to create a PHP function that achieves this?
Many thanks
I wrote a snippet that you might find helpful.
http://gravitywiz.com/require-existing-value-submission-gravity-forms/
To use this snippet for your needs, you would need to setup a new form that will be used to store the 20 codes. Add a field a Single Line Text field to your form. Add an entry for each code.
On your original form, you can now configure the snippet to check the values of the new form for a valid code. Happy to answer any questions.
new GW_Value_Exists_Validation( array(
'target_form_id' => 613, // your original form ID where the codes will be validated
'target_field_id' => 1, // the field on your original form where the user should enter the code
'source_form_id' => 519, // the new form you will create to store your codes
'source_field_id' => 1, // the field on the new form that will store one code per submission
'validation_message' => 'Hey! This isn\'t a valid reference number.' // the error message displayed if the user does not enter a valid code
) );

Converting from typical input "dd/mm/aaaa" to valid Symfony values

I've a table where I set a field as TIMESTAMP, then I generate a module using tasks doctrine:generate-admin. By default Symfony creates a _form.php template where TIMESTAMP fields come separately as for example:
alumnos_fecha_ingreso_day
alumnos_fecha_ingreso_month
alumnos_fecha_ingreso_year
alumnos_fecha_ingreso_hour
alumnos_fecha_ingreso_minute
So in my template I've a field where values are entered as "dd/mm/yyyy" (is the default format) and I don't want to use Symfony way (it's ugly for end users). My question is how I deal with this value in order to get the right value and Symfony pass form validation? Is there any way to hide Hour and Minutes fields? Or is complety necessary?
If you just want day/month/year, you have to define the option with_time to false inside your form class.
with_time: Whether to include time (true by default)
And in your form:
$this->widgetSchema['my_date'] = new sfWidgetFormDateTime(array(
// I don't remember if you need to re-define the format
'date' => array('format' => '%day%/%month%/%year%'),
'with_time' => false
));

Categories