Simple Perl and CGI::Ajax form validation - ajax

I'm trying to do a real simple setup.
1.Do checks on each field using CGI::Ajax.
2.Validate that all fields have been filled in with simple perl CGI
The thing is, when testing individually, both work, but when combined as seen in the code below I have two issues:
1.In the username and password fields I see CGI=HASH(0x228ed48) etc
2. When I push the submit button and there is an error (a field is empty), it prints an internal server error, I believe this is due to $ajx->build_html( $cgi, \&form($error, $username, $password)); and calling the form function in this manner.
Any ideas?
Thanks in advance.
#!/usr/bin/perl -w
use CGI;
use CGI::Session qw/ -ip-match/;
use CGI::Ajax;
$cgi = new CGI;
#$session = new CGI::Session(undef, $cgi, {Directory=> '/tmp'});
my $ajx = new CGI::Ajax( 'checkuser' => \&checkuser );
#print $ajx->build_html( $cgi, \&form);
if($cgi->param("submit")) {
process(); } else { print $ajx->build_html( $cgi, \&form); }
sub checkuser
{
my $input = shift;
my $out = $input . " is not taken";
return $out;
}
sub form {
my $error = shift;
my $username = shift;
my $password = shift;
my $html = <<HTML;
<html>
<BODY>
<form id='log' action='session.cgi' method='post' accept-charset='UTF-8'>
<input type="hidden" name="submit" value="Submit">
<fieldset>
<legend>Login</legend>
<font color="red">$error</font>
<label for='username' >UserName*:</label>
<input type='text' name='user' id='user' value="$username"
maxlength="50" onchange="checkuser( ['user'], ['resultdiv'] );">
<br><br>
<div id="resultdiv"></div>
<label for='password' >Password*:</label>
<input type='password' name='pd' id='pd' value="$password" maxlength="50" />
<input type='submit' name='Submit' value='Submit' />
</fieldset>
</form>
</body></html>
HTML
return $html;
}
sub process
{
if(validate_form()) {
print $cgi->header;
print <<HTML;
<body>Validated<br></body>
HTML
}
}
sub validate_form
{
my $username = $cgi->param("user");
my $password = $cgi->param("pd");
my $error = "";
$error .= "Please enter your username<br/>" if ( !$username );
$error .= "Please specify your password<br/>" if ( !$password );
if ( $error )
{
$ajx->build_html( $cgi, \&form($error, $username, $password));
return 0;
}
else
{
return 1;
}
}

For development, use CGI::Carp qw/fatalsToBrowser/;. This will allow you to see the actual errors your code is producing, rather than "Internal Server Error".
Update: Also, your code is failing because you are misunderstanding how a callback function works. The callback function is not called by you; it is called by the code you pass it to--in this case the module. So you can't provide parameters, the module does. This won't work:
$ajx->build_html( $cgi, \&form($error, $username, $password));
build_html wants to call the function you pass in internally, with its own parameters.
Here you are not allowing to happen. Instead you are calling form() before you call build_html(), then passing in a scalar reference to the result. This fails later, because build_html tries to use that scalar reference as a subroutine reference.
Solution: you just need to use \&form. You will need another way to fill in the fields.
Also:
Form validation is a very common task. Mature Perl modules are available and are widely used for this (for example, HTML::FormFu and Data::Formvalidator). There are also some related modules that appear to add Javascript validation (HTML::FormFu::ExtJS, JavaScript::DataFormValidator). It is probably worth checking these out before you create your own.
Most modern Perl web development is done using a web framework of some sort. The available frameworks are very powerful and worth using for all but the simplest projects. If your goal is to learn, I recommend starting with a framework as early as possible, because development using a framework is quite different from traditional CGI development, and there is a learning curve. I am quite happy with Catalyst, and there are other options as well, such as Mojolicious and Dancer.

Related

Send single email according to Weblesson

I'm new to programming, currently searching for ways to only send a single email like what Web lesson had taught me (bulk email I don't want), here is the link:'How to Send Bulk Email in PHP using PHPMailer with Ajax JQuery'.
I have two places to run this function, one is index.blade.php, and one is ClientController.
index.blade.php
<form action="{{ route('clients.destroy',$client->id) }}" method="POST">
<a href="{{ route('clients.edit',$client->id) }}">
<i class="fas fa-pencil-alt"></i>
</a>
<button type="button" name="email_button" class="email_button"
id="{{ $client->_id }}"
method="post" action="single" email_data="{{ $client->email }}">
<i class="fas fa-envelope"></i>
</button>
#csrf
#method('DELETE')
<button type="submit"><i class="far fa-trash-alt"></i></button>
</form>
here's my JQuery and Ajax at the bottom of index.blade.php
<script>
$(document).ready(function(){
$('.email_button').click(function(){
$(this).attr('disabled', 'disabled');
var id = $(this).attr("id");
var action = $(this).data("action");
var email_data = $(this).data("email_data");
$.ajax({
url:'{{ route('send-email-test') }}',
method:'POST',
data:{email_button: email_data, _token: '{{csrf_token()}}'},
beforeSend:function(){
$('#'+id).html('Sending...');
$('#'+id).addClass('uk-text-danger');
},
success:function(data){
if(data = 'ok')
{
$('#'+id).text('Success');
$('#'+id).removeClass('uk-text-danger');
$('#'+id).removeClass('uk-text-info');
$('#'+id).addClass('uk-text-success');
}
else
{
$('#'+id).text(data);
}
$('#'+id).attr('disabled', false);
}
});
});
});
</script>
Here's my route and script
// Here's my script in layout
<script src="{{ asset('js/jquery.min.js') }}" type="text/javascript"></script>
// Here's my route
Route::post('send-email-test','ClientController#send_mail')->name('send-email-test');
After creating the index, I'm trying to use ajax to route to my controller.
ClientController
namespace App\Http\Controllers;
use App\Models\Company\Client\Client;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
class ClientController extends Controller
{
public function send_mail()
{
if(isset($_POST["email_data"]))
{
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
require 'class/class.phpmailer.php';
$output = '';
foreach($_POST['email_data'] as $row)
{
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = '587'; //Initially is 465, doesn't work
$mail->SMTPAuth = true;
$mail->Username = 'xxxxxxx#gmail.com';
$mail->Password = 'xxxxxxx';
$mail->SMTPSecure = 'tls'; //Initially is SSL, doesn't work either
$mail->From = 'xxxxxxxx#gmail.com';
$mail->FromName = 'Coverage Giant';
$mail->addAddress($row["email_data"]);
$mail->To($row["email_data"]);
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = 'Welcome To Coverage Giant';
$mail->Body = '
<p>Sed at odio sapien. Vivamus efficitur</p>
';
$mail->AltBody = '';
$client_email = $mail->Send();
if($$client_email["code"] == '400')
{
$output .= html_entity_decode($client_email['full_error']);
}
}
if($output == '')
{
echo 'ok';
}
else
{
echo $output;
}
}
}
}
As you can see, I'm doing something opposite from the Web lesson because Webslesson uses index.php and send_mail.php, I'm using index.blade.php and ClientController. Since after applying what Websleeson has shown to me, it doesn't function well, so I reverse the engine a bit, thinking maybe it might work the other way round.
My problem now is, my JQuery and Ajax are functioning correctly, and it's able to route to ClientController from index.blade.php. Still, after routing to the controller, it seems that I can't send a single email using PHPMailer; maybe something is wrong with my controller and PHPMailer?
I was also wondering, is there a better way to send a single email?
BTW, I'm using MongoDB and Laravel. My UI is Uikit instead of Boostrap.
Since you're using Laravel, it is indeed easier to use Laravel's built-in mail classes, but you've got this far with PHPMailer so I'll help you clean this up...
You're loading two different copies of PHPMailer at the same time. This is very likely to cause major problems! class.phpmailer.php is from a very old version that you should not be using. It also looks like you have based your code on a very old PHPMailer example – use the latest ones from the repo.
If you're using composer properly (which you should be given you've set up a Laravel project), you should not need any of those require lines - the autoloader will load the classes for you if you added phpmailer/phpmailer to your composer.json requires, as described in the readme.
Port should be an integer, not a string:
$mail->Port = 465;
There is no To() method; call addAddress to add recipients.
When sending multiple messages in a loop, create the instance outside the loop, and re-use it for each message, remembering to call $mail->clearAddresses(); at the end of each iteration, as shown in the mailing list example.
This is peculiar code, and wrong because send() returns a boolean, not an array:
if($$client_email["code"] == '400')
and it doesn't provide code or full_error properties. You're looking for ErrorInfo, as shown in all the examples.
Overall, always refer to the original docs and examples when using any open source package – making up random stuff and expecting it to work is not going to serve you well.

controller method is not working and page is refreshing instead of redirecting to given path in laravel

I am not getting any error, it's just refreshing on that page. The controller method is not called where I have given the path for redirection.
My code is:
blade-file
<form action="{{route('validate-promocode')}}" method="post">
#csrf
<input class="promo-input" id="code" type="text" onkeyup="this.value = this.value.toUpperCase();" name="code" placeholder="EG. APPLY HERE"><br>
<input type="hidden" name="_token" value="{!!csrf_token()!!}">
<button id="save" type="submit" class="apply-promo">Apply Promo Code</button>
</form>
Route file
Route::post('/validade-code', 'PromoController#validateCode')->name('validate-promocode');
Controller file
public function validateCode(Request $request){
if (Gate::allows('isUser')) {
$ip = $request->input('code');
dd($promo);
$promo = Promo::where('code','=', trim($ip))->first();
if(!empty($promo)){
$dataamountMonthly = 40000 - (($promo->discount_percentage * 40000) / 100);
$dataamountYearly = 300000 - (($promo->discount_percentage * 300000) / 100);
if($dataamountMonthly == 0 || $dataamountYearly == 0){
return view('paymet.subscription-success');
}
$data = array(
'dataamountMonthly' => $dataamountMonthly ,
'dataamountYearly' => $dataamountYearly,
'code' => $ip
);
return view('payment.startPromoCode',$data);
}else{
$data = array(
'error' => 'Something went wrong, please try again'
);
return redirect()->back()->with($data);
}
}
}
I don't know what I am missing , any help will be appriciated.
Solved
Sometimes you may wish to redirect the user to their previous location, such as when a submitted form is invalid. You may do so by using the global back helper function. Since this feature utilizes the session, make sure the route calling the back function is using the web middleware group or has all of the session middleware applied
I think according to your code
$promo = Promo::where('code','=', trim($ip))->first();
the value of $promo can be null/ empty
and instead of executing your expected code it is redirecting back the page, and it seems the refresh for you. rest your code is correct.

Having issues submitting form via AJAX on WordPress with reCAPTCHA

I've spent a good few hours trying to Google my way out of this, and I keep coming up with one issue or another. I'm getting myself wrapped up in knots and I am hoping that someone can help me by giving me a metaphorical slap around the face and showing me how the hell to do this properly.
Ok ... so I have a page on my front end that is inserted by a shortcode. This form is essentially a sort of AMA (Ask Me Anything) form, which I am using to create posts in my Admin area. Visitors enter their question, name and email, and submit the form to me via AJAX. The submissions are saved into the WordPress database under an ama custom post type, and an email is sent to me via wp_mail because I have an SMTP plugin installed that routes all requests for wp_mail through there. I have CMB2 installed on my website, and have keys for reCAPTCHA saved there.
So far, so good.
I had a working form with CMB2 fields, but CMB2 doesn't seem to support reCAPTCHA (otherwise it worked fine). So I decided to start from scratch and write my own form since it was just three fields that I wanted to submit. What could possibly go wrong, right?
Here's my Franken-code.
<?php
function ccdClient_shortcode_amaForm( $atts ) {
// Parse attributes
$atts = ( shortcode_atts( array(
'id' => uniqid('ccdClient_amaForm_'),
), $atts, 'ama_form' ) );
$rcKey = cmb2_get_option( 'ccdtheme_settings_apikeys', '_ccdclient_themesettings_apikeys_captcha_sitekey' );
$form = '
<form id="' . $atts['id'] . '" name="' . $atts['id'] . '" method="post" action="">
<div class="amaError"></div>
<div class="amaForm-field-question amaForm-field">
<p><label for="question">Your Question</label></p>
<p><textarea id="question" name="question" tabindex="1"></textarea></p>
</div>
<div class="amaForm-fieldGroup amaForm-groupTwo">
<div class="amaForm-field-name amaForm-field">
<p><label for="name">Your Name</label></p>
<p><input type="text" id="name" name="name" tabindex="2" /></p>
</div>
<div class="amaForm-field-email amaForm-field">
<p><label for="email">Your Email</label></p>
<p><input type="email" id="email" name="email" tabindex="3" /></p>
</div>
</div>
<div class="amaForm-fieldGroup amaForm-groupTwo">
<div class="amaForm-field-recaptcha amaForm-field amaForm-recaptcha">
<div class="g-recaptcha" data-sitekey="' . $rcKey . '"></div>
</div>
<div class="amaForm-field-submit amaForm-field amaForm-submit">
<input type="submit" value="Publish" id="submit" name="submit" />
</div>
</div>
</form>
<script>
$(document).ready(function() {
// Get form
var amaForm = $("#' . $atts['id'] . '");
// Get messages div
var amaError = $("#' . $atts['id'] . ' .amaError");
// Set data
var amaData = { "action" : "ama_form_process"}
var options = {
url: "'. admin_url( 'admin-ajax.php' ) .'",
type: "post",
dataType: "json",
data: amaData,
success : function(responseText, statusText, xhr, $form) {
$(amaError).html("Your form has been submitted successfully");
},
};
//Set submit function
amaForm.on("submit", function(e) {
//Prevent default form behavior
e.preventDefault();
// Serialise form data
//Post via AJAX
$.ajax(options)
.done(function(response) {
// Make sure that the amaError div has the "success" class.
$(amaError).removeClass("error");
$(amaError).addClass("success");
// Set the message text.
$(amaError).text(response);
})
.fail(function(data) {
// Make sure that the amaError div has the "error" class.
$(amaError).removeClass("success");
$(amaError).addClass("error");
// Set the message text.
if (data.responseText !== "") {
$(amaError).text(data.responseText);
} else {
$(amaError).text("Oops! An error occured, and your message could not be sent.");
}
});
});
});
</script>';
return $form;
}
add_shortcode('ama_form', 'ccdClient_shortcode_amaForm');
function ama_form_process() {
// If the form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Include WordPress files
include_once '../../../../../wp-includes/wp-load.php';
// Set reCaptcha private key
$recaptchaKey = cmb2_get_option( 'ccdtheme_settings_apikeys', '_ccdclient_themesettings_apikeys_captcha_secretkey' );
// If the Google Recaptcha box was clicked
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){
$captcha = $_POST['g-recaptcha-response'];
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptchaKey . "&response=" . $captcha);
$obj = json_decode($response);
// If the Google Recaptcha check was successful
if($obj->success == true) {
$question = strip_tags( trim( $_POST['question'] ) );
$name = strip_tags( trim( $_POST["name"] ) );
$name = str_replace( array("\r","\n"), array(" "," "), $name);
$email = filter_var( trim( $_POST["email"] ), FILTER_SANITIZE_EMAIL );
if ( !$name || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Oops! There was a problem with your submission. Please complete the form and try again.";
exit;
}
// Add the content of the form to $post as an array
$post = array(
'post_title' => $question,
'post_status' => 'pending', // Could be: publish
'post_type' => 'ama', // Could be: `page` or your CPT
'meta_input' => array(
'_ccdclient_ama_name' => $name,
'_ccdclient_ama_email' => $email,
),
);
wp_insert_post($post);
echo 'Saved your post successfully! :)';
$recipient = get_option('admin_email');
$subject = "New question from $name";
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Message:\n$question\n";
$email_headers = "From: $name <$email>";
wp_mail( $recipient, $subject, $email_content, $email_headers );
}
// If the Google Recaptcha check was not successful
else {
echo "Robot verification failed. Please try again. Success:" . $response;
}
}
// If the Google Recaptcha box was not clicked
else {
echo "Please click the reCAPTCHA box.";
}
}
// If the form was not submitted
// Not a POST request, set a 403 (forbidden) response code.
else {
echo "There was a problem with your submission, please try again.";
}
}
add_action("wp_ajax_ama_form_process", "ama_form_process");
//use this version for if you want the callback to work for users who are not logged in
add_action("wp_ajax_nopriv_ama_form_process", "ama_form_process");
As you can guess, I have looked at about a dozen or so pages and combined the efforts of each of them, thus overwriting parts that would perhaps have worked and confused myself no end, and so am resorting to here to preserve what is left of my sanity.
EDIT: Apologies. Whilst I copied the code, I wasn't specific on what issues I was facing. Goes to show the extent I was frustrated.
I have had a number of issues with this code. Currently, when I submit the form, it keeps the same URL but returns a 404 error page. However, it has previously told me that it cannot recognise functions - and therefore couldn't run - such as cmb2_get_option (which is a modification of get_option that specifically works with CMB2 options pages) and wp_insert_post. The latter error (ie: wp_insert_post) came up when the secret key was hard-coded into the script and not called from the get_option function.

Laravel 4: Form::macro with Form::model

Is it possible to use a custom Form::macro() with the Form::model() feature?
When I tried it at first glance, I could not get the model data to be passed to the macro method.
Only Form functions like Form::text will look for the form model automatically. Inside your macro, you could do this a couple of ways. Easiest would be to use Form::getValueAttribute($name). For example:
Form::macro('myField', function() {
$value = Form::getValueAttribute('username');
return "<input type='text' name='username' value=$value >";
});
And then you'd use it in the blade template like this:
<?php
$user = new User;
$user->username = "bob";
echo Form::model($user);
echo Form::myField();
echo Form::close();
?>
You can find all of the available form functions in the source code here: https://github.com/laravel/framework/blob/master/src/Illuminate/Html/FormBuilder.php

strict with CGI::AJAX

I have set of code for updating a password in the table, here I'm using CGI::AJAX module to update the password and get the popup screen on corresponding execution.When using that code with my application it is executing properly but I didn't get the output(means Perl subroutine is not called when JavaScript function to get use.password is not updated into table). I don't get any error either.
#!/usr/bin/perl -w
use strict;
use CGI;
use DBI;
use Data::Dumper;
my $p = new CGI qw(header start_html end_html h1 script link);
use Class::Accessor;
use CGI::Ajax;
my $create_newuser;
my $ajax = new CGI::Ajax('fetch_javaScript' => $create_newuser);
print $ajax->build_html($p,\&Show_html,{-charset=>'UTF-8', -expires=>'-1d'});
sub Show_html
{
my $html = <<EOHTML;
<html>
<body bgcolor="#D2B9D3">
<IMG src="karvy.jpg" ALT="image">
<form name='myForm'>
<center><table><tr><td>
<div style="width:400px;height:250px;border:3px solid black;">
<center><h4>Create New Password's</h4>
<p>&nbsp User Name</b>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<INPUT TYPE="text" NAME="user" id = "user" size = "15" maxlength = "15" tabindex = "1"/></p>
<p>&nbsp Password:</b>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<INPUT TYPE=PASSWORD NAME="newpassword" id = "newpassword" size = "15" maxlength = "15" tabindex = "1"/></p>
<p>&nbsp Re-Password:</b>&nbsp&nbsp&nbsp<INPUT TYPE=PASSWORD NAME="repassword" id = "repassword" size = "15" maxlength = "15" tabindex = "1"/></p>
<input type="submit" id="val" value="Submit" align="middle" method="GET" onclick="fetch_javaScript(['user','newpassword','repassword']);"/><INPUT TYPE="reset" name = "Reset" value = "Reset"/>
<p>Main Menu <A HREF = login.pl>click here</A>
</center>
</div>
</td></tr></table></center>
</form>
</body>
</html>
EOHTML
return $html;
}
$create_newuser =sub
{
my #input = $p->params('args');
my $user=$input[0];
my $password=$input[1];
my $repassword=$input[2];
my $DSN = q/dbi:ODBC:SQLSERVER/;
my $uid = q/123/;
my $pwd = q/123/;
my $DRIVER = "Freetds";
my $dbh = DBI->connect($DSN,$uid,$pwd) or die "Coudn't Connect SQL";
if ($user ne '')
{
if($password eq $repassword)
{
my $sth=$dbh->do("insert into rpt_account_information (user_id,username,password,user_status,is_admin) values(2,'".$user."','".$password."',1,1)");
my $value=$sth;
print $value,"\n";
if($value == 1)
{
print 'Your pass has benn changed.Return to the main page';
}
}
else
{
print "<script>alert('Password and Re-Password does not match')</script>";
}
}
else
{
print "<script>alert('Please Enter the User Name')</script>";
}
}
my $create_newuser;
my $ajax = new CGI::Ajax('fetch_javaScript' => $create_newuser);
...;
$create_newuser =sub { ... };
At the moment when you create a new CGI::Ajax object, the $create_newuser variable is still undef. Only much later do you assign a coderef to it.
You can either assign the $create_newuser before you create the CGI::Ajax:
my $create_newuser =sub { ... };
my $ajax = new CGI::Ajax('fetch_javaScript' => $create_newuser);
...;
Or you use a normal, named subroutine and pass a coderef.
my $ajax = new CGI::Ajax('fetch_javaScript' => \&create_newuser);
...;
sub create_newuser { ... }
Aside from this main error, your script has many more problems.
You should use strict instead of the -w option.
For debugging purposes only, use CGI::Carp 'fatalsToBrowser' and sometimes even with warningsToBrowser can be extremely helpful. Otherwise, keeping a close eye on the error logs is a must.
my $p = new CGI qw(header start_html end_html h1 script link) doesn't make any sense. my $p = CGI->new should be sufficient.
use Class::Accessor seems a bit random here.
The HTML in Show_html is careless. First, your heredocs allows variable interpolation and escape codes – it has the semantics of a double quoted string. Most of the time, you don't want that. Start a heredoc like <<'END_OF_HTML' to avoid interpolation etc.
Secondly, look at that tag soup you are producing! Here are some snippets that astonish me:
bgcolor="#D2B9D3", align="middle" – because CSS hasn't been invented yet.
<center> – because CSS hasn't been invented yet, and this element isn't deprecated at all.
<table><tr><td><div ... </div></td></tr></table> – because there is nothing wrong with a table containing a single cell. (For what? This isn't even for layout reasons!) This table cell contains a single div …
… which contains another center. Seriously, what is so great about unneccessary DOM elements that CSS isn't even an option.
style="width:400px;height:250px;border:3px solid black;" – because responsive design hasn't been invented yet.
<p> ... </b> – Oh, what delicious tag soup!
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp – this isn't a typewriter, you know. Use CSS and proper markup for your layout. There is a difference between text containing whitespace, and empty areas in your layout.
tabindex = "1" … tabindex = "1" … tabindex = "1" – I don't think you know what tabindex does.
<A HREF = login.pl> – LOWERCASING OR QUOTING YOUR ATTRIBUTES IS FOR THE WEAK!!1
onclick="fetch_javaScript(['user','newpassword','repassword']);" – have you read the CGI::Ajax docs? This is not how it works: You need to define another argument with the ID of the element where the answer HTML is displayed.
In your create_newuser, you have an SQL injection vulnerability. Use placeholders to solve that. Instead of $sth->do("INSERT INTO ... VALUES('$foo')") use $sth->do('INSERT INTO ... VALUES(?)', $foo).
print ... – your Ajax handler shouldn't print output, instead it should return a HTML string, which then gets hooked into the DOM at the place your JS function specified. You want something like
use HTML::Entities;
sub create_newuser {
my ($user, $password, $repassword) = $p->params('args');
my ($e_user, $e_password) = map { encode_entities($_) } $user, $password;
# DON'T DO THIS, it is a joke
return "Hello <em>$e_user</em>, your password <code>$e_password</code> has been successfully transmitted in cleartext!";
}
and in your JS:
fetch_javaScript(['user','newpassword','repassword'], ['answer-element'], 'GET');
where your HTML document somewhere has a <div id="answer-element" />.

Resources