Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Function to update databse fields

@martinbeaulne

Participant

Well well. I finally found, and I’m surprised the answer didn’t come from this thread.

It is quite simple, in fact. Just need to use the function:


xprofile_set_field_data($field, $member-id,  $value);

So, with a simple form sending those three values, one can update a single field anywhere. As I wanted to let members update their fields directly from their member profile ( without using the very bad and obscure edit.php ), I put a form and the function in the member-header.php

My form and function updates three fields.

Here is the function, somewhere in the member-header.php file:


<?php
function updatedemo() {
    $id = $_POST['id-member'];
    $liendemo = $_POST['liendemo'];
    $champdemo = $_POST['champdemo'];
    $titre = $_POST['titre'];
    $champtitre = $_POST['champtitre'];
    $description = $_POST['description'];
    $champdescription = $_POST['champdescription'];

    xprofile_set_field_data($champdemo, $id,  $liendemo);
    xprofile_set_field_data($champdescription, $id,  $description);
    xprofile_set_field_data($champtitre, $id,  $titre);
}
if(isset($_POST['submit']))
{
    updatedemo();
    
}
?>

And here is the form:


<?php if ( bp_is_my_profile() ) { ?>
	<form method="post" action="<?php bp_displayed_user_link(); ?>">

	<?php if ( xprofile_get_field_data('25') == "" ) { ?>
		<img src="http://www.cinemacontact.com/fr/images/form-demo-01.jpg"><br>

	<?php }; if ( !xprofile_get_field_data('25') == "" ) { ?>
		<img src="http://www.cinemacontact.com/fr/images/form-demo-01-1.jpg"><br>
	<?php }; ?>

		<img src="http://www.cinemacontact.com/fr/images/form-demo-02.jpg"><br><input type="text" name="titre" size="40"><br>
		<img src="http://www.cinemacontact.com/fr/images/form-demo-03.jpg"><br><input type="text" name="liendemo" size="80"><br>
		<img src="http://www.cinemacontact.com/fr/images/form-demo-04.jpg"><br>
		<img src="http://www.cinemacontact.com/fr/images/form-demo-05.jpg"><br>
		<textarea style="width:400px; height:75px;" name="description"></textarea>
		
		<input type="hidden" name="champdemo" value="lien-4">
		<input type="hidden" name="champdescription" value="description-4">
		<input type="hidden" name="champtitre" value="titre-4">
		<input type="hidden" name="id-member" value="<?php echo bp_loggedin_user_id(); ?>"><br>
		<input type="submit" value="Envoyer" name="submit">
	</form>
	<?php }; ?></h3>

And this actually works.

Maybe I didn’t ask correctly at the beginning of the thread. All I wanted to know was:
« Oh, Martin, there is, indeed, a function to update xprofile fields: xprofile_set_field_data(), don’t need to start with edit.php file. »

🙂

Skip to toolbar