[Resolved] How to embed/write basic php in generatepress html ?

Home Forums Support [Resolved] How to embed/write basic php in generatepress html ?

Home Forums Support How to embed/write basic php in generatepress html ?

  • This topic has 4 replies, 2 voices, and was last updated 4 years ago by David.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1224242
    michael

    I have successfully entered the the html of my home page in my home page generatepress html editor, including displayed text.

    Everything works fine.

    I try to add more text using simple php statement: “<?php echo “Hi there.”; ?>”

    Nothing displays… PLEASE HELP!!! I am new to WordPress, I must understand this before I can create my own Form.

    I am testing to be able to create my own Contact Form using generatepress.com suggestion:
    https://premium.wpmudev.org/blog/how-to-build-your-own-wordpress-contact-form-and-why/&#8221;

    … the php statements are not being processed.

    Thanks,

    Michael

    #1224317
    michael

    (this is an addition to my above post)

    …I am trying to create a “Contact Form” on my Home Page, as only one of several parts on my page.

    On this Home Page I have 1) Hero, 2) Text, 3) Text, 4) Text, 5) Contact Form, 6) About.

    I do not want to a separate page for my “form”.

    How do I do this using GeneratePress, Mellow SiteLibrary child theme?

    Thanks,

    Michael

    #1224662
    David
    Staff
    Customer Support

    Hi there,

    WordPress will not execute PHP that is added via the editor.

    Instead you could call your template using a Shortcode. Example function for creating shortcode:

    function your_form_shortcode() {
       ob_start();
       get_template_part('your_form_template');
       return ob_get_clean();   
    } 
    add_shortcode( 'form_shortcode', 'your_form_shortcode' );
    #1224847
    michael

    (Michael from above, more details on my issue)

    My “Contact Form” HTML code on my Home Page that is not working
    (Note that this is not a separate form page, but rather a Form Section on my Home Page.
    This is a direct copy from “https://premium.wpmudev.org/blog/how-to-build-your-own-wordpress-contact-form-and-why/&#8221; begining with line “<style type=”text/css”>”

    I am not getting an actual error number, rather the PHP code is not being substituted for values and instead the PHP statement is being displayed along with labels.

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    <span id=”signup-title” class=”section-title”>Signup</span>
    <hr id=”signup-title-underline”>

    <p>• Sign-up is Optional.</p>
    <p>• All Fields are Optional.</p>
    <p>• The more info you give, the more you can help IMPROVE the game.<br>
      –THANK YOU</p>
    <p>• If you would like to receive Email, you must enter your Email Address.</p>
    <style type=”text/css”>
    .error{
    padding: 5px 9px;
    border: 1px solid red;
    color: red;
    border-radius: 3px;
    }

    .success{
    padding: 5px 9px;
    border: 1px solid green;
    color: green;
    border-radius: 3px;
    }

    form span{
    color: red;

    margin-left: 30% !important;
    }
    </style>

    <?php echo $response; ?>
    <form action=”<?php the_permalink(); ?>” method=”post”>
    <p><label for=”name”>Name: <input type=”text” name=”message_name” value=”<?php echo esc_attr($_POST[‘message_name’]); ?>”></label></p>
    <p><label for=”message_email”>Email: <input type=”text” name=”message_email” value=”<?php echo esc_attr($_POST[‘message_email’]); ?>”></label></p>
    <p><label for=”message_text”>Message: <textarea type=”text” name=”message_text”><?php echo esc_textarea($_POST[‘message_text’]); ?></textarea></label></p>
    <p><label for=”message_human”>Human Verification: <input type=”text” style=”width: 60px;” name=”message_human”> + 3 = 5</label></p>
    <input type=”hidden” name=”submitted” value=”1″>
    <p><input type=”submit”></p>
    </form>

    #1225423
    David
    Staff
    Customer Support

    As i said – you cannot add PHP to the editor – WordPress will NOT execute it.
    If you create the template as that article explains you can then use the Shortcode i provided to call that template.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.