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']
Related
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.
I'm using the Formidable Pro WordPress plugin to create editable forms. Each form has several different "Contact Info" areas (in the below picture, one such area is "General Contractor", and another one is "Mechanical Engineer"), and each area has several inputs.
What I'm looking to create:
Enter first few letters of persons name in "Contact" input
Select a name from resulting Autocomplete drop-down
Populate nearby fields with Contact's respective information (Company, Email, Phone, Fax, Tax ID, and Address)
The first image below shows two of the "Contact Info" areas (the first of which I drew in each input's ID). The second image shows how each Contact's information is stored in a MySQL table.
So are there any Autocomplete WordPress or jQuery plugins that can help me accomplish this, and if so, how would I go about implementing this feature?
I'm guessing for the drop-downs you're using dynamic fields? Replace these with Lookup fields and then you can automatically populate values of other fields like so:
For each field you want auto-populated, go into the field settings and check the option 'Dynamically retrieve the value from a Lookup field'. Then, for the 'Get value from' options, you'll need to select the form and field you want to Get the data from. Then, for the 'Watch Lookup fields' option you'll need to select the lookup field (which will be your 'Contact' input that users are typing into).
im doing some web designing with wordpress at the moment.
I have created a page with a web form where a client can input some information (name, email, invoice number, price, gst, etc).
I used a plugin called contact form 7 to provide the web form, when the user inputs all of their information, the plugin then emails an html formatted invoice to my email address, with the fields occupied by shortcodes which take on the value from the web form.
For example, in the name field of my invoice table, i enter [first-name] and the name the user inputs gets emailed to me in the invoice.
I need to find a way to sum the value of two of the other fields, one of the fields on my invoice form is called total, which should be equal to [gst]+[price] that the user inputs on the web form.
Ive tried to look for a php shortcode function that can take its arguments as the values of other shortcodes, but havent had any luck. I have never really used php before either so wouldnt know how to write one.
I managed to find this, which doesnt seem to work, as when the email comes through all i see is [sumsc][gst] [price][/sumsc]
add_shortcode('sumsc','sumsc_func');
function sumsc_func( $atts, $content = null ) {
$sum=0;
$content=str_replace(array(" ","] [","]["),array(" ","][","]|["),$content);
$codes=explode("|",$content);
foreach($codes as $code){
$sum+=do_shortcode($code);
}
return " <div>".$sum."
</div>";
}
Any help would be greatly appreciated, I also need to the functionality to be able to multiply a shortcode value by a certain number. For example the price needs to be divided by 0.6 to give the quantity which appears on the invoice. Thanks!
Create a hidden field in the form say with a unique id say it fields_sum.
Use jquery on that page and catch form submission event. Get values of those fields, sum it and set the result to fields_sum field. And then use field shortcode where you want.
jQuery script would be something like (Algorithm)
$(document).ready(function(){
$("your_form_id").submit(function(e){
// get value of field one
// get value of field two
// sum them
// set sum to the hidden field
});
});
I hope this works and enough to get a solution like this.
I want to create a PHP script which can fill up a form from a text file. The form is on a password-protected page. There are 4 fields where i need to put text (name, village, etc.)
I need to select checkboxes but they are in an array and I only know their label name. At max I can look up id's and use it as static values, but I don't know them how to use them either.
<form method="POST" action="...">
<input type="checkbox" name="tag_id[]" id="tag_id_192" value="192"><label for="tag_id_192">House</label>
I saw lots of tutorials which shows how to do it with checkboxes but they used the check box name and without the login part. I never used PHP before so I don't know even where to start. If someone could guide i would be very grateful.
Example:
The .txt file each row represents a form fill up the fields are separated with a *: Name * village .... * the check boxes label names which i need to set active
If you're using cURL, you can post multiple fields with the same name, if it has [] after the name, php will automatically concatenate them all into an array..
So its valid to do tag_id[]=192&tag_id[]=175&tag_id=[285]..
In PHP it will know to make it array(192,175,285)
As a side note, fields that do not have [] get overwritten each time they appear...
I have a dropdown with a list of values that are pulled from a MySQL database. Each of these values has other corresponding attributes in the database. This is the structure of that table:
id | name | password
The dropdown values are basically just all of the values in the "name" column.
What I'd like to do is display the id/name/password for a selected dropdown value in a separate div. That is, if I select "MIT" from the dropdown, I'd like the div to show me the id and the password associated with MIT. If I select "Harvard", I'd like the div to show the id and password associate with Harvard.
I am just looking for high-level suggestions on how I should approach a setup like this.
I was thinking of using AJAX and passing the selected value into a separate PHP file, which would then pull and display the associated ID and password. The div would then contain code to make a call to that PHP file and display the values on that page.
I think it'd work in theory, but it seems a bit cumbersome...any ideas for simplifying the process?
You could use data-attributes on your options. This would expose the passwords through the markup, but since they are accesible anyways through choosing the option in the dropdown, I guess this isn't an issue.
If you gave each option an attribute data-password="thepassword", then you could $("select").find(":selected").data("password") to retrieve the password. Do the same with a data-id attribute, and you're golden.
Another solution would be to have a JSon structure with the option values as keys. Let's say {"MIT":"1234","Harvard":"verysecret"} and then use $("select").change() and $(this).val() to retrieve the corresponding passwords (and other data) from you JSon structure.