Wordpress shortcode api registertion form

=== hestiacp-register ===
i was bored so i made this use it as you want

you need to edit the server address and login details.

and activate plugin
downloadzip

add [sitepoint_register_form] shortcode and the form will appear

<?php
/*
Plugin Name: Hestiacp Wordpress Registration
was board with some time made this
Description: Simple Registartion Form
Version: 1.0
Author: Spacestangs
Author URI: http://palm-tree.finance
*/

function html_form_code() {
	echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
	
	echo '<p>';
	echo 'Registration form';
	echo '</p>';
	
	echo '<p>';
	echo 'Your username Name (required) <br/>';
	echo '<input type="text" name="cf-username" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["cf-username"] ) ? esc_attr( $_POST["cf-username"] ) : '' ) . '" size="40" />';
	echo '</p>';
	
	echo '<p>';
	echo 'Your Name (required) <br/>';
	echo '<input type="text" name="cf-name" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["cf-name"] ) ? esc_attr( $_POST["cf-name"] ) : '' ) . '" size="40" />';
	echo '</p>';

	echo '<p>';
	echo 'Your last Name (required) <br/>';
	echo '<input type="text" name="cf-lastname" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["cf-lastname"] ) ? esc_attr( $_POST["cf-lastname"] ) : '' ) . '" size="40" />';
	echo '</p>';
	
	echo '<p>';
	echo 'Your Email (required) <br/>';
	echo '<input type="email" name="cf-email" value="' . ( isset( $_POST["cf-email"] ) ? esc_attr( $_POST["cf-email"] ) : '' ) . '" size="40" />';
	echo '</p>';
	echo '<p>';

	echo '<p>Passwords must match!</p>';
	echo '<p>';
	echo 'Password (required) <br/>';
	echo '<input type="password" name="cf-password" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["cf-password"] ) ? esc_attr( $_POST["cf-password"] ) : '' ) . '" size="40" />';
	echo '</p>';
	
	echo '<p>';
	echo 'Confirm Password (required) <br/>';
	echo '<input type="password" name="cf-password" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["cf-password"] ) ? esc_attr( $_POST["cf-password"] ) : '' ) . '" size="40" />';
	echo '</p>';
	

	echo '<p><input type="submit" name="cf-submitted" value="Register"></p>';
	do_action( 'anr_captcha_form_field' );
	echo '</form>';
}

function register_now() {

	// if the submit button is clicked, send the email
	if ( isset( $_POST['cf-submitted'] ) ) {

		// sanitize form values
		$hst_hostname = 'SERVERADRESS';
		$hst_port = '8083';
		$hst_username = 'admin';
		$hst_password = 'PASSWORD';
		$hst_returncode = 'yes';
		$hst_command = 'v-add-user';
		
		
		$username = sanitize_text_field( $_POST["cf-username"] );
		$password = sanitize_text_field( $_POST["cf-password"] );
		$email = sanitize_email( $_POST["cf-email"] );
		$package = 'Free4life';
		$first_name = sanitize_text_field( $_POST["cf-name"] );
		$last_name = sanitize_text_field( $_POST["cf-lastname"] );
		

		$postvars = array(
    		'user' => $hst_username,
    		'password' => $hst_password,
    		'returncode' => $hst_returncode,
    		'cmd' => $hst_command,
    		'arg1' => $username,
    		'arg2' => $password,
    		'arg3' => $email,
    		'arg4' => $package,
    		'arg5' => $first_name,
    		'arg6' => $last_name
    		);

		$postdata = http_build_query($postvars);
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/');
		curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($curl, CURLOPT_POST, true);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
		$answer = curl_exec($curl);

    	// Check result
		if($answer == 0) {
    echo "User account has been successfuly created\n";
		
} elseif($answer == 4)  {
    echo "Allready registered ";
}
		} else {
  			  echo "Query returned error code: " .$answer. "\n";
		}
	}
	

function rf_shortcode() {
	ob_start();
	register_now();
	html_form_code();

	return ob_get_clean();
}
add_shortcode( 'sitepoint_register_form', 'rf_shortcode' );

?>
1 Like

Nice work!