Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

First question and first commercial plugin. Woohoo!

I'm trying to create a dashboard widget that leverages user input and a predefined URL structure to create an outbound link that sends the user to his/her desired destination. This is basically a hack created so that users on a blogging network can query another Wordpress site that holds all the content from the bloggers in that network. So if the user enters "pretty cats" and click on the search button, a link appears taking the user to the search page for the aggregating website i.e. http://wordpressag.com/?s=pretty+cats

So far I have the dashboard widget being created and displaying a text field and "search" button, but I'm stumped on the other functions I need to create a link based on the user input. The variable for the user input is $wpag_search, so the desired URL structure would be something akin to http://wordpressag.com?s=($wpag_search) , only with the user input instead of the variable.

Here's what I have, any suggestions?

// Function for displaying text input fields and search button 

function wpag_search_forms() {
    ?>
    <input id="search_terms" type="text" size="50" name="wpag_search" value="<?php echo esc_attr($wpag_search);?>" />
    <input id="search_button" type="button" value="Search WPAG" class="button-secondary"/>
    <?php
} 

//Other function for utilizing user input
//Has to follow http://wordpressag.com/?s=(user input) structure

// Create the function use in the action hook

function wpag_plugin_init () {
    wp_add_dashboard_widget('example_dashboard_widget', 'Search The WP Ag Network', 'wpag_search_forms');   
} 

// Hook into the 'wp_dashboard_setup' action to register our other functions

add_action('wp_dashboard_setup', 'wpag_plugin_init' );

?>
share|improve this question
    
Have you tried setting the action of the form to the site you want the form to be processed by? –  m0r7if3r Feb 20 '12 at 16:20
    
I hadn't, but by golly, that worked! And with only a few modifications to the original code. Thanks @m0r7if3r! –  Jared Sulzdorf Feb 20 '12 at 23:11
    
I'll submit it as an answer so you can accept it :D –  m0r7if3r Feb 21 '12 at 0:25
add comment

2 Answers

up vote 1 down vote accepted

If you set the action of the form to the page which you want to do the processing, it will redirect to that page as well as setting all the $_GET and $_POST variables up for easy access.

share|improve this answer
    
Demoed the code yesterday to my clients. Success! –  Jared Sulzdorf Feb 24 '12 at 14:45
add comment

You want add_query_arg.

For example,

$url = "http://wordpressag.com"; //base url
$wpag_search = urlencode('myinput'); //replace 'myinput' with user input.
$url = add_query_arg('s',$wpag_search,$url);
//$url is now http://wordpressag.com?s=myinput

Note: add_query_arg expects the input values to be encoded, see urlencode

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.