• Resolved scamrwordpressadmin

    (@scamrwordpressadmin)


    I have a table with multiple forms in it. (Same field names in each form). Each form describes the users who have signed up for a specific hike for a hiking club. I created a page formatted with the needed form fields and it works great as long as I hardcore the form name.

    I now need to be able to pass in the form name as a global variable, so I can use one output page for multiple forms.

    How can I send the form name in as a variable? Variable is $hikers. I assigned it like this:
    <?php $hikers=”my form”;?>

    Echoing out $hikers shows it contains the correct info.

    I’ve tried using $hikers and ‘$hikers’ and “hikers” but none work. No errors, just no data is output on the page.

    https://www.ads-software.com/plugins/contact-form-7-to-database-extension/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    I don’t understand. Are you using a shortcode? Are you calling the shortcode from PHP?

    Thread Starter scamrwordpressadmin

    (@scamrwordpressadmin)

    Hi Michael,

    Sorry for not being more clear.

    I have a html page and I am using a shortcode, like this:

    [cfdb-html form=”Dutchman Trail” show=”your-name,your-email,your-phone,can-drive,Num-hikers” limit=”20″ orderby=”Submitted desc”]

    The output is displayed in table format on that page.

    All works great – your plug in made that very easy!

    What I would like to do is replace the hard coded form name “Dutchman Trail” with a variable. The goal is to have one page where I can display the hikers that have signed up for any hike, and then print out that page. The only thing that will change between hikes is the hike name itself (ie: the form name).

    If there is an easier way to print out selected columns from a specific form, I’m all for that too. Currently the table of signed up hikers is part of a larger page (see above) and we don’t want to print the whole page – just the hikers who have signed up for that hike.

    The php code was just my way of trying to assign the hike name to a variable (I’m new at this, so most likely there is a much better way to go about that too.)

    Thanks!

    Plugin Author Michael Simpson

    (@msimpson)

    Something like this:

    <form action="" method="post">
        <select name="trail">
            <option value="Dutchman Trail">Dutchman Trail</option>
            <option value="Hike2">Hike2</option>
            <option value="Hike3">Hike3</option>
        </select>
    </form>
    [cfdb-table form="$_POST(trail)" show="your-name,your-email,your-phone,can-drive,Num-hikers" limit="20" orderby="Submitted desc"]

    See Filter variable substitution and Creating a form to search the database

    Thread Starter scamrwordpressadmin

    (@scamrwordpressadmin)

    Hi Michael,

    Thanks for the links to the articles, and the code.

    I read the articles and tried the code, and several variations, but am not getting anywhere. Nothing is explicit about substituting in the form name, and so I wonder if there’s something different there?

    When I use the above code, my table data just contains the actual field placeholders (ie. ${your-name} ${your-email} etc.). If I hardcode the form name in, the table prints fine, so I believe that part of my code works great.

    For some reason, the shortcode isn’t getting the form name from the $_POST(trail)

    Any other ideas?

    Thanks

    Plugin Author Michael Simpson

    (@msimpson)

    I fixed something. Update to 2.10.0 which should be available shortly.

    Then try this code (set the options to your form names)

    <form action="" method="POST">
        <select name="trail" onchange="this.form.submit()">
            <option value=""></option>
            <option value="Dutchman Trail">Dutchman Trail</option>
            <option value="Hike2">Hike2</option>
        </select>
    </form>
    [cfdb-table form="$_POST(trail)" show="your-name,your-email,your-phone,can-drive,Num-hikers" limit="20" orderby="Submitted desc"]

    Placeholder like ${your-name} only apply to [cfdb-html]. So I don’t understand why you would be seeing them.

    Thread Starter scamrwordpressadmin

    (@scamrwordpressadmin)

    That worked like a charm! We will have too many hikes to effectively use the drop down selector – so what I did was create a landing page that held the report of hikers signed up, and passed in the name of the hike. For anyone else that might need to do this, here’s the code I used.

    On the actual HIKE EVENT page, I displayed the list of hikers signed up as follows:
    [cfdb-table form="Dutchman Trail" class="hikersgoingclass" headers="your-name=Hiker Name,your-email=Email,your-phone=Phone,can-drive=Can Drive?,Num-hikers=Number of Hikers I Can Take" show="your-name,your-email,your-phone,can-drive,Num-hikers" limit="20" orderby="Submitted desc"][/cfdb-table]

    Then I included a button to take the users to the printable hikers list page, passing the hike name to the new page via the NAMEOFHIKE variable in the new page URL like this: suncityanthemhikingclub.com/who-is-going/?nameofhike='Dutchman Trail'

    Here’s the full line of code:
    <a href="https://suncityanthemhikingclub.com/who-is-going/?nameofhike='Dutchman Trail'">Click For Printable List of Hikers</a>

    The REPORT page code required that I strip the slashes out of the incoming NAMEOFHIKE. The report header uses the variable to identify the hike in question. This allows me to have one landing page that we can use for any hike. Here is that final code:

    <?php $nameofthehike=$_GET[nameofhike]?>
    
    <h1 style="text-align: center;"><strong>HIKERS WHO HAVE SIGNED UP</strong></h1>
    <h1 style="text-align: center;"><strong>FOR THE FOLLOWING HIKE</strong></h1>
    ?
    <h2 style="text-align: center;"><?php echo stripslashes($nameofthehike);?></h2>
    
       [cfdb-table form=<?php echo stripslashes($nameofthehike);?> class="hikersgoingclass" headers="your-name=Hiker Name,your-email=Email,your-phone=Phone,can-drive=Can Drive?,Num-hikers=Number of Hikers I Can Take" show="your-name,your-email,your-phone,can-drive,Num-hikers" limit="20" orderby="Submitted desc"]

    Thanks so much for all your help. Everything is working perfectly now.

    Cheers
    Kathy

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to pass FORMNAME as variable’ is closed to new replies.