I would like to add user data when registering, like middle name and many others.
I have found that I can add it to wp-includes/user.php in function _get_additional_user_keys and add them to $keys, but when user edit his profile, and submit changes, that data is not saved in database, and that meta is empty.
Does anyone know what else should I do?
Thank you
edit:
in \wp-admin\user-edit.php, i have added:
<tr>
<th><label for="last_name2"><?php _e('Middle name') ?></label></th>
<td><input type="text" name="last_name2" id="last_name2" value="<?php echo esc_attr($profileuser->last_name2) ?>" class="regular-text" /></td>
</tr>
and now in my db I got meta_key without value in table wp_usermeta
Dorijan
Related
hope someone can help. I found the following code on the web and it works well to create a new custom field which I can input from the WP 'users' tab. Yet I need to give this field manually a value in php instead trough an input form. Thanks!
function custom_user_profile_fields($user){
if(is_object($user))
$company = esc_attr( get_the_author_meta( 'company', $user->ID ) );
else
$company = null;
?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="company">Company Name</label></th>
<td>
<input type="text" class="regular-text" name="company" value="<?php echo $company; ?>" id="company" /><br />
<span class="description">Where are you?</span>
</td>
</tr>
</table>
<?php
}
add_action( 'show_user_profile', 'custom_user_profile_fields' );
add_action( 'edit_user_profile', 'custom_user_profile_fields' );
add_action( "user_new_form", "custom_user_profile_fields" );
function save_custom_user_profile_fields($user_id){
# again do this only if you can
if(!current_user_can('manage_options'))
return false;
# save my custom field
update_user_meta($user_id, 'company', $_POST['company']);
}
add_action('user_register', 'save_custom_user_profile_fields');
add_action('profile_update', 'save_custom_user_profile_fields');
If you are looking to save a fixed value to each company field to the usermeta table in the WordPress database, you can modify your saving function, to provide a fixed value instead of the POST field, you are assigning in your code snippet right now.
update_user_meta(
user_id: $user_id,
meta_key: 'company',
meta_value: 'your-custom-fiexed-value-here', // <--- here you go
);
(using named parameters requires PHP ^8.0.0)
WordPress docs: https://developer.wordpress.org/reference/functions/update_user_meta/
Also, note that there is a special Stack Exchange for WordPress Q&A: https://wordpress.stackexchange.com/
I have a form which will input data from database and print it. Now at the customer name, i want an autosuggestion from the list of customer which are already in database. Eg when i start typing it should start suggesting the list of customer names which are stored in database. This is my current code for that text box.
<td valign="top"><div align="right">Enter Customer Name :</div></td>
<td valign="top"><div align="left">
<input name="customername" class="gentxt" id="customername" maxlength="50" type="text" value="<?php echo $customername; ?>" >
</div></td>
http://www.coderiddles.com/codeigniter-fetch-data-from-database/
Go through this link you will get idea how to retrieve the data form database
Happy Coding :)
i was always curious about how many websites have a delete button on their user panels.
For example, if a user can submit a post and this must be available on his user control panel to delete it if he wants how would you code this button without any frameworks in php?
What i've dont now its creatre a form with a hiden value, you can see a piece of the code below:
<?php foreach ($results as $result): ?>
<tr>
<td> <?php echo $result['id'] ?> </td>
<td> <?php echo $result['message'] ?> </td>
<td> <?php echo $result['name'] ?> </td>
<td>
<form method="POST" action="">
<input type="checkbox"
name="delete_action"
value="<?= $result['id'] ?>"
style="display:none; visibility:hidden;"
checked>
<input class="" type="submit" value="Delete">
</form>
</td>
</tr>
Time for the php action:
if (isset($_POST['delete_action'])) {
$get_id_to_delete = $_POST['delete_action'];
$delete_action = $pdo_testimonials->prepare("DELETE FROM testimonials WHERE id = :id");
$delete_action->bindParam(':id', $get_id_to_delete);
$delete_action->execute();
}
So, as you can see the methond is so insecure and easy to mess up. However i've used it only for a control panel which only i have access. I know that i should never use a similar way of adding a delete button on a production website.
Is there any better, more secure and reliable way to do it?
Simple link (GET) showing only when it's content that current user can remove is ok, as long as you check that in PHP again. So:
Check if current user can remove element.
If so, display (image) link to for example /delete.php?id=2.
On page delete.php check if current user can remove element with id = 2.
If so, remove element and get back to page. Otherwise display warning.
It can be done with AJAX too, with same steps.
I have a form that has many text fields. Among them I have an issue with textfields (seating area and price). They can me added more and more according to the user clicks.
Here are my conditions:
1 - if (either of them) seating area textfield is empty or the price textfield is
empty the form should not be submitted.
2 - I have already used jquery plugin to validate some text fields but not all.
3 - As the field(seating area and price are related to each other in my condition
I have used their name as array to post all the value in array like:
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea[]">
</td>
<td>
<input type="text" name="fldPrice[]" id="fldPrice[]">
</td>
</tr>
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea[]">
</td>
<td>
<input type="text" name="fldPrice[]" id="fldPrice[]">
</td>
</tr>
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea[]">
</td>
<td>
<input type="text" name="fldPrice[]" id="fldPrice[]">
</td>
</tr>
4 - and whenever the user clicks add more the table row is inserted with fields
5 - I have not validate these fields(fldSeatingarea[] and fldPrice[])
6 - User must put value to both field of same row or to none of same tbl row.
SO my question is: how am I gonna find either of the two fields (fldSeatingarea[] and fldPrice[]) of the same table row are not empty when the form is submitted?
If either of the fields of same table row is empty the form should not be submitted.
I am doing this small experiment using html, php, and a little bit of javascript.
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea_1">
</td>
<td>
<input type="text" name="fldPrice[]" id="fldPrice_2">
</td>
</tr>
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea_2">
</td>
<td>
<input type="text" name="fldPrice" id="fldPrice_2">
</td>
</tr>
Use Id's Like this to reference the fields for validation.. otherwise it will not work.
I don't particularly agree with how you have used IDs on your form. I would keep a JS array variable to indicate the selected seating areas, while you populate the form.
Then you can change the ID of the element to be fldSeatingarea_3 or fldSeatingarea_5 and target both area and price elements by looping through the array for (var n in selection) { //check the 'fldSeatingarea_'+n field }
if you wana concept than you can do it with parent and child concept through jquery
what you have to do find all tr in table and than for each tr find their fldSeatingarea[] and fldPrice[]
after it validate it if you find both are empty return false for submit event
here are some link which may help you more for it
http://api.jquery.com/child-selector/
http://api.jquery.com/parent/
Just my opinion
After submiting the form all the field(fldSeatingarea[] and fldPrice[])
is passed in an array.both of them..
You can used count to compare the how many value are inserted and how many fields are added and if they ddon`t have the same value the form will triger and not submit unless they have the same value.
dear all..i have a textfield
<tr>
<td>
<td><input type="text" id="model_name"></td>
</td>
</tr>
and a cell
<tr>
<td><div id="value">//i want data show here after fill textfield</div>
</td>
</tr>
beside that, i've a table "settingdata" in database it consist of 2 field:itemdata and remark..
itemdata's value are "UD" and remark's value are "FM=87.5-108.0MHZ"...
what must i do if i want after type model name "car01UD" at textfield inside
<div id="value"></div>
can show "FM=87.5-108.0mhz"...
if you want "0103" + value of itemdata then do following
<input type="text" id="mod" value="0103<?PHP echo $itemdata ?>">
Looks like you are trying to do basic Ajax functionality. Consider reading some Ajax tutorials to get an idea how to do this.