Can anyone help me with my feedback form for a website I am building?
I am not receiving any errors when I run this, although it doesn't actually send any email at all.
The following is the code I am trying to use:
<form action="mailto:admin#example.com" enctype="text/plain" method="post">
<p>Name: <input name="Name" type="text" id="Name" size="40"></p>
<p>E-mail address: <input name="E-mail" type="text" id="E-mail" size="40"></p>
<p>Comment:</p>
<p><textarea name="Comment" cols="55" rows="5"
id="Comment"></textarea></p>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
Sending mail from HTML Form is not a right option to do, you are using an HTTP Method (POST), so you have to set a http/https link from your action value. Otherwise, you have to send the email using the href tag, including a subject and body parameters.
E.g: Send Message
The mail application installed in your machine would automatically opened when you click that link.(Outlook, Gmail,...) and you can choose which one you have to send the mail within it.
you should maken a .php file
eg.
<form method="post" action="mail.php">
then in your mail.php put something like this:
<?php
session_start();
$to = "contact#webmagico.be"; // this is your Email address
$from = htmlspecialchars($_POST['email']); // this is the sender's Email address
$naam = htmlspecialchars($_POST['naam']);
$email = htmlspecialchars($_POST['email']);
$messageText = $naam . " " . $email . " wrote:" . "\n\n" . htmlspecialchars($_POST['bericht']);
$message = array(
"ontvanger" => $to,
"zender" => $from,
"naam" => $naam,
"email" => $email
);
$valid = true;
foreach($item in $message)
{
if(!isset($item) || $item === "")
{
$valid = false;
}
}
if($valid)
{
mail($to, $naam, $message, "From:" . $email);
}
else
{
$_SESSION['error'] = "Forgot something!"
}
/*file that gives the response*/
header('Location: thankyou.php');
?>
You can find different alternatives about a post-form on the web.
Hope this helps.
Related
I created a form that can send an email, but it is not redirecting to the php script when hitting submit.
Here is the form by the way
Code:
<form method="post" id="myForm" name="myForm" action="mail_handler.php">
<div class="row">
<div class="col-lg-12">
<div class="single-form">
<label>* FULL NAME</label> <input class="form-control" type="text" name="full_name" id="full_name" placeholder="Enter full name" required="">
</div>
</div><!-- Nice Select -->
<!-- First Name -->
<div class="col-lg-6">
<div class="single-form">
<label>* Email Address</label> <input class="form-control" type="email" name="emailAdd" id="emailAdd" placeholder="Enter email" required="">
</div>
</div>
<div class="col-lg-4">
<div class="single-form">
<input type="submit" name="submit" value="Submit" class="btn apply-btn mt-30">
</div>
</div>
</div>
</form>
and here is the mail_handler.php.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
if(isset($_POST['submit'])){
if(!empty($_POST['full_name']) && !empty($_POST['emailAdd'])){
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.mail.yahoo.com"; // sets yahoo as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = "my username"; // yahoo username
$mail->Password = "my pass"; // yahoo password
$full_name = $_POST['full_name'];
$emailAdd = $_POST['emailAdd'];
$subject = "Webpage Client Feedback";
$to = "cremlicofficial#yahoo.com";
$subject = "WEBPAGE: PRE-APPLICATION";
$mail->From = "cremlicit#yahoo.com";
$mail->FromName = "CREMLIC ADMIN";
$mail->AddAddress("cremlic#yahoo.com");
$mail->AddCC('cegabrillo#yahoo.com.ph');
$mail->AddCC('ksgaro#yahoo.com');
$mail->Subject = "WEBPAGE:PRE-APPLICATION";
$mail->Body = "To Whom it may concern, \r\n"
. "A visitor submits a pre-application information, please see details below. \r\n \r\n"
. "Name: " . $full_name . " \r\n"
. "Email: " . $emailAdd;
$mail->AddEmbeddedImage('./images/1593998909.jpg', 'palogo', '1593998909.jpg');
if(!$mail->Send()) {
echo '<script type="text/javascript">alert("Message was not sent. \r\nMailer error: '.$mail->ErrorInfo.'");window.history.go(-1);</script>';
}
}else{
echo '<script type="text/javascript">alert("Error Occured! \r\nPlease fill up fields: Name, Address and Contact No.");window.history.go(-1);</script>';
}
}
?>
I am 100% sure that both HTML file and PHP script is on the same folder. Is there any problem with these line of codes?
The form is working fine, kindly check the location of mail_handler.php if its in the same folder or in different folder. Also share mail_handler.php code so we can check if there's any issue with the code.
I've been trying to learn the basics of HTML, and in doing this I've been designing my own rudimentary webpage. I don't plan on making it public at all, but it's good to help me to learn all of the different aspects of both HTML and CSS. In doing this, I've added a Contact section on one of the pages, that includes both an email address and a form that allows for an E-mail to be sent, I used one of the tutorials on W3Schools to create it. For the purposes of this I have removed my own email address, and replaced it with someone#example.com, but here is the output of this specific part of the code:
However, whenever I try to fill the form in to test it, I get this pop-up message. If I click cancel, then nothing happens, but if I click OK then then the mail app on my computer is opened. But the message that I typed into the form isn't there, and the E-mail address that I type into the box to send from is just changed to the default address on my computer.
So what can I do to prevent this pop-up message, and to just send the e-mail to me?
Here is the relevant code from the HTML document:
<h2 style = 'font-weight:normal'><a name = 'Contact' id = 'Contact'></a>Contact me:</h2>
<p>
You can reach me at: someone#example.com <br />
Or by just using the form below
</p>
<form action = 'mailto: someone#example.com' method = 'post' enctype = 'text/plain'>
<input type = 'text' name = 'name' placeholder = 'Name'> <br />
<br />
<input type = 'text' name = 'mail' placeholder = 'E-mail'> <br />
<br />
<input type = 'text' name = 'comment' size = '50' placeholder = 'Comment'> <br />
<br />
<input type = 'submit' value = 'Send'>
<input type = 'reset' value = 'Reset'>
</form>
If HTML isn't going to be enough to send an e-mail from a webpage, and I need another language to write a program that can do it, I am quite competent in Python, and I know C# to some extent. However, I've never used JavaScript, PHP, Perl, or anything else (I don't know what sort of languages would be appropriate)
If you want to submit the form to go to an email it's simple really. You could use a simple server-side language like PHP. You'll need 3 files. One file that houses the front-end form contents, one file that processes the form once the user hits the submit button and a thank you page after the form gets sent to let the user know that the form has been submitted. Here is a demo below.
HTML:
<form action="processor.php" method="post" id="myForm">
<label for="firstname"></label>
<input type="text" name="firstname" placeholder="First Name" id="firstname" required>
<label for="lastname"></label>
<input type="text" name="lastname" placeholder="Last Name" id="lastname" required>
<label for="email"></label>
<input type="email" name="email" placeholder="Email" id="email" required>
<label for="comments"></label>
<textarea rows="4" cols="32" name="comments" id="comments" placeholder="Questions & Comments"></textarea>
<input type="submit" value="Submit">
</form>
PHP (processor.php file)
/***********************************************************/
/******* Set the receipient email address below ********/
/******* And set the subject line of the email ********/
/*$recipient_email = "testemail#yahoo.com";*/
$recipient_email = "testemail#yahoo.com";
$email_subject_line = "Mail from Website";
/***********************************************************/
/***********************************************************/
if(isset($_POST['firstname']))
{
$firstName = $_POST['firstname'];
$lastName = $_POST['lastname'];
$email = $_POST['email'];
$comments = $_POST['comments'];
if(!empty($firstName) &&
!empty($lastName) &&
!empty($email) &&
!empty($comments))
{
$message = "Name: $firstName, Lastname: $lastName, Phone: $phoneNumber,
Email: $email, Comments: $comments";
send_mail($email, $message, $recipient_email, $email_subject_line);
}
}
function send_mail($email, $message, $recipient_email, $email_subject_line)
{
$to = $recipient_email;
$from = $email;
$subject = $email_subject_line;
$headers = "From: {$email}" . "\r\n" . 'Reply-To:' . $email . "\r\n" . 'X-
Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
header("Location:thankyoupage.php");
thankyoupage.php (After data has been submitted)
<div class="thankyoucontainer">
<h1>Thank you, your message has been submitted.</h1>
Go back to home page
</div>
Hey guys I'm just starting to learn some php and I was wondering how I could send information from a completed form to an email. I have the code I have listed on the bottom but I know it's not right, any help will be appreciated thanks!
PHP:
<?php
$email = $_REQUEST['clientEmail'] ;
$subject = "New Order";
$name = $_REQUEST['clientName'] ;
$articleAmount = $_REQUEST['articleNum'];
$wordAmount = $_REQUEST['wordNum'];
$topic = $_REQUEST['topic'];
$info = $_REQUEST['addInfo'];
mail("kevin.duan996#gmail.com", $subject,
"Name:" . $name . "<br/>" . "Amount of Articles:" . $articleAmount . "<br/>" . "Amount of Words:" . $wordAmount . "<br/>" . "Topic:" . $topic . "<br/>" . "Additional Information:" . $info, "From:" . $email);
echo "Thank you for ordering!";
?>
html:
<form action="order.php">
<fieldset id="client" >
<legend>Client Information</legend>
<label for="clientName">Name:</label><input type="text" name="clientName" id="clientName" tabindex="1"/>
<label for="clientEmail">Email:</label><input type="email" name="clientEmail" id="clientEmail" tabindex="2"/>
</fieldset>
<fieldset id="order">
<legend>Order Information</legend>
<label for="articleNum">Number of Articles</label><input type="text" name="articleNum" id="articleNum" tabindex="3"/>
<label for="wordNum">Words per Article</label><input type="text" name="wordNum" id="wordNum" tabindex="4"/>
<label for="topic">Topics</label><input type="text" name="topic" id="topic" tabindex="5"/>
<label for="addInfo">Additional Info</label><input type="text" name="addInfo" id="addInfo" tabindex="6"/>
</fieldset>
<fieldset>
<button type="submit">Submit!</button>
</fieldset>
</form>
Use PHP mail or PHPMailer (works pretty well) ?
Using the PHPMailer library: https://github.com/PHPMailer/PHPMailer
define('PROJECT_ROOT', '/path/to/your/root/'); //Different for different webhosts or self hosted environments
require (PROJECT_ROOT . 'PHPMailer-master/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$to = $_POST['clientEmail']; //Email dervied from POST data.
$mail->Host = "mail.example.com"; //If you haven't got an SMTP server, use Gmail's free one.
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->Port = 25;
$mail->Username = "someEmail#example.com";
$mail->Password = "somePass";
$mail->From = 'someEmail#example.com';
$mail->FromName = 'My Website';
$mail->WordWrap = 50;
$mail->isHTML(true); // Or false
$mail->addReplyTo('support#example.com', 'Support');
$mail->Subject = 'Message subject here';
$mail->addAddress($to);
$mail->Body = ""; // Message body using HTML here. (Remove if $mail->isHTML(); is false)
$mail->AltBody = "
Client: " . $_POST['clientName'] . " //Again: derived from POST data.
Email: " . $to . " //We defined this variable before as clientEmail
Number of Articles: " . $_POST['articleNum'] . "
Words per Article: " . $_POST['wordNum'] . "
Topics: " . $_POST['topic'] . "
Additional Info: " . $_POST['addInfo'] . "
";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
} else {
echo "Mail sent!";
}
I noticed that your form is missing a method of sending this information that the users type in.
<form action="order.php">
It should be:
<form action="order.php" method="POST">
Hope that you get it working!
I'm trying to make a simple contact form for my website, so I bought one from Code Canyon. After not receiving slow and scarce help from the author, I'm asking you guys for help.
Basically it's a very simple contact form but I'm not too good with coding so it bothers me regardless. This is the HTML code;
<div id="contact" class="clearfix"><!-- contact -->
<h1><img name="logo" src="" width="300" height="50" alt="" style="background-color: #3366FF" /></h1><p class="txn">Lorem ipsum dim sum sum.</p>
<div id="message"></div>
<form method="post" action="contact.php" name="contactform" id="contactform">
<fieldset>
<legend>Please fill in the following form to contact us</legend>
<label for=name accesskey=U><span class="required">*</span> Your Name</label>
<input name="name" type="text" id="name" size="30" value="" />
<br />
<label for=email accesskey=E><span class="required">*</span> Email</label>
<input name="email" type="text" id="email" size="30" value="" />
<br />
<label for=phone accesskey=P><span class="required">*</span> Phone</label>
<input name="phone" type="text" id="phone" size="30" value="" />
<br />
<label for=subject accesskey=S>Subject</label>
<select name="subject" type="text" id="subject">
<option value="Support">Support</option>
<option value="a Sale">Sales</option>
<option value="a Bug fix">Report a bug</option>
</select>
<br />
<label for=comments accesskey=C><span class="required">*</span> Your comments</label>
<textarea name="comments" cols="40" rows="3" id="comments" style="width: 350px;"></textarea>
<p><span class="required">*</span> Are you human?</p>
<label for=verify accesskey=V> 3 + 1 =</label>
<input name="verify" type="text" id="verify" size="4" value="" style="width: 30px;" /><br /><br />
<input type="submit" class="submit" id="submit" value="Submit" />
</fieldset>
</form>
The JavaScript file I was given in the template...practically unchanged
jQuery(document).ready(function(){
$('#contactform').submit(function(){
var action = $(this).attr('action');
$("#message").slideUp(450,function() {
$('#message').hide();
$('#submit')
.after('<img src="assets/ajax-loader.gif" class="loader" />')
.attr('disabled','disabled');
$.post(action, {
name: $('#name').val(),
email: $('#email').val(),
phone: $('#telephone').val(),
subject: $('#enquiry').val(),
comments: $('#message').val(),
},
function(data){
document.getElementById('message').innerHTML = data;
$('#message').slideDown('fast');
$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
$('#contactform #submit').attr('disabled','');
if(data.match('success') != null) $('#contactform').slideUp('slow');
}
);
});
return false;
});
});
And then there is the contact-php file I got
<?php
if(!$_POST) exit;
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div class="error_message">Attention! Please enter a valid phone number.</div>';
exit();
} else if(!is_numeric($phone)) {
echo '<div class="error_message">Attention! Phone number can only contain digits.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
}
if(trim($subject) == '') {
echo '<div class="error_message">Attention! Please enter a subject.</div>';
exit();
} else if(trim($comments) == '') {
echo '<div class="error_message">Attention! Please enter your message.</div>';
exit();
} else if(trim($verify) == '') {
echo '<div class="error_message">Attention! Please enter the verification number.</div>';
exit();
} else if(trim($verify) != '4') {
echo '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
exit();
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
//$address = "example#themeforest.net";
$address = "mylerworks#gmail.com";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'You\'ve been contacted by ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name with regards to $subject, their additional message is as follows.\r\n\n";
$e_content = "\"$comments\"\r\n\n";
$e_reply = "You can contact $name via email, $email or via phone $phone";
$msg = $e_body . $e_content . $e_reply;
if(mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n")) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
}
function isEmail($email) { // Email address verification, do not edit.
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
?>
Problem is: let's say I fill up the form but forget to put my name in. The form will notify me I forgot it but I will not be able to post it, I will need to refresh the page. Also, it keeps giving me the "please enter a valid phone number" error even when I fill the form completely.
So how do I get it to work?
In case I didn't post something correctly here, check how the form looks here - You can view the form here
Your submit button is disabled after posting data . That is why you are not able to re-post it
$('#contactform #submit').attr('disabled','');
Use correct id of input field.
phone: $('#telephone').val(),
this will be always null as there is no component with this id
Its same kind of error. There is no element with id enquiry or message.
subject: $('#enquiry').val(),
comments: $('#message').val(),
Please be sure about name and id of your html components while retrieving values
Thanks
I have a client that needs a custom registration form.
I need to make a custom design on this page
I need to add custom fields like First Name, Company, Phone, etc.
Someone can help me with this?
A better place to ask WordPress questions is probably on WordPress Answers. Anyhoo, if you want to solve this without plugins, you need three things:
A custom WordPress theme
A Page Template
A WordPress Page that uses the Page Template
When you have these three parts in place, you can do the following in your Page Template:
<?php
/*
Template Name: Registration
*/
global $current_user;
wp_get_current_user();
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$company = $_POST['company'];
if (($firstname != '') && ($lastname != '') && ($company != '')) {
// TODO: Do more rigorous validation on the submitted data
// TODO: Generate a better login (or ask the user for it)
$login = $firstname . $lastname;
// TODO: Generate a better password (or ask the user for it)
$password = '123';
// TODO: Ask the user for an e-mail address
$email = 'test#example.com';
// Create the WordPress User object with the basic required information
$user_id = wp_create_user($login, $password, $email);
if (!$user_id || is_wp_error($user_id)) {
// TODO: Display an error message and don't proceed.
}
$userinfo = array(
'ID' => $user_id,
'first_name' => $firstname,
'last_name' => $lastname,
);
// Update the WordPress User object with first and last name.
wp_update_user($userinfo);
// Add the company as user metadata
update_usermeta($user_id, 'company', $company);
}
if (is_user_logged_in()) : ?>
<p>You're already logged in and have no need to create a user profile.</p>
<?php else : while (have_posts()) : the_post(); ?>
<div id="page-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="content">
<?php the_content() ?>
</div>
<form action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post">
<div class="firstname">
<label for="firstname">First name:</label>
<input name="firstname"
id="firstname"
value="<?php echo esc_attr($firstname) ?>">
</div>
<div class="lastname">
<label for="lastname">Last name:</label>
<input name="lastname"
id="lastname"
value="<?php echo esc_attr($lastname) ?>">
</div>
<div class="company">
<label for="company">Company:</label>
<input name="company"
id="company"
value="<?php echo esc_attr($company) ?>">
</div>
</form>
</div>
<?php endwhile; endif; ?>
Now, when you want to retrieve the stuff you've stored, you need to know whether the information is within the User object itself or in metadata. To retrieve the first and last name (of a logged-in user):
global $current_user;
$firstname = $current_user->first_name;
$lastname = $current_user->last_name;
To retrieve the company name (of a logged-in user):
global $current_user;
$company = get_usermeta($current_user->id, 'company');
That's the basic gist of it. There's still a lot of stuff missing here, like validation, error message output, the handling of errors occurring within the WordPress API, etc. There's also some important TODO's that you have to take care of before the code will even work. The code should probably also be split into several files, but I hope this is enough to get you started.
An advantage of using a custom registration form is that modifying the code according to the user's needs becomes easy. For a custom submit form you can make use of existing hooks in Wordpress like template_redirect and then map that hook to some function which will do the post-processing of the form, like validation and submitting data to the site's database. You can refer to an in-depth article here.
<div class="employee">
<input type="hidden" name="show_msg">
<form name="customer_details" method="POST" required="required" class="input-hidden">
Your Name: <input type="text" id="name" name="customer_name">
Your Email: <input type="text" id="email" name="customer_email">
Company: <input type="text" id="company" name="company">
Sex: <input type="radio" name="customer_sex" value="male">Male <input type="radio" name="customer_sex" value="female">Female
<textarea id="post" name="experience" placeholder="Write something.." style="height:400px;width:100%"></textarea>
<input type="submit" value="Submit">
<!--?php wp_nonce_field( 'wpshout-frontend-post','form-submit' ); ?-->
</form></div>
PHP function
function wpshout_frontend_post() {
wpshout_save_post_if_submitted();
}
add_action('template_redirect','wpshout_frontend_post', 2);
A custom WordPress registration form has two major advantages over the standard form.
The first is the integration with the overall look and feel of the website theme. Standard forms often don’t work well with custom themes and there is always a chance that the custom CSS files do not render well with the form. A custom form, on the other hand, can be easily set up to work with custom CSS.
The second and more popular reason of using a custom registration form is the option of custom fields that are not included on the standard form. A small custom registration form speeds up the process and collects all the necessary data from a neat interface.
function wordpress_custom_registration_form( $first_name, $last_name, $username, $password, $email) {
global $username, $password, $email, $first_name, $last_name;
echo '
<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
First Name :
<input type="text" name="fname" value="' . ( isset( $_POST['fname']) ? $first_name : null ) . '">
Last Name:
<input type="text" name="lname" value="' . ( isset( $_POST['lname']) ? $last_name : null ) . '">
Username <strong>*</strong>
<input type="text" name="username" value="' . ( isset( $_POST['username'] ) ? $username : null ) . '">
Password <strong>*</strong>
<input type="password" name="password" value="' . ( isset( $_POST['password'] ) ? $password : null ) . '">
Email: <strong>*</strong>
<input type="text" name="email" value="' . ( isset( $_POST['email']) ? $email : null ) . '">
<input type="submit" name="submit" value="Register"/>
</form>
';
}
This form can be inserted anywhere by using the shortcode [wp_registration_form]. Here is the code snippet for setting up the shortcode:
function wp_custom_shortcode_registration() {
ob_start();
wordpress_custom_registration_form_function();
return ob_get_clean();
}
I hope that by now you have a fair idea of creating a WordPress custom Registration form.Still any confusion kindly check Build Custom WordPress Registration Forms