Customizing WordPress

A potential customer has a WordPress site & needs to add the capability to interface one or more web forms to a MySQL database on the web server.

Is this easy to do in WordPress? Is it possible (or desirable) to add custom php scripts to accomplish this?

How easy is it to do form field edits (for example, an email address must be formatted as a standard email, a telephone # must be in the standard format, etc.)?

Can WordPress be used to provide admin tools to allow reports to be generated from the database, to maintain admin tables, etc.

Any references to documentation that addresses these capabilities & how to accomplish them would be appreciated.
Richard KortsBusiness Owner / Chief DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I wrote an article recently as to the dynamic capabilities of WordPress you might want to read:

Basically, you can create any sort of a page (including forms) in a standard WordPress page by simply adding a shortcode to the page, as your case could be [client_form] or something like that.

Having that in your WordPress page, add the code from the article and modify it to do something like:


function custom_shortcode_handler( $atts, $content=null, $code="" ) {
   global $wpdb;

   extract( shortcode_atts( array(
      'attr_1' => 'attribute 1 default',
      'attr_2' => 'attribute 2 default',
      // ...etc
      ), $atts ) );

      if (isset($_POST['submitted'])) {
          if ($_POST['test_text'] != '')
               $test = mysql_real_escape_string( $_POST['test_text'] );
          $sql = "INSERT INTO table_name VALUES ($test)";
          if (!$res = mysql_query($sql))
              $errmsg = mysql_errno() . ' ' . mysql_error();
              echo "<br/>QUERY FAIL: ";
              echo "<br/>$sql <br/>";
          } else {
              echo "Form successfully submitted.";
      $html = '<form name="client_form" method="post" action="">';
      $html .= '<label for "test_text">Text: <input name="test_text" id="test_text" value="' . $_POST['test_text'] . '" /></label><br />';
      $html .= '<input type="hidden" name="submitted" id="submitted" value="1" /></label><br />';
      $html .= '<input type="submit" value="Submit">';
      $html .= '</form>';

      return $html;
add_shortcode( 'example', 'custom_shortcode_handler' );

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sorry, I didn't address this question:

"Can WordPress be used to provide admin tools to allow reports to be generated from the database, to maintain admin tables, etc."

WordPress can be adapted to do anything you want.  In the case of database reporting, it is recommended that you tie into the administrative backend of WordPress by accessing the wp-admin pages.  You can create a plugin that would create a new menu item in the sidebar and display any information you want form the database.

Preliminary coding you would need to set up the admin pages is as follows:

Plugin Name: <Name of your plugin>
Plugin URI: <Your url>
Description: <A brief description of what it does>
Version: 1.0
Author: <Your name>
Author URI: <Your website>
License: GPL2

 * Custom Administrative Menus Functions
function display_module_menu() {
// Display Module Administrative Menus

	add_menu_page('Reports', 'Reports', 'manage_options', __FILE__, '', '', 61);
	$gn_hook = add_submenu_page(__FILE__, 'Display', 'Display', 'manage_options', __FILE__, 'display' ); 

function display() {
   echo "This is the report display page";
   // This function will display the database info in whatever format you want it

Open in new window

Sorry, I forgot to add this to the end of my coding:

add_action('admin_menu', 'display_module_menu');

Open in new window

And I didn't mention at the end of the custom_shortcode_handler() function you will need to change "example" to whatever your shortcode will be.  If you choose to use [client_form] like I had suggested, then your code would be:
add_shortcode( 'client_form', 'custom_shortcode_handler' );

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.