Support

Account

Forum Replies Created

  • Based on your resource page for displaying a random row, the code for doing this has changed to the following. I tried the code above and it didn’t work, but the code stated on the resource page does work to display a random row perfectly. My question now is how to mod it to display a random set of rows, not just one. Note, I tried adding that comma and a number that’s in your example, but it broke the whole output and displays nothing.

    <?php 
    
    $rows = get_field('repeater_field_name' ); // get all the rows
    $rand_row = $rows[ array_rand( $rows ) ]; // get a random row
    $rand_row_image = $rand_row['sub_field_name' ]; // get the sub field value 
    
    // Note
    // $first_row_image = 123 (image ID)
    
    $image = wp_get_attachment_image_src( $rand_row_image, 'full' );
    // url = $image[0];
    // width = $image[1];
    // height = $image[2];
    ?>
    <img src="<?php echo $image[0]; ?>" />
  • So far my workaround has been to create the group twice and setting rules to have them display only on the pages I want, etc. Was just hoping for a more elegant solution. Would be great if the at least the Pro version had something like that included where you can have a filter set on specific fields.

  • Is there a working example of the code? The description makes it sound like it applies to fields displayed on the front end. I need this for the back end.

  • Here are a couple screenshots showing the results. Thanks to everyone who helped me to get the last few bits I needed to make this work as I needed it to!

  • For those interested, below is the final code that worked. The above $headers code doesn’t work because of the double quotes, and even then, it doesn’t work. I’m guessing that the codex hasn’t been updated in a long time for that. But I managed to find a solution that works.

    To recap, the use case here is where I have a custom post type setup just for having an online design approval system. I have it set to not be archived and scanned by search engines. Soon each page will only be visible to specific users who must log in. Using acf_form() I have it set to update two custom fields. Since the validation aspect of ACF doesn’t work for forms (because you’d have to fill them in when you create the page in the first place) I have set up a sort of “faux” validation. There is a hidden div that will only display if, and only if both of those fields in the form have a value. When it does, the div containing the form is hidden and the previously hidden one is unhidden. The email notification is then only triggered if, and only if both of the fields have a value.

    If anyone is interested in a full demo of how it works live and would like the full code, just let me know.

    
    // Updates FYI last update timestamp when custom field is updated and notify admin
    function my_acf_save_post( $post_id ) {
      // bail out early if we don't need to update the date
      if( is_admin() || $post_id == 'new' ) {
         return;
       }
       global $wpdb;
    
       $datetime = date("F j, Y g:i a");
       $query = "UPDATE $wpdb->posts
    	     SET
                  post_modified = '$datetime'
                 WHERE
                  ID = '$post_id'";
        $wpdb->query( $query );
    	
    	$print_approved = get_field('approved_by');
    	$approved_email = get_field('approval_email');
    	$to = '[email protected]';
    	$subject = get_the_title($post_id) .' Design Approved';
    	$message = 'The design was approved by '. $print_approved .' ('.$approved_email.') to be sent to print.';
    	
    add_filter('wp_mail_from', 'new_mail_from');
    add_filter('wp_mail_from_name', 'new_mail_from_name');
    
    function new_mail_from($old) {
        return '[email protected]';
    }
    function new_mail_from_name($old) {
        return 'Spiderfly Studios';
    }
    
    if ( $approved_email && $print_approved ) {
    	wp_mail( $to, $subject, $message );
    }
    }
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);
    
  • @imaginedd Is there a trick to getting the $headers part to work? I’ve tried and tried and the emails will not send if I include the headers part. I followed the codex exactly too.

  • Yeah…I managed to get it to send a quick email. Now I’m just messing with different variables to plugin more info.

  • @hube2 Well…I’ve seen other forum threads that show how email alerts can be setup using acf_form, so it should be possible. He said he was open to suggestions…so one can hope.

    As for your suggestion. I have no idea how to implement that wp_mail code correctly when it comes to integrating it with that code. I just tried and no email came. I’ve never messed that wp_mail stuff before.

  • @imaginedd Actually… I do have one more related issue to this. Getting notified in some way when this is updated. I have tried a couple plugins that are a little older and claim to do this, but they don’t.

    I’d like to be notified when a client submits the form. Whether via email, push notification…whatever. It’s the missing feature I need for this to be complete.

    I am using a beta plugin which allows me to put in the acf_form() anywhere I want using a shortcode. It works really well. I have requested the ability to include optional email alerts…but ya never know if the dev will do this. https://github.com/jonathan-dejong/acf-form-shortcode

    Any creative/crazy ideas?

  • I was actually able to take care of it with the following code (which is similar to your own…just left open ended for other uses than my stated one) so I could just easily display the page’s last update time stamp. Whenever the client fills in and submits the form on the front it to update the custom fields the form is tied to, it updates the page’s time stamp. Can be used for any acf_form() used actually. For some reason acf_form doesn’t do this on its own. Personally, I think it should considering its intended purpose.

    
    // Updates FYI last update timestamp when custom field is updated
    function my_acf_save_post( $post_id ) {
      // bail out early if we don't need to update the date
      if( is_admin() || $post_id == 'new' ) {
         return;
       }
       global $wpdb;
       $datetime = date("F j, Y g:i a");
       $query = "UPDATE $wpdb->posts
    	     SET
                  post_modified = '$datetime'
                 WHERE
                  ID = '$post_id'";
        $wpdb->query( $query );
    }
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);
    
  • This reply has been marked as private.
  • Regarding the email option request…I did find this if it helps.

    https://github.com/cpham/acf-contact-form

  • I’ll let you know how it all works out on my end and if I run into any bugs.

    The suggestion for a landing page site eventually was mainly to allow you to do a little more on the explanation and demo side. And to house more examples.

    The suggestion regarding styling…those classes seem to be set for the fields. Right now I am easily styling using my stylesheet, but I thought it might make it a little easier if there could be something done in your shortcode to inject a class or id. Either through a theme’s stylesheet or a text field you put into an admin settings page, users could create their own styles to apply to said classes and IDs.

    As for theme support…I personally am using Enfold on my site. I believe it is a pretty popular theme for novice and advanced users. I think the devs have some sort of API to include in their theme builder section.

  • Ok…scratch that. I did get it to work as needed using the field key. Works great! Would recommend letting it use the field name like all the other ACF shortcodes and php snippets do just for continuity.

    Also… An admin interface for it would be great as well so people can specify things for like optionally sending an email. Things like email address it gets sent to, the subject, etc. Things like applying classes or IDs to each field so we can more easily make it match themes. Maybe….if it is possible…allow people to do a shortcode for each specific field so they can be placed and organized individually. Maybe something like…

    [acf_form] [acf_field="123"] [acf_field="456"] [acf_submit value="Save"] [/acf_form]

    Then, something you can do on the git page is start a running list of examples to help people out…then later on a landing page site for the plugin, etc.

  • @jonathan I honestly have no clue what you’re talking about…lol…

    I am new to trying to use acf_form. Never was viable for my use before. I thought your plugin took care of everything in the background programatically and all I would have to do is use the shortcode.

    I just need it to update one or two fields and email me as a notice. I’m pretty familiar with ACF and I don’t see any way to get the specific field ID number. Only the field group. The only identifier for a specific field I have ever had to use with the plugin is the name. In this case, “approved_by”.

    So does your plugin load the text fields on the front end? I haven’t been able to see a demo or get it working for myself…just going on your description.

  • @jonathan is it possible to use the filed names rather than IDs? The ACF setup as it is now doesn’t make it easy to find the specific id of a single field. Nearly every snippet used with ACF uses the field name.

  • @jonathan Will you be releasing and uploading this plugin to WordPress.org? Supporting and updating it? I tried to install it and got the following error that showed up twice right after activating:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, class ‘Acf_Form_Shortcode_Admin’ does not have a method ‘enqueue_styles’ in /home/wp-content/21/3843821/html/wp-includes/plugin.php on line 525

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, class ‘Acf_Form_Shortcode_Admin’ does not have a method ‘enqueue_scripts’ in /home/wp-content/21/3843821/html/wp-includes/plugin.php on line 525

    P.S. Bonus points for the Seinfeld reference on your site.

  • Yeah…that’s my hurdle there…getting it into the content. That’s why I was wondering if anyone has been successful in turning that part into a shortcode so I can just create the shortcode in my functions file.

    I did check out that link and left a message for an example. Will update here should it work as I need it to.

  • Hey Jonathan…this is almost exactly what I am looking for… But… Do you have an example that works to simply update a simple custom field? Just a text field. I don’t need to create new posts with an acf_form. I just need to update a field.

    To explain…I have setup a project art approval post type. They fill out the form by confirming their name and email and clicking the “Approve” button. Right now I go in and fill the field in manually with their name. Doing so hides the form section and displays a new, previously hidden section that basically says something like “Dee Buttersnaps approved this project….”, where the name is the value of said custom field.

    Having a form that pulls that value, saves it so it can be displayed…would be so helpful. Right now I get several form submissions from people thinking they don’t go through because I can’t always manually update right away.

  • Has anyone figured out how to achieve this? This as in quick/bulk editing of custom fields. That admincolums plugin is really a non-starter for most being that it is overkill when you need just that single feature. That and adding new columns is easy to do with a few line of code. I’m surprised that this isn’t a built in feature of at least the Pro version.

  • Would it still be possible to request that this be made native? That plugin does a lot more than is really needed for quick/bulk editing of custom fields. That…and $60 is an awful lot just for that single feature that is requested/needed. Especially when it is ridiculously easy to add new columns to the admin interface with little more than a few lines of code in the functions file.

  • I have looked at those and while they give the starting info, they don’t show more in depth customizations. Things like how to control how the form is thrown together…or how to include it without having to edit a theme file. Like many new themes, ours has a page builder…so a custom page template isn’t really going to work here if we want to keep things up-to-date with the theme as it updates.

    As I mentioned in my initial post, I have looked at those links in great detail and they don’t provide the info I’m looking for. Not to be rude, but I was hoping for a little more help beyond “look at these pages and figure it out for yourself” type answers.

    It doesn’t seem like it is possible to do what I am looking for it to do with the kind of control I need. I need to do more than just editing/creating posts from the front end or creating a basic contact form while using a simple WordPress theme. I need to take it to the next level. Hence my suggestion for having this built into the UI of ACF that allows you to build these forms with finer control. Basically taking what is already there for the admin backend and applying it to the frontend. For instance, when creating the field group and fields, having an option down in the “settings” section in the “position” options….”frontend”.

  • @acf-support

    The thing I would also need is the ability to define the fields in the form, as well as their layout (mainly so it fits in with the theme css and is responsive)…then have it send an email alert to me in the process.

    In this example, I would have a select box like you mentioned, a name field, an email field and a text box for notes if declined. If approved, it marks the item as approved, hides the form, then displays some text using the form fields to build it. Something like…”Dee Buttersnaps ([email protected]) approved this design on [datestamp] at [timestamp]”. That action seems pretty easy to do. It’s the rest that I can’t figure out. The acf_form() documentation is pretty slim here. All it really says is put this in a template file and you can edit a post. There aren’t any refined examples that shows you how to only show specific form fields that are tied to custom fields. Name field for the sender of the email, email address (self explanatory), and how to set the subject, etc.

    I think it would be GREAT if a form builder was added in to make it easier to create and manage this within the UI. Even if it were only part of the Pro version. It seems like the core functionality is there.

  • I too would like an easier way of doing this…ideally within the custom field setup. Just like we tell it where the entry would go in the page/post/custom post type edit screens…there would be an option for also adding it to the quick edit.

    Hell, while we’re at it, it would be great if there was an option to add the field value as an admin column. Pretty easy to do with a hook on the functions.php file, but still.

Viewing 24 posts - 1 through 24 (of 24 total)