I use Symfony 1.4.11. I have two tables "companies" and "ads". When user add new ad, he can connect ad with his company.Before it I check, if user have company, for example I have variable $has_company, if $has_company==1 - user has company, if $has_company==0 he has not company. If user want connect company with ad, he must check checkbox :-) So I want to validate checkbox, If user check checkbox, and he has not company,I want to show messages, that first he must create company.... Is it possible? Can I use sfValidatorBoolean ? If yes, how to validate variable has_company? Thank you!
I think you can create a method in myUser class to check if the current user has a company (if your models user and company are linked).
And then, you can pass the result of this method in option of your form.
For validation, you can use a callback validator : http://www.symfony-project.org/forms/1_4/en/B-Validators#chapter_b_sub_sfvalidatorcallback
you can use halt_on_error option like
$v = new sfValidatorAnd(
array(
new sfValidatorString(array('max_length' => 255)),
new sfValidatorEmail(),
),
array('halt_on_error' => true),
array('invalid' => 'The input value must be an email with less than 255 characters.')
);
Related
I am wondering if the updateOrCreate method in Laravel has a way to skip some information in case the record exists in the database. For example, I wanna be able to search for users, and assign a password if the user is to be created, but not if the user already exists.
Say, I have 3 data for a user, $email, $info and $password. The search criteria would of course be $email, then maybe $info needs to be updated for whatever reason, while $password should only be given if the record is new.
Is there a 'do not update' parameter for updateOrCreate where I can put the password?
User::updateOrCreate(
[
'email' => $email // These parameters are the search criteria, but also used on create
],
[
'data' => $info, // These parameters are the values that will be updated if exist
],
[
'password' => $password, // These parameters are used only in create but are not search criteria
]
);
There are so many questions I would have love to ask to fully understand your organization's process.
1.How did the information get to the db at the first place if the user has not be created?
2. Why can't the password be generated when creating the info into the db at the first place
But I guess all these might bore down to design issue so, I think would say you can create a regular expression that would match your organization document number pattern and use it to check for new user through a loop and the assign password to such ones.
when user unsubscribes from list he can't subscribe again with the same email address. How can allow user to resubscribe to list?
$unsubscribe = $mailChimp->call('lists/unsubscribe',array(
'id' => $list_id,
'email' => array('email' => $email),
true,
true
));
If you want to resubscribe the user later, you need to delete him, see the documentation:
When you need to remove a few subscribers, decide whether you want to delete
them yourself or unsubscribe them. Deleted subscribers can be added
back to your list, so if you need to make sure a subscriber isn't
accidentally re-added, unsubscribe them instead.
If you are using the latest mailchimp-api then you can delete the user as follows:
include 'Mailchimp.php';
use \DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp('your**api***key');
function deleteUser($email){
global $MailChimp;
//your list_id from Mailchimp
$list_id = 'your***list**id';
$subscriber_hash = $MailChimp->subscriberHash($email);
$MailChimp->delete("lists/$list_id/members/$subscriber_hash");
}
If no user with that email exists, then $MailChimp->delete() will return an array like this:
Array ( [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ [title] => Resource Not Found [status] => 404 [detail] => The requested resource could not be found. [instance] => )
If the user was found, then the method will not return anything. Note that this does not imply that the user has been deleted, because if the user has been unsubscribed previously, then its not possible to delete him.
If you do not want to use the api, then you can also write your own custom curl command using the delete verb.
Try deleting the email from list and re-subscribe the same.
You can delete the member by setting delete_member property to true in unsubscribe method
You can do it by updating the user to a status of "pending"
Unfortunately my code is the Python api, but you should be able get the idea.
def mcResendSubscriptionSignup(self,email,audienceId):
# calculate the hash of the email address
emailHash = hashlib.md5(email.lower().encode()).hexdigest()
# get existing user, and all their data
data = self.mcClient.lists.members.get(list_id=audienceId, subscriber_hash=emailHash)
# set the user status to pending to resend subscription email
data['status'] = 'pending'
# update the data back to the user record in the audience
data = self.mcClient.lists.members.update(list_id=audienceId, subscriber_hash=emailHash, data=data)
print(f'Sent a resubscription email to {email}')
This function will resend a confirmation email to the user which he has to click on to resubscribe. Note, you need to also find your audienceId.
This is the only way that Mailchimp will allow you to re-add the user to an audience as of 2020, after an unsubscribe.
Yes, this is a pain when testing, which is why I worked on this function. Tiny bit better than doing it in the GUI interface.
https://developer.paypal.com/braintree/docs/guides/recurring-billing/create
result = Braintree_Subscription::create(array(
'paymentMethodToken' => 'the_token',
'planId' => 'silver_plan'
));
Is it a random generated string in my code? Or is it something else?
The paymentMethodToken is a unique identifier for the customer's credit card to use. After you create a Customer with a stored payment method you can use the returned token to subscribe a user to a plan. This article explains it well:
https://developer.paypal.com/braintree/docs/guides/recurring-billing/overview
The default JUser::setParam() method sets parameters only to the session. Is is possible somehow to store parameters not in the session, that they would be always available? I also found in users table field params, which stores some parameters for current user, but don't know how to add data there...
Have you tried to save the object after adding your param?
$user = JFactory::getUser();
$user->setParam($key, $value);
$user->save;
An easy and comfortable approach would be to use the popular Community Builder Extension which lets you define custom user fields in the administrator backend. It has an API to obtain the CB User Object and to write and read those fields which get stored in the DB as opposed to the session. Simple example without knowing your Joomla/CB version (works with Joomla 2.5 and CB 1.8) and the place (site, admin, external) where this should be executed (assuming your parameter is named customParam and the user id is 42):
cbimport( 'cb.field' );
$mosCbUser = CBUser::getUserDataInstance(42);
// read value
$customParameter = $mosCbUser->customParam;
// write value
$mosCbUser->customParam = 'newnew';
$mosCbUser->store();
/* write value to DB directly with optional boolean third parameter
specifing whether to trigger the user update plugins
like onBeforeUserUpdate or onAfterUserUpdate
*/
$mosCbUser->storeDatabaseValue('cb_adresse', 'new address', false);
be sure to be in CB plugin context, if not already the case, include e.g. like
global $_CB_framework, $_CB_database, $ueConfig;
$app = JFactory::getApplication();
include_once( $app->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' );
I am making a password reset form, which contains two fields: password1 and password2. The user enters their new password and then re-types their new password again.
I'm not sure how to make a validation rule that will compare the two values from the fields and see if they're the same.
IMHO it's more trouble than worth to create a separate rule in this case. You could, if you want to code "pure" CakePHP, but it's easier to just compare the fields in the controller and invalidate one of them manually if they don't match:
if( $this->data[ 'User' ][ 'password1' ] != $this->data[ 'User' ][ 'password2' ] ) {
$this->User->invalidate( 'password2', "The passwords don't match." );
}
if you are using Auth component then you need to hash the second password in the controller, because the password will be automatically hashed.
To compare 2 fields, you need to write a custom validation rule: http://bakery.cakephp.org/articles/aranworld/2008/01/14/using-equalto-validation-to-compare-two-form-fields (read the comments also, because the tutorial itself is kind of old)
I just happen to have written a behavior for this 2 days ago:
https://github.com/dereuromark/tools/blob/master/Model/Behavior/PasswordableBehavior.php
some sample code how to use it:
http://www.dereuromark.de/2011/08/25/working-with-passwords-in-cakephp/