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.

I am Working on wordpress plugin. and i have a form like this

    $action_url = WP_PLUGIN_URL .'/demo-url-rewrite/include/test.php';


   <form action="<?php echo $action_url; ?>" method="get" name="f1">
    Name : <input type="text" name="name" id="name" value=""><br />
    <input type="submit" name="b1" value="Save">
   </form>

when user submit a form and action is performed i want this url :: http://mysite.com/Projects/demos/demo-url-rewrite/client/pranav-gandhi/

instead of this url ::

http://mysite.com/Projects/demos/demo-url-rewrite/wp-content/plugins/demo-url-rewrite/include/test.php?name=Pranav+Gandhi&b1=Save

so How can i overwrite url with worpress functionality.

thanx.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Do you actually need the URL? Such URLs are needed only if you want the search to be indexed. Example: Check this. (That 'a' in the url comes from the search form in this page and the homepage) The ideal way for parsing a form is to use the init action hook instead of setting the form action. If you still want the custom URL, let me know and I'll tell you a solution!

Edit: Assuming only the client name will change.

URLS:

add_filter('init', 'add_page_rewrite_rules');
function add_page_rewrite_rules()
{
    global $wp_rewrite, $wp;

    //this will hold the text field data
    $wp->add_query_var('client_name');

    //the actual rule
    add_rewrite_rule('^Projects/demos/demo-url-rewrite/client/(.*)?$','index.php?pagename=client-data&client_name=$matches[1]','top');
}

Now make a WP page with slug as client-data. This is required for the rule to work. Make a page template, assign it to this page. Make sure the following 2 lines are in the page template.

global $wp, $wp_query;
$name = get_query_var('client_name');

The $name var will have the client name you pass in the URL, use it to do the processing as you would using the form data. You can either use jQuery to handle the form submit and redirect to this custom URL or you can use the init action to check the form submit and use a hard redirect to this URL. Using PHP the redirect URL should be

echo home_url('/Projects/demos/demo-url-rewrite/client/'.$_POST['name']);

Let me know how it goes!

share|improve this answer
    
Thanx but i want custom url like i had given. –  Gandhi Pranav Jun 18 '12 at 11:04
    
Kewl! Updating the answer... –  Rutwick Gangurde Jun 18 '12 at 11:04
    
What is the exact URL that you want? –  Rutwick Gangurde Jun 18 '12 at 11:06
    
    
From this URL, which all parts are gonna stay constant, and which will change? I guess only the client name will change –  Rutwick Gangurde Jun 18 '12 at 11:09

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.