web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Add custom fields to r...
Power Pages
Unanswered

Add custom fields to registration site (JavaScript Code)

(0) ShareShare
ReportReport
Posted on by 67

Dear community,

I am having a hard time getting work on a custom code that will add two fields First Name and Last Name to the registration website, below is the code that I had written so far to see if you have any input on it:

 

Content snippet HTML (Account/Register/PageCopy)

 

<script>
 $(document).ready(function() { 
 // Code to add custom First Name and Last Name Fields 
 $('#ContentContainer_MainContent_MainContent_ShowEmail').before('<div class="form-group"><label class="col-sm-4 control-label required" for="FirstNameTextBox"><span id="ContentContainer_MainContent_MainContent_FirstNameLabel"><span class="xrm-editable-text xrm-attribute"><span class="xrm-attribute-value">First Name</span></span></span></label><div class="col-sm-8"><input name="ctl00$ctl00$ContentContainer$MainContent$MainContent$FirstNameTextBox” type="text autocomplete="off" id="FirstNameTextBox" class="form-control" aria-required="true"></div></div><div class="form-group"><label class="col-sm-4 control-label required" for="LastNameTextBox"><span id="ContentContainer_MainContent_MainContent_LastNameLabel"><span class="xrm-editable-text xrm-attribute"><span class="xrm-attribute-value">Last Name</span></span></span></label><div class="col-sm-8"><input name="ctl00$ctl00$ContentContainer$MainContent$MainContent$LastNameTextBox” type="text autocomplete="off" id="LastNameTextBox" class="form-control" aria-required="true"></div></div>');

 //Code to Add Custom 'Register' Button
 $('#SubmitButton').after('<input type="submit" name="ctl00$ctl00$ContentContainer$MainContent$MainContent$mySubmitButton" value="Register" id="mySubmitButton" class="btn btn-primary">'); 
 
 //Hide the original 
 $('#SubmitButton').hide();
 
 $("#mySubmitButton").click(function()
 {
 localStorage.setItem(“firstname”, $(“#FirstNameTextBox”).val());
 localStorage.setItem(“lastname”, $(“#LastNameTextBox”).val());
 
 //trigger standard submit click
 $('#SubmitButton').click(); 
 return false;
 });
 });
 </script>

 

 

I noted that if I delete these two lines below, the fields show in the website otherwise hide, so I presume is an issue with these two lines.

 

localStorage.setItem(“firstname”, $(“#FirstNameTextBox”).val());

localStorage.setItem(“lastname”, $(“#LastNameTextBox”).val());

 

Also, I am planning to use this code for the JS code in the user profile web page:

 

$(document).ready(function() { 
 // get values of First name and last name from local storage and set it in profile form fields.

 var firstname= localStorage.setItem("firstname1"); 
 var lastname= localStorage.setItem("lastname1");

 if(firstname != undefined && firstname != null && firstname != “”)
 {
 $(“#firstname”).val(firstname);
 }
 if(lastname != undefined && lastname != null && lastname != “”)
 {
 $(“#lastname”).val(lastname);
 }

localStorage.clear(); 

});

 

 

Thank you in advance,

 

Jose G Diaz

Categories:
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard