Form with email validation with Drupal - php

I need to create this using Drupal, but I have no idea how to simply implement this.
Form with an input to insert an email and a submit button.
When the form is submit, send a validation email to make sure the email addr is valid
When the user validate the email (clicking the link in his email), the email is stored in the database.
Thanks a lot for your help!

I guess there are better solutions, but here is a rather simple way. I assume you do know how to basically do stuff in Drupal like creating forms, storing information in the database, sending mails and so on. If not, there is a link for each...
Define a table with email (varchar), key (varchar), status (int) (hook_schema)
Create a form where the user can enter the email (how to create a form
Store the mail in the database together with a random key (like md5($mail . uniqueid()) (db_insert for D7, db_query for D6), set status to 0
Send a mail to the user with a link that contains the key like yourmodule/verify/$key (drupal_mail
Register that path (yourmodule/verifiy/%) in hook_menu
When the user clicks on the link, look for that key in the database and set status to 1 (db_query + db_update (D7 only))
Done, all mails with status 1 are now confirmed.
And as others have mentioned, drupal core user registration is already doing this.

Related

How to send verification email after registration form in extjs

How verification email is sent to user after filling in registration form? Let's say that I have a registration form as given in picture, and I would like to send the verification email to email entered in the form, so only after user confirms it, I can create new record in MySql database. In this context, I don't understand two things:
How to send verification email, and
What happens, when user clicks on that email and confirms. How in that case server knows that verification was successful, and how new user is created in database. I know that in case of classic registration, if all fields are correct, a PHP code is used to create new record in database for that user. But how to achieve this with additional confirmation email?
I can provide you with simple solution:
Create an function that will send an email with text and some link like: www.site.com/activate.php?random=ng8a8712jh3j
Where activate.php is your script which will get the randomly generated code and will match it with this specific email/user, and will set the status as activated.
Create an extra field into your table where the registration is going, and name it like user_status and you may assign default value of inactive or 0 and as soon as the user opens the link you will match the random code with the user ID and set the user_status to active or 1.
You can use swiftmail framework to send emails with html or just simple text.

How to create this type of form in PHP

I have to put a sort of "double opt-in newsletter registration form" in a website.
Since I don't know much about php, I thought about how to limit the code I have to write, and I thought this:
I want to create a registration form (with fields: name, email address and an OBLIGATORY checkbox); when the user clicks Submit:
Of course it checks that all the fields are filled in.
An email is sent to that email address.
User RESPONDS to that email, I see the reply on my email and I manually add him to my mailing list.
Is this a reasonable thing? If so, how do I do that?
Thanks.
I wanted to add some steps to make it automatic, you don't have to do it manually
Of course it checks that all the fields are filled in.
An email is sent to that email address. with a unique link with some random key
link http://domain.com/confirm.php?regId=4&key=DTSRROymc90JDklrTu2wi64Nny0
User RESPONDS to that email by clicking on confirm link in email,
You get the response from confirm.php?regId=4&key=DTSRROymc90JDklrTu2wi64Nny0 and update its status to confirmif its found in db using regId=4 and key=DTSRROymc90JDklrTu2wi64Nny0
in confirm.php
if(isset($_GET['regId']) && isset($_GET['key'])) {
//Get the reg details and update the status if row found in db
....
}
Here is an script, give it a try

CodeIgniter | How to solve this logical issue?

I have a function that lets you update your information, like email and username. The email field has a validation is_unique[table.email]. When lets say the user doesn't want to change the email, but just the country or other info, the is_unique is going to display the message. But if I remove it in update page, the user might put an email address that is already in database.
What would be best logical method of solving this issue?
Assuming you are using a database query and counting the number of rows it returns (0 meaning that the address is free), you'll want to pass the user's unique ID along:
$result = $this->db->where('email_address',$email)->where('id !=',$userid)->get('users')->num_rows();
What I just did above will check if anyone other than our current user is signed up with the requested email. If this user wants to just update his/her country, it won't trigger an error.
edit: This would be in your custom form validation rule __unique_email() or something similar. Which needs to be in the controller.
Compare the email that's being submitted to the email in the database. If it's different then use the email validation. If not, don't.
you can add a hidden field in your form containing the value of the current email address then if the submitted value is different run the validation

Email confirmation with prototype.js?

I have a simple name and email form built in Ajax, PHP and mySQL.
The user enters a name, and email address and the fields are saved into a database.
How can I once the name and email have been submitted, send a confirmation email to this user?
I think you're after (double) opt-in. Just to give a basic outline how you can achieve your goal.
Register user details to your db.
Store a unique token for every user (every action: new user/lost pw/etc.)
Store a token lifetime value (the date until token is accepted as valid)
Use some Mail library for PHP (PHPMailer)
Send a greeting (validation) message for every new user including their unique tokens
If user opens the provided link, you could set a flag so user is active from now on.
Note: Since this is just a basic outline i am not mentioned any security pitfalls.
As you haven't provided us much info that's why I'm just giving a imperfect answer here.--
See first in your registration code use bin2hex on username to generate activation code because this will make sure that each user have different activation code. And use INSERT INTO mysql syntax and insert the activation code in a new column named activation_code or maybe anything as per your needs.
Secondly if registration is successful just send a mail to the email id you just retrieved from the user using mail($to, $subject, $body, $headers) function where set $to to your user email id.
Then create a page, just name it as activation.exec.php where you would get the activation code from the URL, the URL has to be sent to the user, and don't forget to include user id or email id in that link.
Thirdly add a mysql query to check that the user id you just got from the URL is in your database or not. And then check that the activation code in the database is similar to the one you just received from the URL. And if successful redirect him to the Activation Successful page.
I hope this would help you.

Best practices: how to implement an invitation system in Zend Framework?

I've built out most of the functionality, now I'm getting stuck...
I am creating a private, web application that has an invite only registration system. An admin user sends an email invitation to a user, the user clicks the link, and takes them to a page where they can create an account that has been linked to their email address.
When the form is submitted and does not have any validation errors, the data is inserted into the database for the first time. The email column of the invitations table is unique, so this is the token that the user needs in order to verify that they have permission to create an account.
The situation that I am confused about is when the admin user tries sending an invitation to the same email address. The email address column is unique so there is an SQL error. I don't know if I should do a check for that email address before inserting that record in the database, or what I should do.
I want to create a re-send invitation feature for emails that get lost, or accidentally deleted. Which is why I didn't want the admin user to be able to send a duplicate email to the same person, rather, they should use the re-send feature.
I hope this is all making sense. Any insights would be appreciated.
I use paper and pen to visualaize what I realy want. If the flow is clear I think you can make it ;)
I would definitely add a check to see if that address is already in the database before you attempt the insert. You could trap for the exception, but I would prefer to explicitly test for the presence of the email address.
An idea for you... When the email address already exists, you could make the system resend the invite. If you did that, you may be able to reduce some code repeat by not having to write an additional 'resend invite' function. Just call the same 'send invite' function on the initial invite request, or a 'resend invite' link described by others.
I also like the idea that others have already mentioned of the "Resend invite", especially philipnorton42's implementation.
I would use a validator inside your form, so the emailaddress is checked against your allready stored emails. So there should be no duplicate entry. Also i would implement an action that lists all your entered accounts and the creation- and activationtime in a nice table. Of course the action and view will support a pagination, so you can easy navigate through your data. If an entry has not yet been activated there should be a link, maybe an icon too, to a resend-the-email action for this special entry. And another action which resend the email to all not yet activated entries would be handy. Last but not least i would implement a reporting action so i can easily figure out whats going on.
I would say that Valter is correct, you perhaps need to draw out what you want to accomplish.
However, you appear (from what I can tell) to have all of the information in place for a "Resend invitation" button that the admin can click on to resend the invitation. I would create some reports in the backend that would allow me to view invitations that have been sent, that converted into users and that haven't been answered yet. Adding a button to the haven't answered yet report that resends individual invitations shouldn't be too hard.
Hum, i would create an view where all "Activations" are visible, with an button to just resend the invitation ? Without changing the record inside the database.

Categories