Skip to content

Instantly share code, notes, and snippets.

@coquer
Last active August 29, 2015 14:22
Show Gist options
  • Save coquer/33e4108f255d89435f6d to your computer and use it in GitHub Desktop.
Save coquer/33e4108f255d89435f6d to your computer and use it in GitHub Desktop.
simple form wordpress
function createShortCut() {
ob_start();
generateFormHTMLCode();
doTheThing();
return ob_get_clean();
}
function generateFormHTMLCode(){
?>
<div class="front-get-one-form">
<form action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" method="post" role="form" autocomplete="off">
<div class="form-inline">
<div class="form-group full-width">
<label for="one-form-domain" class="sr-only"><?php _e( 'Domain name', 'html5blank' ); ?></label>
<input id="one-form-domain" class="form-control input-lg" type="text" name="domain" value="" placeholder="domain"/>
<input class="btn btn-default btn-lg btn-xs-center" type="submit" name="get-one" value="<?php _e( 'Get .one', 'html5blank' ); ?>" />
</div>
</div>
</form>
</div>
<?php
}
add_shortcode('magic_form', 'createShortCut');
function doTheThing(){
if(isset($_POST['get-one'])){
$domain_to_look_for = sanitize_text_field($_POST['domain']);
loopAddress($domain_to_look_for);
}
}
function loopAddress($url){
if(empty($url)){
return false; // you candle error request, either here of in the function calling it
}
try {
$process = curl_init();
curl_setopt($process, CURLOPT_URL, "URL HERE".$url);
curl_setopt($process, CURLOPT_USERPWD, "USER:PASS");
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, FALSE);
curl_setopt($process, CURLOPT_POSTFIELDS, $url);
$return = curl_exec($process);
print_r(curl_getinfo($process));
}catch (Exception $e){
echo "Error {$e}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment