0

ok, guys this one is tricky at least for me. I have been given a template called page-warranty-registration.php and in this area towards the end:

            <option value="10">10</option>
              <option value="9">9</option>
              <option value="8">8</option>
              <option value="7">7</option>
              <option value="6">6</option>
              <option value="5">5</option>
              <option value="4">4</option>
              <option value="3">3</option>
              <option value="2">2</option>
              <option value="1">1</option>
              <option value="0">0</option>
            </select>
          </fieldset>
          <fieldset>
            <div style="float: left; margin-right: 10px;">
              <input type="checkbox" name="share-permission">
            </div>
            <label style="display: inline;" for="share-permission">I do not want my comments/feedback shared</label>
          </fieldset>
          <fieldset class="form-confirmation">
            <div style="float: left; margin-right: 10px;">
              <input type="checkbox" name="document-confirmation" required>
            </div>
            <label style="display: inline;" for="document-confirmation">I have read and acknowledge receipt of the Warranty, Fiberglass Pool Care Guide, and all APSP Safety Documents. <em style="font-weight: 400;">(If you have not reviewed the documents click <a href="#warranty-documents">here</a>)</em><label/><br/>
            <label for="fullname">Full Name:</label>
            <input type="text" name="fullname" required>
            <em style="font-weight: 400; font-size: 14px;">(By entering your full name here, you are signing this registration electronically. You agree your electronic signature is the legal equivalent of your manual signature on this registration.)</em><br/>
            <br/>
            <label for="signature-date">Date:</label><br/>
            <input type="date" name="signature-date" required>
            <br/>
          </fieldset>
          <fieldset>
            <input onclick="formSubmit()" type="submit" value="Submit" class="button button-yellow">
          </fieldset>
        </form>


      <a href="#page-top" class="scroll-button"><img src="<?php bloginfo( 'template_directory' ); ?>/img/white-arrow-up.svg"></a>
    </div>
  </main>
</div>

<?php get_footer(); ?>

I need to code something dynamic from two different wordpress pages via dashboard. That is, there are two different pages created on Pages in dashboard, one called standard and one called fpa for simplicity sake. I am assuming both are rendered dynamically using the page-warranty-registration.php.

Now I need to code a snippet that will render two different codes for each page. Let me unpack that. There is a textarea created with acf pro for each page. In that textarea will be a script that looks like this:

<script type="text/javascript">
   var __ss_noform = __ss_noform || [];
   __ss_noform.push(['baseURI', 'https://app-3QN76YGDSU.marketingautomation.services/webforms/receivePostback/MzawMDE1sTA3BgA/']);
   __ss_noform.push(['endpoint', 'eb954452-79ae-44e2-b1d2-ecf25f4fa285']);
</script>
<script type="text/javascript" src="https://koi-3QN76YGDSU.marketingautomation.services/client/noform.js?ver=1.24" ></script>

this will be added in the textarea via dashboard, but the script will be slightly different for the standard page and the fpa page.

I believe I can code something in the page-warranty-registration.php file that will allow for the dynamic rendering of the code in the textarea of each individual page. Does this make sense? If so, how would that code look like? Is it the same as dynamically coding a blog?

see usually dynamically coded wp is to show on the front end the content from the dashboard but that's not exactly what we want here. I want the code from the dashboard to be pulled in as if I had hard coded it on the backend. I have never done this before.

So I thought perhaps I could do this:

<?php the_field('textarea'); ?>

but that cannot be enough because there are two separate acf textareas in each page, so there is an argument missing somewhere so that the id of each textarea can be passed.

I am even thinking why is there one templated page for two separate Pages. I also see there are no conditional statements saying if customer fills out standard output this or if they fill out fpa output that. I am feeling like there should be two separate php files, one for standard and one for fpa.

1 Answer 1

0

Daniel, To clarify. You have acf installed, and in acf you have created a field group that shows up on pages and in that field group you have a text area called 'textarea'?

Then when you edit a page under the content editor you have a the 'textarea' field. You enter your script here. On the two pages in quesion each has a script and you want when someone goes to www.example.com/standard or www.example/fpa, they will see ONLY the script that was entered into the page edit screen of the page that the user is viewing?

If this is the case the code is here:

if (get_field('textarea')) {  //checks if there is content in the field 'textarea'
   echo get_field('textarea'); //if there is, displays the content of the field
}

This will only render the textarea field for the page that is being viewed.

if indeed those pages are using the page-warranty-registration.php file then put this code there and it will show the field if there is content in the field.

Based on your comment:

if (get_field('sharpspring_code')) {  //checks if there is content in the field 'textarea'
   echo get_field('sharpspring_code'); //if there is, displays the content of the field
}

I would still add the conditional because if some other pages don't have this code entered you will get a php error.

whether you use echo get_field() or the_field() is particular to coding and in this case either will work.

2
  • rudtek, thank you, what my colleague and I did was add this snippet: <?php the_field('sharpspring_code'); ?> to page-warranty-registration.php and it seemed to be offering the behavior we want. So I am marking your answer as the correct one.
    – Daniel
    Commented Apr 6, 2017 at 0:27
  • Hi Daniel, thanks for the credits. See my update at the bottom of my answer regarding your comments.
    – rudtek
    Commented Apr 6, 2017 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.