Support » Plugin: GiveWP - Donation Plugin and Fundraising Platform » Two (or more) module in page

  • Resolved marcorm69


    Hi all.

    I have insert a two donation modules in my home page and add a custom field (upload file) on both module.
    All work fine except the upload file on second module!
    On submit the field check work fine but the file is not upload in my site.
    This is the code from save custom fields.
    The $_FILES[‘fileToUpload’][‘name’] is empty for second module but work for the first module

    function give_mamafrica_donations_save_custom_fields( $payment_id ) {
    	if (!empty($_FILES['fileToUpload']['name'])) {
    		$timestamp = time(); 
    		$userfile_name = $timestamp . "-" . $_FILES['fileToUpload']['name'];
     	    //$message = wp_strip_all_tags( $_FILES['fileToUpload']['name'], true );
    		$message = wp_strip_all_tags($userfile_name, true );
    		give_update_payment_meta( $payment_id, 'fileToUpload', $message );	
    		//percorso della cartella dove mettere i file caricati dagli utenti
    		$uploaddir =  get_stylesheet_directory() . '/offline_donation/';
    		//Recupero il percorso temporaneo del file
    		$userfile_tmp = $_FILES['fileToUpload']['tmp_name'];
    		//recupero il nome originale del file caricato
    		//copio il file dalla sua posizione temporanea alla mia cartella upload
    		if (move_uploaded_file($userfile_tmp, $uploaddir . $userfile_name)) {
    		//Se l'operazione è andata a buon fine...
    			echo 'File inviato con successo.';
    			//Se l'operazione è fallta...
    			echo 'Upload NON valido!'; 
    add_action( 'give_insert_payment', 'give_mamafrica_donations_save_custom_fields' );

    Can you help me?


    • This topic was modified 9 months ago by marcorm69.
    • This topic was modified 9 months ago by Yui. Reason: please use CODE button for code formatting

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Support Rick Alday


    Hi @marcorm69

    We cannot provide support for custom code on your website, only the code that we create and distribute. However, I think the problem is that you’re probably using the same custom field name for both forms and using the same filter give_insert_payment for both. So all the code is executing only on the first form.

    One way around this is to use different field names for each form, and trigger different functions for each form using conditionals.

    Something like:

    if ($form_id= 123) {
    function give_mamafrica_donations_save_custom_fields( $payment_id ) {....}
    add_action( 'give_insert_payment', 'give_mamafrica_donations_save_custom_fields' );
    if ($form_id=456) {
    function give_mamafrica_donations_save_custom_fields_2( $payment_id ) {....}
    add_action( 'give_insert_payment', 'give_mamafrica_donations_save_custom_fields_2' );

    Hopefully that will give you some rails to run on.

Viewing 1 replies (of 1 total)
  • The topic ‘Two (or more) module in page’ is closed to new replies.