WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Cant get php to work inside shortcode content (7 posts)

  1. senyoraangelica
    Member
    Posted 1 year ago #

    I tried several solutions from looking at similar questions within the site but it won't work me. =( Please help.

    This is an excerpt from my original code:

    <form action="" method="get">
    <input type="text" name="search" value="">
    <input type="submit" value="Search">
    <?php echo do_shortcode('[expand]
    <input type="checkbox" name="title" <?php if(isset($_GET['title'])) echo "checked='checked'"; ?>>
        <label for="ti">Title</label></td>
    [/expand]'); ?>
    </form>

    Basically, I want my checkboxes to remain checked, if they were checked before hitting submit. Unfortunately, it's been hours and I can't get the php to work inside the shortcode.

    Please help.

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Where is this code being added?
    Where is the shortcode being defined?

  3. senyoraangelica
    Member
    Posted 1 year ago #

    Hello! Please see my code excerpt from the first post. I don't know but you may have missed it when I was editing it before you replied?

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    I did look at your code. I have no idea from that where it is being used. And the shortcode is not defined in the snippet you posted above.

  5. senyoraangelica
    Member
    Posted 1 year ago #

    I am writing the code from a pod page:
    http://wordpress.org/plugins/pods/
    Is that what you mean?

    <?php if(isset($_GET['title'])) echo "checked='checked'"; ?> works if I remove the <?php echo do_shortcode('[expand] and [/expand]'); ?>

    So I guess it doesn't work inside do_shortcode? How do I get it to work?

  6. esmi
    Forum Moderator
    Posted 1 year ago #

  7. senyoraangelica
    Member
    Posted 1 year ago #

    I don't think that's necessary since my question doesn't have anything to do with pods but simply with making the PHP work inside a shortcode.

    EDIT:

    <form action="" method="GET">
        <input type="text" name="search" value="">
        <input type="submit" value="Search">
        <?php
         $check=isset($_GET['title']) ? "checked='checked'" : '';
         echo do_shortcode('[expand]
         <input type="checkbox" name="title" '.$check.' ><label for="ti">Title</label></td>
         <input type="submit" value="Search">
         [/expand]');
        ?>
    </form>

    The above code is the solution. Thanks to Spencer for replying!

Topic Closed

This topic has been closed to new replies.

About this Topic