Automatically populate username and mail on a contact sidebar form
There is another thing I would like to see on Classipress – that my username and e-mail is automatically entered into contact form. Here I’m going to show you how easy it is to correct this.
This modification was tested on Classipress 3.3.x, 3.4.x, 3.5.x and 3.6.x
This tutorial requires you to change this file:
wp-content/themes/classipress/includes/sidebar-contact.php
It is recommended to make backup of this file before changing it.
Step 1
Locate this code:
?> |
and ADD this BEFORE it (put code before ?> ):
$current_user = wp_get_current_user(); if ( 0 != $current_user->ID ) { $contact_username = $current_user->display_name; $contact_usermail = $current_user->user_email; } if(!isset($contact_username)) $contact_username = $_POST['from_name']; if(!isset($contact_usermail)) $contact_usermail = $_POST['from_email']; |
Then locate this in line 29:
<input id="from_name" class="text required" name="from_name" type="text" value="<?php if(isset($_POST['from_name'])) echo esc_attr( stripslashes($_POST['from_name']) ); ?>" /> |
And replace it with this:
<input id="from_name" class="text required" name="from_name" type="text" value="<?php echo esc_attr( stripslashes($contact_username) ); ?>" /> |
Then locate this in line 44:
<input id="from_email" class="text required email" name="from_email" type="text" value="<?php if(isset($_POST['from_email'])) echo esc_attr( stripslashes($_POST['from_email']) ); ?>" /> |
And replace it with this:
<input id="from_email" class="text required email" name="from_email" type="text" value="<?php echo esc_attr( stripslashes($contact_usermail) ); ?>" /> |
That’s it.
If you find any issues with this tutorial, please be so kind and write a comment. I’ll try to help as much as I can.
If you find this tutorial useful, please consider making a small donation.
Please brother,
In this “wp-content/themes/classipress/includes/sidebat-contact.php”
please correct “/sidebar-contact.php” Me visitor got confused for a short while
thanks and regards
Thank you for this. It is corrected.
Hi bro, regarding this post, blogspot tuto and this web tuto are not same I tried few times, not working out. You have used “class” and “name” in different place. Please can you check and advice which one to follow. But a small error somewhere I think so. Pleaseeee…
Sorry, for this error. The version here was apparently from some other ClassiPress version. It is corrected now. Please try it and let me know.
Regards
Now charming bro,
If you don’t mind, I want your help in this page to change from “<form class" as "<form name" I did it in my and itz charming bro…
Hi ! I tried to use this mod on Classipress 3.6.1 but the file sidebar-contact.php is so different. Please, did you update it ? I can send you the file or let me see if it fits below.
Thank you four your help !
Fabienne
ID );
if ( $result->get_error_code() ) {
$error_html = ”;
foreach ( $result->errors as $error ) {
$error_html .= $error[0] . ”;
}
$msg = array( ‘error’, $error_html );
} else {
$msg = array( ‘success’, __( ‘Your message has been sent!’, APP_TD ) );
}
}
?>
<input name="from_name" id="from_name" type="text" minlength="2" value="” class=”text required” />
<input name="from_email" id="from_email" type="text" minlength="5" value="” class=”text required email” />
<input name="subject" id="subject" type="text" minlength="2" value=" ” class=”text required” />
<input name="submit" type="submit" id="submit_inquiry" class="btn_orange" value="” />
Please attach the file to email and I’ll do the change for you.
Blaz
Thank you so much Blaz, that wonderfully works !
Kind regards
Fabienne