would someone be so kind to translate this php to perl code? the json bitchery is not needed.
this is what i have tried, but this goes nowhere...
Code: Select all
<?php
// process.php
$errors = array(); // array to hold validation errors
$data = array(); // array to pass back data
// validate the variables ======================================================
// if any of these variables don't exist, add an error to our $errors array
if (empty($_POST['name']))
$errors['name'] = 'Name is required.';
if (empty($_POST['email']))
$errors['email'] = 'Email is required.';
if (empty($_POST['superheroAlias']))
$errors['superheroAlias'] = 'Superhero alias is required.';
// return a response ===========================================================
// if there are any errors in our errors array, return a success boolean of false
if ( ! empty($errors)) {
// if there are items in our errors array, return those errors
$data['success'] = false;
$data['errors'] = $errors;
} else {
// if there are no errors process our form, then return a message
// DO ALL YOUR FORM PROCESSING HERE
// THIS CAN BE WHATEVER YOU WANT TO DO (LOGIN, SAVE, UPDATE, WHATEVER)
// show a message of success and provide a true success variable
$data['success'] = true;
$data['message'] = 'Success!';
}
// return all our data to an AJAX call
echo json_encode($data);
this is what i have tried, but this goes nowhere...
Code: Select all
#!/usr/bin/perl
use strict;
#use warnings;
use JSON;
use CGI;
my $cgi = CGI->new;
print $cgi->header('application/json;charset=UTF-8');
my @errors;
my @data;
my $lparnmame = $cgi->param('lparname');
my $from = $cgi->param('from');
my $to = $cgi->param('to');
my $email = $cgi->param('email');
if ( my $lparname eq "" ) { push(@errors, 'Lparname is required') };
if ( my $from eq "" ) { push(@errors, 'From is required') };
if ( my $to eq "" ) { push(@errors, 'To is required') };
if ( my $email eq "" ) { push(@errors, 'Email is required') };
if (!@errors) {
push(@data, @errors);
}
else {
push(@data, 'Success');
};
no plan