Forum

Thread tagged as: Addons, Forms

Alter Contact Form through Perch Admin

Hi,

I have a form that is sending contacts through to the admin area. It is also sending through a hidden field called active with a number 0 as the value. Does anyone know how I can edit the from in the perch admin area so that the user can change that to 1? (Or display a checkbox - true / false only in the Perch Admin Area)?

Steven Bradley

Steven Bradley 0 points

  • 6 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

We need to see your template.

Thanks for replying Rachel -

<perch:form id="contact" method="post" app="perch_forms">

    <perch:content id="intro" type="textarea" label="Intro" textile="true" editor="markitup" size="m" />

    <div>
        <perch:label for="name">Name</perch:label>
        <perch:input type="text" id="name" required="true" label="Name" />
        <perch:error for="name" type="required">Please add your name</perch:error>
    </div>

    <div>
        <perch:label for="email">Email</perch:label>
        <perch:input type="email" id="email" required="true" label="Email" placeholder="admin@widescope.net" />
        <perch:error for="email" type="required">Please add your email address</perch:error>
        <perch:error for="email" type="format">Please check your email address</perch:error>
    </div>

    <div>
        <perch:label for="message">Message</perch:label>
        <perch:input type="textarea" id="message" required="true" label="Message" />
        <perch:error for="message" type="required">Please add a message</perch:error>
    </div>

    <div>
        <perch:input type="hidden" id="active" value="0" label="Live" />
    </div>

    <div>
        <perch:input type="submit" id="submit" value="Send" />
    </div>

    <perch:success>
        <perch:content id="success" type="textarea" label="Thank you message" textile="true" editor="markitup" />
    </perch:success>
</perch:form>

What I want to do is take that hidden variable - active and allow the person in perch admin to change it to 1 (probably a dropdown) to signify that it is live. The intention is then to display all submissions on site if active=1.

But I don't know where to add it to the template or another one so that the option to change is only shown in perch admin.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd need to do something like:

<perch:input type="hidden" id="active" value="<perch:content id="live" type="select" options="Yes|1,No|0" label="Live" />" label="Live" />

I've tried that but the "Viewing a Response" page in the perch admin lists the following;

Response
Received    30 Jun 2015 16:36
Name    Steve 
Email   test@test.com 
Message test 
Live    

Basically it just leaves the Live bit blank. I have the template in the templates/content folder. Is that correct?

Plus none of it is editable. How do I let the Admin user edit a form response without it appearing on the form? Or am I barking up the wrong tree here completely?

Ah I've just realised it's added the option box to the region for the template under Pages. I understand why it's done that but it's actually the response form I'm trying to allow the Administrator to alter - ie view each response and change live to yes so that I can display it on another page. Is that possible?

I know this would be easier using comments App but I've already used the comments App for something else so I need a work around using a form.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Why could you not use the Comments app with a different form template?

Hi.

Ok I'm trying to go down this route but I'm really stuck now (IE using the comments app with a different form), and I can't work out why.

sell-your-horse.php page - code is essentially;

<?php perch_comments_form('sellyourhorse', 'Sell Your Horse', array('template'=>'sellyourhorse_form.html')); ?>

<?php PerchUtil::output_debug(); 

sellyourhorse_form.html is;

<perch:form id="sellyourhorse" method="post" app="perch_comments">
    <fieldset>
       <legend>Leave a comment</legend>
        <div>
            <perch:label for="sellyourhorseName">Name</perch:label>
            <perch:input type="text" id="sellyourhorseName" required="true" label="Name" antispam="name" />
            <perch:error for="sellyourhorseName" type="required">Required</perch:error>
        </div>
        <div>
            <perch:label for="sellyourhorseEmail">Email</perch:label>
            <perch:input type="email" id="sellyourhorseEmail" required="true" label="Email" antispam="email" />
            <perch:error for="sellyourhorseEmail" type="required">Required</perch:error>
            <perch:error for="sellyourhorseEmail" type="format">Check format of address</perch:error>
        </div>
        <div>
            <perch:label for="sellyourhorseURL">Website</perch:label>
            <perch:input type="url" id="sellyourhorseURL" placeholder="https://" label="URL" antispam="url" />
        </div>
        <div>
            <perch:label for="sellyourhorseHTML">Comment</perch:label>
            <perch:input type="textarea" id="sellyourhorseHTML" required="true" label="Message" antispam="body" />
            <perch:error for="sellyourhorseHTML" type="required">Required</perch:error>
        </div>
        <div>
            <perch:input type="hidden" id="parentID" value="<perch:comments id="parentID" />" />
            <perch:input type="hidden" id="parentTitle" value="<perch:comments id="parentTitle" />" />
            <perch:input type="submit" id="submitComment" value="Submit" />
        </div>

    </fieldset>
    <perch:success>
        <p>Thank you. Your comment has been submitted and will appear on the site once approved.</p>
    </perch:success>

</perch:form>

sellyourhorse.html;


<perch:before> <ul class="comments listing"> </perch:before> <li id="comment<perch:comments id="commentID" type="hidden" />"> <img src="//www.gravatar.com/avatar/<perch:comments id="sellyourhorseEmail" type="email" label="Email" order="2" hash="md5" required="true" />?s=120&d=mm" width="60" height="60" /> <div class="comment"> <div class="commenter"> <perch:if exists="sellyourhorseURL"><a href="<perch:comments id="sellyourhorseURL" type="url" label="URL" order="3" />"></perch:if> <strong><perch:comments id="sellyourhorseName" type="text" label="Name" order="1" required="true" />:</strong> <perch:if exists="sellyourhorseURL"></a></perch:if> </div> <p rel="bookmark" class="date"><perch:comments id="sellyourhorseDateTime" format="%d %b %Y %X" type="date" time="true" label="Date" /></p> <perch:comments id="sellyourhorseHTML" encode="false" html="true" type="textarea" label="Message (HTML)" order="4" required="true" /> </div> </li> <perch:after> </ul> </perch:after>

It's esentially the comment.html and comment_form.html pages with changes to the ID.

However it doesn't post.

The debug for the form - sellyourhorse_form.html shows;


Debug Message SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0 Using template: /templates/comments/sellyourhorse_form.html

But comparing it to a comment form that works - there appears to be an insert missing.

Can anyone help tell me where I'm going wrong?

Drew McLellan

Drew McLellan 2638 points
Perch Support

The form ID needs to be comment. You shouldn't need to change the other IDs. You only need to change the template if you want to collect different fields.

Again, thank you. Sorted, I understand now.

Actually Drew, I do need to collect different fields;

How do I get the comments form (that can be edited by admin) in Perch admin to display a different template for this specific input?

Is it just a case of adding some kind of IF:ELSE routine in the comment.html template based on the comment parent id?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not completely sure what you're trying to do. Could you give an example?

I have a customised comments form and comment.html template - comment_form.html that obviously uses comment.html in the perch admin. I have created another form sellyourhorse_form.html that has different fields that now posts these.

When I now go to comments and view the comment posted via the sellyourhorse_form in the perch admin, the template it is using to display the info is the comment.html and not sellyourhorse.html as displayed in the code above.

I therefore assume all of the comments (irrelevant of parentID) use the same comment.html template for Perch Admin. How do I customise that template so that it accomodates the different fields from the two different forms?

Does that make sense?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I would include all the fields you need in your comment.html master template and then use task-specific templates for display on the site.

Thanks, that's what I ended up doing, bit clunky but I think it's because I'm trying to put round pegs in square holes but had to find a solution with it being time critical. I'm going to go back and rework through it all using forms instead when time permits.

Cheers Steve