I am using ACF repeater field for user profiles, which shows like this in the user profile page:
That's cool.
But on the front-end I have a form that I want to use to delete a specific row. My custom form simply lists all the rows with radio buttons, and so if the user selected number 3 and submitted the form then I want to delete the third row (in this example, the row with Catherine Davies would be deleted).
The form works fine in that it submits as expected and returns the value the user selected, but my code to delete the row that was selected doesn't seem to work.
The ACF documentation seems a little vague on the subject. Based on a combination of the ACF doc and this StackOverflow post, I expect this code to work but it does not:
$user_ID = get_current_user_id();
$field = 'extra_user_info'; // Name of the repeater field
$row_to_delete = $_POST["row_to_delete"];
delete_sub_row($field, $row_to_delete, 'user_' . $user_id);
Just to be sure, even if I hardcode the $row_to_delete variable to any number (from 1 to 4) it still does not delete any row.
Just to clarify, I wish to delete an entire row.
Note: I realise I could just embed the ACF form on the front-end, but for reasons I won't go into this is not an option, hence using my own custom form.
There could be another issue but in your example at least, your $user_ID variable has capital letters, while the variable passed to delete_sub_row() is lowercase. PHP variables are case-sensitive.
Related
I have a SQL Database where the users can create a ticket then update the ticket if need be. This all works and the user can view the updated field in the , but what I would to achieve is to display the newly updated field in a different textarea field but not be able to edit it and only edit a new textarea field. Once saved and the user needs to update it again it needs to then display the 2 uneditable textfields and display new textfield to update.
Here is my code what i have at the moment:
<div class="form-group col-lg-12 col-md-12 col-sm-12 <?php echo (!empty($description_err)) ? 'has-error' : ''; ?>">
<label>Description</label>
<textarea name="descriptionfield" class="form-control" required="required" placeholder="Enter Description"><?php echo $description; ?></textarea>
</div>
So with this code I can update and delete but only displays in the same textarea.
Can someone point me in the right direction to achieve this?
Hoping what I explained makes sense.
Thanks
Something like the below image
So you are only able to update and delete a textarea but you want to show the original one and a new empty text area after they submit, then if they update that one, the original one and second one show all while allowing a new textfield to be there?
You aren't creating the text-boxes, submitting queries, and fetching results in a way the allows you to do that.
What you need to do is:
In your general application you will need 2 things, the empty text area field for the which you already have. An empty div area where you could display the old text areas.
In your database you need to add another table because you you will basically be joining these child text area updates updates. new table: textareachildren.
When somebody submits a ticket, that text area information should go into your first table where the info is going which is already happening. Now I'm assuming your table for those posts has a primary ID correct? so lets say we just put a ticket in and the ID is 1. Here is where #Padmanabhan is trying to find out, when the ticket is submitted the page is refreshed correct? and it shows that ticket they just submitted?
Now they want to edit that ticket's text area, I assume you already are pulling in the ticket by it's ID. Since you said they could already edit/update but it just shows the value they submitted. It looks by your picture that theres a note added and new note section. OK so thats good, so within that function where they could update the ticket text area field, a few important things need to happen. Once they click update, you need to run a sql query to input this new textarea value into the textareachildren table. within that table there should be 3 columns, the primary ID of the new items in there, the value of the textarea field, and third the important the connecting_ID which is the same value of the ID of the original ticket ID. this is how they will be connected and you could display those historical text areas.
Now go back to your original query that displays the ticket when they first submit, in there you need to also query by joining the the original ticket id with the connecting_ID of the new child textarea. The query will say ah yes, I am pulling this textarea value from the other table because my connecting_ID is 1 and it matches my 'parents' so I know I belong to them. Then just display that in the html within a new text area field that does not have the option to update/edit, since its probably a for loop for all those children that you want to show, you could add in the HTML textarea disabled readonly attributes, and even add classes to it so its like grayed out or something that shows you can't edit.
So to summarize every time somebody updates the text field you aren't changing that original value since you want to display that, you just add this new child textarea field value in a new table, when you query to show those old values to you just join them and display those historical textareas how ever you want.
The above function then checks for a condition for two scenarios:
1. Image is selected: a post is created from the first function when an image is selected. Because it already has the post_id, it simply updates the "dummy" content with the real content from the input fields
2. Image is not selected: as an image is not selected, then there is no post created from the first function. Because there is no post (thus no post_id), it creates a new post using the input fields.
Problem:
There are total 4 input fields that I need to have: title (title), description(content), tag(rh_tag) and custom field (custom_1).
I am having a problem with tag and custom field in a scenario when an image is selected (the function is not completed).
So, let say, if I do not select an image (thus no post is created from the first function), then the second function (and "else" part) simply creates a new post with all the four input. This works just fine.
However, if I select an image, then I am missing something and I can't somehow make the function work. I tried to add same $post =array as the second function, but it was not successful.
Can someone help me out how to "complete" the first function so that I can add tag and custom post meta even when an image is selected?
At first, look at WordPress codex. As I see, you have incorrect usage of update_post_meta. You should use post_id as first argument of the function, not array
At second, before accessing value from $_POST array, be sure that it exists:
$customValue = isset($_POST['custom_1']) ? $_POST['custom_1'] : 'default value';
I've got a List field with Gravity Forms to populate some custom fields in a custom post type. The site is a recipe submission site, and I'm looking for users to be able to add ingredients individually for better SEO. My issue is, when I submit the form only the last input field under ingredients is passed to the recipe.
I know I need a serialized list as this custom field pulls an array, but I'm at a complete loss of how to do that. The array should read something like this
a:8:{i:0;s:26:"4oz piece of salmon/person";i:1;s:12:"1 egg/person";i:2;s:37:"1-2 multi-colored bell peppers/person";i:3;s:12:"Greek olives";i:4;s:9:"Olive oil";i:5;s:13:"Salt & Pepper";i:6;s:22:"Basil (fresh or dried)";i:7;s:0:"";}
I don't even know where to begin in putting together a serialized array for one form field, so any nudge in the right direction is greatly appreciated.
Unfortunately Gravity Forms is configured to store these as separate meta records. One option is to customize the Gravity Forms forms_model.php file, create_post function, which unserializes the field contents and loops through each item to create a new post_meta record.
The following code should replace the case for field type list, and will prevent the creation of individual meta records on a predefined array of Gravity Form fields:
case "list" :
$skipped_list_fields = array('<meta name for field to skip unserializing>',
'<meta name for another field to skip unserializing>');
$value = maybe_unserialize($value);
if (in_array($meta_name, $skipped_list_fields)) {
if(!rgblank($value))
add_post_meta($post_id, $meta_name, $value);
} else {
if(is_array($value)){
foreach($value as $item){
if(is_array($item))
$item = implode("|", $item);
if(!rgblank($item))
add_post_meta($post_id, $meta_name, $item);
}
}
}
break;
Jason, someone had a similar situation https://stackoverflow.com/questions/20591802/how-to-save-comma-separated-inputs-in-gravity-forms-to-a-global-array-on-form-su - I think a similar edit in functions.php in your theme is the direction...
With a Custom Field form field configured as a List type and having filled out the form like this, I'm seeing all the ingredients as separate post meta items (but all attached to the same key) like this.
Is this different from what you are seeing or are you trying to achieve something different?
Use the 'List' field type from the 'Advanced Fields' area when creating/editing your form. That data is already serialized and saved as an array in a single field. Just use the gform_after_submission hook to save the GF field as postmeta.
I have the following JsFiddle to help with my question:
http://jsfiddle.net/eY2yH/3/
I am ultimately trying to create a simple input field which allows a user to enter multiple 'names' which creates a message to those users on our system. In many ways, this should function EXACTLY as Composing an email in Gmail (enter text for a user name/email, the autosuggests appears, then allow for additional input or submit).
When I run the code given, the results of the $_POST are quite strange.
Depending on which members are selected, the value of the key changes:
array([as-results-0XXX]=>1,2,3,4)
where XXX varies and 1,2,3,4 would represent the value of the members selected. These values are stored in a single element and separated by comma. In the end, I want to run through a loop for each user selected and send the necessary alert:
If 3 members are selected, e.g.
foreach($rows as $row) {
do table insert with particular value
}
My site is built with php and clearly using jquery. I have done a bit of searching and can find nothing regarding multiple inputs on the same autosuggest field.
You can change the way the name of the hidden input is determined by adding the asHtmlID attribute to your .autoSuggest():
$("input.autoSuggest").autoSuggest(data.items, {
selectedItemProp: "name",
searchObjProps: "name",
asHtmlID: "custom_id"
});
The variable posted to your php script will be available through $_POST['as_values_custom_id']
I currently have a PHP form that uses AJAX to connect to MySQL and display records matching a user's selection (AJAX: Display MySQL data with value from multiple select boxes)
As well as displaying the data, I also place an 'Edit' button next to each result which displays a form where the data can be edited. My problem is editing unique records since currently I only use the selected values for 'name' and 'age' to find the record. If two (or more) records share the same name and age, I am only able to edit the first result.
Let's assume your file for editing is edit.php. Then, in the file where you generate the edit links, try changing your edit button link as follows:
'edit'
Then you will be able to access ID variable as
echo $_REQUEST['ID'];
Note that the ID is case sensitive. Let me know how it goes.
when displaying records from ajax, also send the primary field(id in most cases) along with name and age
and when u are displaying these data along with edit incorporate that primary field with edit