0

I have a widget that I'm making that builds a multi-step form which retrieves xml data from a third party plugin (http://xmlplugin.com/geoquote.php). While this plugin is available for use already it isn't wordpress friendly at all.

In widget.php I have the php that displays the form like this:

<form method="POST" action="<?php echo plugins_url( 'step2.php' , __FILE__ ) ?>" name="Calculate" onsubmit="return checkInput(this)">

The form is then rendered on the page in html like this:

<form method="POST" action="http://example.com/wp-content/plugins/geoquote_plugin/views/step2.php" name="Calculate" onsubmit="return checkInput(this)">

When submitting step1 the url for step two is:

http://example.com/wp-content/plugins/geoquote_plugin/views/geoquote_step2.php

Is there a way to rewrite the URL for step two to become something like this:

http://example.com/quote/step2.php

Even if it's not possible in the html it would be nice to not have /wp-content/plugins/geoquote_plugin/ displayed in the url after submitting step one and redirecting to steop two. I know I can change th wp-content folder and plugins folder name, but I'd rather rewrite this to make the plugin work for any site as a wordpress plugin. Each step is a form written to a seperate file. Without rewriting every file of the prebuilt plugin, how can I rewrite the URLS?

I tried this but it didn't do anything:

RewriteRule ^/quote/step-2$ http://example.com/wp-content/plugins/geoquote_plugin/views/geoquote_step2.php [QSA,NC,L]
  • 2
    You shouldn't be using a standalone file in your theme/plugin to act as a form handler. This is bad practice, a potential security risk, and makes your work more difficult. Consider handling the form and displaying it in the same place, and loading different templates depending on the current step – Tom J Nowell Jul 7 '14 at 22:25
  • Thanks for the comment Tom. I definitely would rather not use the file itself, however this is currently already a generalized "plugin" that is suppose to support many CMS's. I would like to avoid rewriting too much if possible. All of the steps are already written to files. I rewrote step-one to work with wordpress, but rewriting any of the other steps breaks the plugin unless I rewrite the entire thing. – Bryan Willis Jul 8 '14 at 3:18
  • A plugin that works across multiple CMS'? I would have written a library that had APIs to display each form step, and APIs to process those forms, then written glue code that actually called them in the appropriate manner. Your current approach doesn't scale. – Tom J Nowell Jul 8 '14 at 8:52
  • 1
    You could add an extra endpoint using add_rewrite, then reference that URL to load any file you want. – jgraup Aug 14 '16 at 2:20
1

Instead of using fixed php file you can use the custom wordpress templates

create a custom template file and give it a name such as custom template name is step2.php and Step2

/*
    Template Name: Step2
*/

The contents of the custom template file is similar to the content of the file on your step2.php

Or you can use ajax to request but still could not hide the file path step2.php

  • Thanks. I tried the following but it doesn't load the file without rewriting the entire thing: function page_template( $page_template ) { if ( is_page( 'step2' ) ) { $page_template = plugin_dir_path(__FILE__) . 'views/geoquote_step2.php'; } return $page_template; } – Bryan Willis Jul 8 '14 at 4:02
  • Without rewriting to make completly wordpress compatible it seems that a rewrite is my only option maybe – Bryan Willis Jul 8 '14 at 4:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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