This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 2

Problem with validate_username function


  1. idckamikaze
    Member

    I installed the Exec-PHP plugin for Wordpress to be able to execute PHP on a certain page (where a MachForm would be displayed). When I try to embed the form using the code generated in my admin panel, it gives me an error in the validate_username() function.
    Cannot redeclare validate_username() (previously declared in /homepages/32/d239429970/htdocs/mdpc/wp-includes/registration.php:49) in /homepages/32/d239429970/htdocs/machform/includes/common-validator.php on line 242

    I think this relates to my previous post about unique identifiers in XHTML. Wordpress has a registration.php file that uses the validate_username() function. MachForm also uses this function, however, I don't have enough coding knowledge to know how it relates to the ability to embed the form. I used the iframe code and I achieved what I set out to do, but I think this is an important point for future revisions of MachForm.

    Posted 15 years ago #
  2. yuniar

    Go to line 243 of "includes/common-validator.php" file. You'll find this line:

    function validate_username($value){

    change it to become:

    function validate_user_name($value){

    or any other similar function name. Thanks for the suggestion on this.


    MachForm Founder

    Posted 15 years ago #
  3. idckamikaze
    Member

    That worked and then I got a similar error on helper_functions.php, line 201, function show_message. I changed that to show_machform_message (also used in manage_form, not sure where else), but that only fixed the function conflicts.

    Now it seems like I'm getting SQL errors. This displays:
    select form_name, form_description, form_redirect, form_success_message, form_password, form_unique_ip, form_frame_height, form_has_css, form_active, form_captcha, form_review from ap_forms where form_id='2' Query failed: Table 'db273972956.ap_forms' doesn't exist

    The only thing I can figure is the query is trying to run on my WP database and not the MachForm database. It isn't critical that I use the PHP embedding feature, but I thought it would be nice to have Wordpress integration. Any thoughts would be appreciated.

    Posted 15 years ago #
  4. yuniar

    Apparently, WordPress and MachForm are using the same constant name for the database. That's why it won't able to select machform database.

    To fix it, edit your "includes/db-core.php" file. Around line 12 you will find this:

    mysql_select_db(DB_NAME) or die('Could not select database');

    change the DB_NAME above with your machform database name, example:

    mysql_select_db('my_machform') or die('Could not select database');

    make sure to put quotes as above.

    also, adjust your php embed code, add the code to re-select your wordpress db. like this:

    <?php
    	require("/appnitro/machform/machform.php");
    	$mf_param['form_id'] = 519;
    	$mf_param['base_path'] = 'http://example.com/machform/';
    	display_machform($mf_param);
    	mysql_select_db('your_wordpress_db_here'); //<-- this line
    ?>

    MachForm Founder

    Posted 15 years ago #
  5. idckamikaze
    Member

    I forgot to mention that the MachForm db and the Wordpress db are on separate servers (I'm on a virtual host). Would I need to define the parameters for the MachForm database in the db-core.php file, or could I import the config.php file into the db-core file?

    Posted 15 years ago #
  6. yuniar

    Ah.. I see. If that is the case, you need to edit another line of db-core.php file.

    Search for this line:

    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Could not connect: ' . mysql_error());

    change the DB_HOST, DB_USER and DB_PASSWORD above with a quoted string, exactly like DB_NAME


    MachForm Founder

    Posted 15 years ago #
  7. bfkouba
    Member

    This was helpful... this is the information you need (including that last step) if you're having trouble integrating with wordpress. Worked for me.

    Posted 15 years ago #
  8. jolynnbraley
    Member

    Hi, in your comment above where you wrote, "also, adjust your php embed code, add the code to re-select your wordpress db. like this:", which is followed by the block of code underneath.....what is the exact name of the file that code is to be placed in?

    Thanks!

    Posted 14 years ago #
  9. yuniar

    That code should be placed into your WordPress post/page, which you can do it from WordPress admin panel.


    MachForm Founder

    Posted 14 years ago #
  10. jolynnbraley
    Member

    Thanks Yuniar. My db's run on the same server but I also had to add in those other changes to the $link line of code after making the change in my php code in my WP page, and now the form is displaying in my WP page.

    It has a couple other issues and I'll work on those now, and then I want to connect it to Aweber. At least it's connecting to the db now though - progress is being made! :)

    JoLynn

    Posted 14 years ago #
  11. jvarn1
    Member

    It's a pain to have to remember to add:

    mysql_select_db('your_wordpress_db_here'); //<-- this line

    Every time in the embed code.

    Instead I just did a search and replace on DB_NAME, DB_PASSWORD, DB_USER, and DB_HOST across all the MachForm files using Coda and replaced all occurrences with MF_DB_NAME, MF_DB_PASSWORD etc.

    This way I can still use the copy-and-pasteable embed code from within MachForms without having to add the additional line above.

    Posted 14 years ago #
  12. yuniar

    jvarn -- yep, that works best indeed. As a matter of fact, I think we'll doing it that way for the next update.


    MachForm Founder

    Posted 14 years ago #

RSS feed for this topic

Reply