Last active
October 27, 2021 05:44
-
-
Save topmask/74a209c0610ac8c09016d0a8790a7885 to your computer and use it in GitHub Desktop.
Enhancing this form with PHP and WordPress magic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="#" method="POST" class="comment-form"> | |
<?php wp_nonce_field( 'faire-don', 'cagnotte-verif' ); ?> | |
<div> | |
<label for="don"><?php _e( 'Amount donation' ); ?></label> | |
<input id="don" type="number" name="don" value="5" /> | |
</div> | |
<input id="submit" type="submit" name="cagnote-don-envoi" id="submit" class="submit" value="<?php esc_attr_e( 'Submit', 'msk' ); ?>" /> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php function traitement_formulaire_don_cagnotte() { | |
if ( ! isset( $_POST['cagnote-don-envoi'] ) || ! isset( $_POST['cagnotte-verif'] ) ) { | |
return; | |
} | |
if ( ! wp_verify_nonce( $_POST['cagnotte-verif'], 'faire-don' ) ) { | |
return; | |
} | |
// Process the form... | |
} | |
add_action( 'template_redirect', 'traitement_formulaire_don_cagnotte' ); | |
#Let’s focus on the processing logic of the form: we leave the template to go to the functions.php file in order to process the data received. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment