Recalling previous user's information for form autofill - database

I have this form a user completes and their information is transferred to the next landing page's form for lead generation so they don't have to refill another form.
is there anyway to have the database dynamically create links so if the user leaves the landing page and clicks the link they will be directed to the landing page with all form filled information filled out how it was before?
this is the code that calls on the data
global $wpdb;
if ($_SESSION['form'] == 'old') {
$FirstName = $_REQUEST['FirstName'];
$LastName = $_REQUEST['LastName'];
$Address1 = $_REQUEST['Address1'];
$Email = $_REQUEST['Email'];
}
else {
$FirstName = $_REQUEST['first_name'];
$LastName = $_REQUEST['last_name'];
$Address1 = $_REQUEST['street'];
$Email = $_REQUEST['form_email'];
}
$_SESSION['FirstName'] = $FirstName;
$_SESSION['LastName'] = $LastName;
$_SESSION['Address1'] = $Address1;
$_SESSION['Email'] = $Email;
then the form echos in the fields required

Related

Email form when an item is submitted

I am new to Nintex. How can I send the form user submitted in the email after he/she hits submit button?
I tried to to create a workflow, but it just sends email without content.
You can include the item URL in the body your email - the link will take them back to the item/form that they just submitted
or
you can use the lookups to insert the fields on your email
/*
* This function sends an email when a specific Google Sheets column is edited
* The spreadsheets triggers must be set to onEdit for this function to work
*/
function sendNotification() {
//var ss = SpreadsheetApp.openById('1N6dqSXs8hdhCi1vrOGT7I7tD2yDMtgK7BSddMPqmuo0');
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//Get Active cell
var mycell = ss.getActiveSelection();
var cellcol = mycell.getColumn();
var cellrow = mycell.getRow();
//Define Notification Details for vars
var recipients = "joseph#XXXXX.com,jmang#XXXXX.com";
var recipients1 = "joseph2#XXXXX.com"
var subject = "NEW SENSITIVE DATA REQUEST REQUIRES APPROVAL";
var subject1 = "ALERT: SENSITIVE DATA REQUEST";
var body = ss.getName() + " has been updated. Visit " + ss.getUrl() + " to view the changes.";
//Check to see which column will trigger the email - this script sends an email to "var recipients" if
//column 5 is updated and sends and email to "var recipients1" when colum 7 is updated.
if (cellcol == 5) {
//Send the Email to recipients defined in "var recipients"
MailApp.sendEmail(recipients, subject, body);
}
if (cellcol == 7) {
//Send the Email to recipients defined in "var recipients1"
MailApp.sendEmail(recipients1, subject1, body);
}
//End sendNotification
}

Override registration module & Hide or show input text drupal 7

I created a module and a hook to override the registration module form :
function custommodule_form_alter(&$form, $form_state, $form_id) {
// retrieve name & surname
global $user;
$user_fields = user_load($user->uid);
$name = $user_fields->field_name['und']['0']['value'];
$surname = $user_fields->field_surname['und']['0']['value'];
// var_dump($name); die();
// check the form_id
if($form_id=='registration_form'){
if( $form['who_is_registering']['#options']['registration_registrant_type_me'] =='Myself') {
$form['field_name']['und'][0]['value']['#default_value'] = $name;
$form['field_surname']['und'][0]['value']['#default_value'] = $surname;
} else {
$form['field_name']['und'][0]['value']['#default_value'] = '';
$form['field_surname']['und'][0]['value']['#default_value'] = '';
}
}
}
In the original module we can hide or display a field depending on the select value. For example if the select is positionned on "Myself", the user mail field is not visible.
I'd like to set the fields to empty if the select is positionned on "Myself" and to show empty fields otherwise.
Actually the name and surname are defined in the fields.

CakePHP 2.4 Forgotten Password

I have just started using CakePHP and love using it! I have created a login system and registration system, however am really struggling with the "forgotten password" section.
I want to use a tokenhash and expiry date in the Users DB so that it cant be abused, users would need to enter username and email to get an activation link emailed to them with a newly generated tokenhash
There are quite a few tutorials out there but I find most of them work for the first part e.g. emailing the activation link/ resetting token and timer but all seem to fail on the change of the password.
Please help me, either with a working tutorial from the net or a solution that applies the above required things.
Thanks in advance
Steve
Below I am writing the code that I wrote for one of my project, this might help you out.
1- I created a new table which contains the unique token for every user.
Table Name:- user_password_resets
Columns : userclient_id, token
2- A email template name as:- change_password.html inside /webroot/template/change_password.html
public function login_send() {
$this->isLoggedIn(); //Check if the user is logged in
if($this->request->is('post')) { #if the form is submitted
$login = $this->data['User']['login'];
$conditions = array('User.login'=>$login);
if($this->User->hasAny($conditions)) {
$users = $this->User->find('first', array('conditions'=>$conditions));
#Generate the token
$token = md5(uniqid(rand(),true));
#Save token and other details in user_password_reset_links table
$users = $this->User->find('first', array('conditions'=>array('User.login'=>$login)));
$my_name = $users['User']['first_name'];
$reset_links = array();
$reset_links['UserPasswordReset']['userclient_id'] = $users['User']['client_id'];
$reset_links['UserPasswordReset']['token'] = $token;
$conditions = array('UserPasswordReset.userclient_id'=>$users['User']['client_id']);
if($this->UserPasswordReset->hasAny($conditions)) {
$user_id = $users['User']['client_id'];
$this->UserPasswordReset->updateAll(array('UserPasswordReset.token'=>"'$token'"), array("UserPasswordReset.userclient_id"=>"$user_id"));
} else {
$this->UserPasswordReset->create();
$this->UserPasswordReset->save($reset_links);
}
$password_reset_link = BASE_URL."users/reset_password/$token";
#Send Welcome Email
$mailContent = file_get_contents(BASE_URL . "templates/change_password.html");
$rootlink = BASE_URL;
$arrMail = array(
"{NICK}" => ucfirst($my_name),
"{rootlink}" => BASE_URL,
"{SITE_TITLE}" => SITE_TITLE,
"{PASSWORD_RESET_LINK}"=>$password_reset_link
);
$mails = explode(',', $users['User']['email']);
$msg = #str_replace(array_keys($arrMail), array_values($arrMail), $mailContent);
$data = array();
$data['to'] = #$mails[0];
$data['body'] = $msg;
$data['subject'] = SITE_TITLE.'- Reset Password.';
$this->send_mail($data);
$this->Session->setFlash('A password reset link has been sent to the email address.', 'default', array('class'=>'successMsg'));
$this->redirect(array('controller'=>'users', 'action'=>'login'));
exit;
} else {
$this->Session->setFlash('The Username entered is not registered with Captain Marketing.', 'default', array('class'=>'errorMsg'));
$this->redirect(array('controller'=>'users', 'action'=>'login_send'));
exit;
}
}
$this->set('title_for_layout', '-Send password reset link');
}

Wordpress: Create pages through database?

Currently I am working on a new traveling website, but am having problems with 1 thing:
I have a list with all the country's, regions and city's i want to publish. How do I quickly create a page for all of them like this:
Every page should be a subpage like: country/region/city
Every page should have a certain page template
Please let me know, thanks in advance for your time and information!
You can do something like this.
<?php
// $country_list = get_country_list(); // returns list, of the format eg. array('India' => 'Content for the country India', 'Australia' => 'Content for the country Australia')
// $region_list = get_region_list($country); // Get the list of regions for given country, Assuming similar format as country.
// $city_list = get_city_list($region); // Get the list of cities for given region, Assuming similar format as country
/* Code starts here...*/
$country_list = get_country_list();
foreach($country_list as $country_title => $country_content) {
$country_template = 'template_country.php';
$country_page_id = add_new_page($country_title, $country_content, $country_template);
// validate if id is not 0 and break loop or take needed action.
$region_list = get_region_list($country_title);
foreach($region_list as $region_title => $region_content) {
$region_template = 'template_region.php';
$region_page_id = add_new_page($region_title, $region_content, $region_template, $country_page_id);
// validate if id is not 0 and break loop or take needed action.
$city_list = get_city_list($region_title);
foreach($city_list as $city_title => $city_content) {
$city_template = 'template_city.php';
add_new_page($city_title, $city_content, $city_template, $region_page_id);
}
}
}
function add_new_page($title, $content, $template_file, $post_parent = 0) {
$post = array();
$post['post_title'] = $title;
$post['post_content'] = $content;
$post['post_parent'] = $post_parent;
$post['post_status'] = 'publish'; // Can be 'draft' / 'private' / 'pending' / 'future'
$post['post_author'] = 1; // This should be the id of the author.
$post['post_type'] = 'page';
$post_id = wp_insert_post($post);
// check if wp_insert_post is successful
if(0 != $post_id) {
// Set the page template
update_post_meta($post_id, '_wp_page_template', $template_file); // Change the default template to custom template
}
return $post_id;
}
Warning: Make sure that the is executed only once or add any validation to avoid duplicate pages.

how to recieve confirmation code to register users?

I am applying this tutorial: Activating User Account via Email
When I submit the message, it is sent like this:
Hey there ahmed, we will have you up and running in no time, but first we just need you to confirm your user account by clicking the link below:
http://localhost/cakenews/users/activate/24/8877ae4a
The problem is that I want to create file users/active.ctp to receive activation code when the user clicks on the link. But I dont know what to write on this file to active user
<?php
# /controllers/users_controller.php
# please note that not all code is shown...
uses('sanitize');
class UsersController extends AppController {
var $name = 'Users';
// Include the Email Component so we can send some out :)
var $components = array('Email', 'Auth');
// Allow users to access the following action when not logged in
function beforeFilter() {
$this->Auth->allow('register', 'confirm', 'logout');
$this->Auth->autoRedirect = false;
}
// Allows a user to sign up for a new account
function register() {
if (!empty($this->data)) {
// See my previous post if this is forgien to you
$this->data['User']['password'] = $this->Auth->password($this->data['User']['passwrd']);
$this->User->data = Sanitize::clean($this->data);
// Successfully created account - send activation email
if ($this->User->save()) {
$this->__sendActivationEmail($this->User->getLastInsertID());
// this view is not show / listed - use your imagination and inform
// users that an activation email has been sent out to them.
$this->redirect('/users/register');
}
// Failed, clear password field
else {
$this->data['User']['passwrd'] = null;
}
}
}
/**
* Send out an activation email to the user.id specified by $user_id
* #param Int $user_id User to send activation email to
* #return Boolean indicates success
*/
function __sendActivationEmail($user_id) {
$user = $this->User->find(array('User.id' => $user_id), array('User.id','User.email', 'User.username'), null, false);
if ($user === false) {
debug(__METHOD__." failed to retrieve User data for user.id: {$user_id}");
return false;
}
// Set data for the "view" of the Email
$this->set('activate_url', 'http://' . env('SERVER_NAME') . '/cakenews/users/activate/' . $user['User']['id'] . '/' . $this->User->getActivationHash());
$this->set('username', $this->data['User']['username']);
$this->Email->to = $user['User']['email'];
$this->Email->subject = env('SERVER_NAME') . ' - Please confirm your email address';
$this->Email->from = 'email#gmail.com';
$this->Email->template = 'user_confirm';
$this->Email->delivery = 'smtp';
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'host' => 'ssl://smtp.gmail.com',
'username'=>'email#gmail.com',
'password'=>'password',
);
$this->Email->sendAs = 'text'; // you probably want to use both :)
return $this->Email->send();
}
}
/**
* Activates a user account from an incoming link
*
* #param Int $user_id User.id to activate
* #param String $in_hash Incoming Activation Hash from the email
*/
function activate($user_id = null, $in_hash = null) {
$this->User->id = $user_id;
if ($this->User->exists() && ($in_hash == $this->User->getActivationHash()))
{
// Update the active flag in the database
$this->User->saveField('active', 1);
// Let the user know they can now log in!
$this->Session->setFlash('Your account has been activated, please log in below');
$this->redirect('login');
}
// Activation failed, render '/views/user/activate.ctp' which should tell the user.
}
?>
and the model is
/**
* Creates an activation hash for the current user.
*
* #param Void
* #return String activation hash.
*/
function getActivationHash()
{
if (!isset($this->id)) {
return false;
}
return substr(Security::hash(Configure::read('Security.salt') . $this->field('created') . date('Ymd')), 0, 8);
}
}
?>
the views is cakenews\app\views\users\register.ctp
<fieldset>
<legend>Add a article</legend>
<?php
echo $form->create('User');
echo $form->input('username');
echo $form->input('password');
echo $form->input('email');
?>
</fieldset>
<?php echo $form->end('Post project'); ?>
In your controller action activate is handling the user activation. If user is verified it redirects to login action otherwise it will try to render activate.ctp file. So in that case you can just show a message to the user that your registration could not be completed. please try again. To set some data for the view (activate.ctp) you can use controller's set method.
If you don't want to render activate.ctp file at all redirect the user to somewhere else telling registration could not be completed.

Resources