WordPress Contact form 7 entry to database without plugin - wordpress

I tried with sort codes to enable database access form contact form 7 but I got failed.
is there any way to handle contact form 7 data's to database without any plugin or add on. I need to finish this through editing the plugin from backend. Can you please help me ??

<?php
function contactform7_before_send_mail( $form_to_DB ) {
//set your db details
global $wpdb;
$table = $wpdb->prefix.'candidate';
$form_to_DB = WPCF7_Submission::get_instance();
if ( $form_to_DB )
{
$formData = $form_to_DB->get_posted_data();
$firstname = $formData['first_name'];
$lastname = $formData['last_name'];
$phoneno = $formData['phone_no'];
$data = array('first_name' => $firstname, 'last_name' => $lastname, 'phone_no' => $phoneno);
$wpdb->insert( $table, $data, array( '%s','%s','%s' ) );
}
}
add_action( 'wpcf7_before_send_mail', 'contactform7_before_send_mail' );
?>

Related

WordPress additonal check while login

When a user register in my site I have set the user_activation_key column value from wp_users table like that:
$code = sha1( $user_id . time() );
global $wpdb;
$wpdb->update(
$wpdb->prefix.'users', //table name
array( 'user_activation_key' => $code ),
array( 'ID' => $user_id ),
array( '%s' ),
array( '%d' )
);
It's because I want to make activation system by sending an email with clickable link:
$activation_link = add_query_arg(
array(
'key' => $code,
'user' => $user_id
), get_permalink( 44 )
);
$message = "<div style='padding : 20px; border : 1px solid #ddd; color : #000;'>Hello $surname, <br/><br/>Please confirm your email addresss . Click this link to confirm : <a href='$activation_link'>Confirm Now</a><br/><br/></div>";
$to = $email;
$subject = 'Confirm your registration process"';
$body = $message;
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $to, $subject, $body, $headers );
Now, the column user_activation_key has the hash code and user_status column value is 0
Now the actual question:
When user go to www.site.com/wp-admin that means login page I want to show an error message if the user_status column value is 0.
I don't' have any idea which hook or how can I cehck this while user login?
Use the admin_notices hook to display messages in the backend, the code below is similar to what your after:
add_action('admin_notices', 'account_activation_check');
function account_activation_check() {
global $wpdb;
// setup vars //
$currentID = get_current_user_id();
$user = get_user_by( 'ID', $currentID );
$userStatus = $user->user_status;
// check if user status is 0 //
if($userStatus == 0) {
echo '<div class="error"><p>Your email has not been verified!</p></div>';
}
}
I have solved the issues by using the wp_authenticate_user hook. Here is the code:
add_filter( 'wp_authenticate_user', 'shibbir_authenticate_user', 10, 2 );
function shibbir_authenticate_user( $user ) {
if ( $user->data->user_status == 0 ) {
return new WP_Error( 'error', __( 'Your account is not activate, Please contact site admininstrator.' , 'shibbir' ) );
}
return $user;
}

WordPress - set display name from nickname with register process

It is possible set display name from entered string into nickname registration field? I trying do this with simple hook, but after all it is not work.
function set_default_display_name( $user_id ) {
$user = get_userdata( $user_id );
$name = $user->nickname;
$args = array(
'ID' => $user_id,
'display_name' => $name
);
wp_update_user( $args );
}
add_action( 'user_register', 'set_default_display_name' );
By default immediately after registration the display name was set from WP username (login) not nickname. Can sombody help me to set a display name from nickname?
// change default display name format
add_action('user_register', 'registration_save_displayname', 1000);
function registration_save_displayname($user_id) {
if ( isset( $_POST['first_name'])){
$pretty_name = $_POST['first_name'];
wp_update_user( array ('ID' => $user_id, 'display_name'=> $pretty_name) ) ;
}
}

How to connect registration form to database in WordPress

How to connect registration form to database in WordPress
Connect registration page in WordPress to MySQL databases?
Create Your custom form and use wp_insert_user function for user registration.
<?php
$website = "http://example.com";
$userdata = array(
'user_login' => 'login_name',
'user_url' => $website,
'user_pass' => $password,
);
$user_id = wp_insert_user( $userdata ) ;
//On success
if ( ! is_wp_error( $user_id ) ) {
echo "User created : ". $user_id;
}
?>
To add a user use ether wp_insert_user or wp_create_user. wp_create_user ONLY creates a user, and does not allow for managing any extra user fields. wp_insert_user allows for filling in all user fields.
<?php wp_insert_user( $userdata ); ?>

Gravity Form save to Database usermeta table

I have created the following wordpress function to save a form created in Gravity Forms to the usermeta database based on one I had working for CF7 but it isn't working, hopefully someone can see where I've made a mistake. It needs to update the current users fields.
add_action('gform_after_submission', 'input_fields', 10, 2);
function input_fields($entry, $form){
$name = $entry['1'];
$email = $entry['4'];
global $wpdb, $current_user;
$wpdb->insert(
'usermeta',
array(
'description' => $email,
'former_name' => $name
)
);
}
I've seen other examples which are pretty much identical so i'm a bit stuck.
This should do the trick:
add_action( 'gform_after_submission', 'input_fields', 10, 2 );
function input_fields( $entry, $form ) {
$name = $entry[1];
$email = $entry[4];
update_user_meta( get_current_user_id(), 'description', $email );
update_user_meta( get_current_user_id(), 'former_name', $name )
}
Alternately, I'd recommend upgrading to a Developer license and getting access to the User Registration add-on which would do this even more easily. :)
Semicolon sign ";" is missing at line 8 so this is right the answer. :)
add_action( 'gform_after_submission', 'input_fields', 10, 2 );
function input_fields( $entry, $form ) {
$name = $entry[1];
$email = $entry[4];
update_user_meta( get_current_user_id(), 'description', $email );
update_user_meta( get_current_user_id(), 'former_name', $name );
}

How is wordpress user validation works?

I have created a custom registration form in the front end using wp_insert_user() function:
$data = array();
$data['user_login'] = $_POST['username'];
$data['user_email'] = $_POST['email'];
$data['user_pass'] = wp_generate_password ( 12, false );
$data['role'] = 'pending';
$user = wp_insert_user( $data );
if ( is_wp_error($user) ){
$error = $user->get_error_message();
echo json_encode( array( 'loggedin' => false, 'info' => $error ) );
} else {
wp_new_user_notification( $user, $data['user_pass'] );
}
But I want the user to receive an activation email with activation link. How can I do this?
If you look at the WordPress codex for the wp_new_user_notification method (http://codex.wordpress.org/Function_Reference/wp_new_user_notification#Examples), there is an example of how to redefine this function. In that example, functionality is added to send an email to the created user.

Resources