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

mysql Search


  1. bhogsett
    Member

    I have just purchased and installed MachForm. Installation was as fast and easy as advertised.

    I want to use the form to launch a search.php script rather than insert information into the database.

    Do I have to manually change the form code? I looked in the data directory and the files subdirectory, but the files are not appearing.

    Help please.

    Bill Hogsett

    Posted 15 years ago #
  2. yuniar

    Hi Bill,

    So you would like your form to redirect to search.php after form submission and pass some search query parameters?

    If so, what are the parameters needed by search.php ?


    MachForm Founder

    Posted 15 years ago #
  3. bhogsett
    Member

    Yes, I want to pass the POST values to search.php so that search.php can construct the mysql query and then display the results.

    Bill

    Posted 15 years ago #
  4. bhogsett
    Member

    I still need some help. After reading many of the forum messages, it appears I intend to use the forms differently than they were intended. While I have a working mysql database on the server (bhogsett.com in music) I do not need to use the Machform form to insert data into the database.

    I bought Machforms for the look of the form and the ease of creating the forms.

    What I want to do is get the data from the form into my own php search script that will search my database and display the results in my page.

    I found a post here that suggested inserting:

    //retrieve the data from element WFH added
    if ($key == 'element_1' && $form_id == '1') {
    $_SESSION['Artist'] = $value;
    }

    to line 948 of the post_functions include file. I added the 'Artist'.

    My redirect test page (variable.php) is:

    <html>
    <head>
    <title>My Variables PHP Script</title>
    </head>
    <body>
    <p>The artist is: <? echo $_SESSION['element_1'] ?></p>
    </body>
    </html>

    I do not think I understand how to pass the $_SESSION to the redirect page.

    At the end of the day, I will settle for just adding an action=variables.php and give up all of the Machform validation and database entry. But maybe there is a better solution.

    Thanks.

    Bill

    Posted 15 years ago #
  5. redityo

    Hi ..

    I think it's better to use SESSION instead of POST variable and I think you've done the correct way.
    In this case I assume you want to parse "element_1" on form 1 to search.php, so you need to do the following steps.

    1. Edit "includes/post-functions.php" on line 943

    if ($key == 'element_1' && $form_id == '1') {
    	$_SESSION['artist'] = $value;
    }

    2. in your search.php file add this code to get session variable

    <?php
       session_start();
    ?>
    <html>
    <head>
    <title>My Variables PHP Script</title>
    </head>
    
    <body>
     The artist is: <? echo $_SESSION['artist'] ?>
    
    </body>
    </html>

    MachForm Support

    Posted 15 years ago #
  6. bhogsett
    Member

    Thanks that works fine. I didn't realize I needed:

    if ($key == 'element_1' && $form_id == '1') {
    $_SESSION['artist'] = $value;
    }

    Any suggestion how to generalize the insertion into the SESSION array? I will have maybe 4 forms each with one element (likely to be album, artist, track, date). I can do a series of ifs or switches, but is there a more elegant way?

    Final question for now. I don't need or particular want the form data to be inserted into my database. I thought I saw once directions as to which lines to comment out to avoid the insertion, but I can't find it now.

    Thanks again!

    Bill

    Posted 15 years ago #
  7. bhogsett
    Member

    OK, I now have my album, artist and track search working, but date is not working.

    Here is what I have added to post-functions.php

    // Get the data to my search script
    if ($key == 'element_1_1' && $form_id == '1') {

    $_SESSION['month'] = $value;
    }
    if ($key == 'element_1_2' && $form_id == '1') {

    $_SESSION['day'] = $value;
    }
    if ($key == 'element_1_3' && $form_id == '1') {

    $_SESSION['year'] = $value;
    }

    if ($key == 'element_1' && $form_id == '2') {

    $_SESSION['artist'] = $value;
    }
    if ($key == 'element_1' && $form_id == '3') {

    $_SESSION['album'] = $value;
    }
    if ($key == 'element_1' && $form_id == '4') {

    The information for the date search form is apparently not being inserted into the $_SESSION variable while the other search forms all insert the data. The date is three elements and I suspect that is the problem.

    Any suggestions? Is the element for date an array that needs walked?

    Thanks.

    Bill

    Posted 15 years ago #
  8. redityo

    You can try this code, For date element you don't have to mention child number like "element_1_1" in there, but you can use "element_1" only

    if ($key == 'element_1' && $form_id == '1') {
    	$_SESSION['date_time'] = $value;
    }

    If you do not want to save the data to database, you can comment the code between line 1015 ~ 1020 in "includes/post-functions.php" file

    /*
    if(empty($form_review)){
    	$query = "INSERT INTO <code>ap_form_{$form_id}</code> ($field_list)
     VALUES ($field_values);";
    }else{ //insert to temporary table, if form review is enabled
    	$query = "INSERT INTO <code>ap_form_{$form_id}_review</code> ($field_list)
     VALUES ($field_values);";
    }
    */

    MachForm Support

    Posted 15 years ago #

RSS feed for this topic

Reply