formulaire dans un widget

Par Paul Bression, il y a 9 ans


Bonjour,

J'aimerais passer un formulaire dans un widget mais je ne sais pas dutout comment faire car il y a du php et du html...

Je voudrais savoir si vous pouriez m'expliquer les démarches a suivres pour passer mon formulaire dans mon widget

Mon formulaire est

<?php if ( ! defined( 'ABSPATH' ) ) { exit; } $message = ''; if( is_single() && get_post_type() == 'opalestate_property' ){ $message = sprintf(__('Hi, I am interested in %s (Property ID: %s)'), get_the_title() , get_the_ID() ); } if( $post_id == 0 && !isset($author_id) ){ global $post; $author_id = $post->post_author; } ?> <?php if ( ! empty( $email ) ) : ?> <div class="agent-contact-form-container"> <h3><?php echo __( 'Contact Form', 'opalestate' ); ?></h3> <div class="box-content agent-contact-form"> <form method="post" action="" class="opalestate-contact-form"> <?php do_action('opalestate_agent_contact_form_before'); ?> <input type="hidden" name="post_id" value="<?php the_ID(); ?>"> <input type="hidden" name="agent_id" value="<?php echo $post_id; ?>"> <?php if( isset($author_id) ) : ?> <input type="hidden" name="author_id" value="<?php echo $author_id; ?>"> <?php endif ; ?> <div class="form-group"> <input class="form-control" name="name" type="text" placeholder="<?php echo __( 'Name', 'opalestate' ); ?>" required="required"> </div><!-- /.form-group --> <div class="form-group"> <input class="form-control" name="email" type="email" placeholder="<?php echo __( 'E-mail', 'opalestate' ); ?>" required="required"> </div><!-- /.form-group --> <div class="form-group"> <textarea class="form-control" name="message" placeholder="<?php echo __( 'Message', 'opalestate' ); ?>" style="overflow: hidden; word-wrap: break-word; height: 68px;"><?php echo $message ; ?></textarea> </div><!-- /.form-group --> <?php do_action('opalestate_agent_contact_form_after'); ?> <button class="button btn btn-primary btn-3d" type="submit" name="contact-form"><?php echo __( 'Send message', 'opalestate' ); ?></button> </form> </div><!-- /.agent-contact-form --> </div><!-- /.agent-contact--> <?php endif; ?>

Mon widget ( rien de compliqué )

<?php add_action( 'widgets_init', function(){ register_widget( 'My_Widget' ); }); class My_Widget extends WP_Widget { /** * Sets up the widgets name etc */ public function __construct() { $widget_ops = array( 'classname' => 'Contact', 'description' => 'formulaire de contact ', ); parent::__construct( 'my_widget', 'Contact', $widget_ops ); } /** * Outputs the content of the widget * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { // outputs the content of the widget } /** * Outputs the options form on admin * * @param array $instance The widget options */ public function form( $instance ) { // outputs the options form on admin } /** * Processing widget options on save * * @param array $new_instance The new options * @param array $old_instance The previous options */ public function update( $new_instance, $old_instance ) { // processes widget options to be saved } } ?>

Merci d'avance de votre aide ! ;)

1 réponse

JiiB, il y a 9 ans

Etant donné que ton formulaire est basique, pourquoi tu n'utilises pas un plugin de formulaire de type (contact form7 ou gravityForm) que tu pourrais utiliser en tant que widget?!