Skip to content

Instantly share code, notes, and snippets.

@topmask
Last active October 27, 2021 05:44
Show Gist options
  • Save topmask/74a209c0610ac8c09016d0a8790a7885 to your computer and use it in GitHub Desktop.
Save topmask/74a209c0610ac8c09016d0a8790a7885 to your computer and use it in GitHub Desktop.
Enhancing this form with PHP and WordPress magic
<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>
<?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