Uncategorized

Build a Blog in Drupal 8: Custom Contact Forms

This tutorial is part of the “Build a Blog in Drupal 8” series:

  1. Content types and Fields
  2. Adding Comments
  3. Using Views
  4. Managing Blocks
  5. Create and Manage Menus
  6. Custom Contact Forms

In the last tutorial, we added a few menus to flesh out the site navigation. Let’s now build on this by creating a few contact forms.

In Drupal 7, the Contact module is used to create basic contact forms. When a user fills them out, an email is sent to configured email addresses.

One limitation in Drupal 7 is you can’t modify the fields on the form. You can create different categories but the form stays the same.

In Drupal 8, things have changed. Instead of having a single form, you can now create different contact form types. Following in good old Drupal tradition, these contact form types are fieldable. This means you can add any custom field to them and this let’s you create proper, albeit basic forms.

So in this tutorial, we’ll create a custom contact form called “Drupal question”. This form will be similar to the standard contact form but we’ll add an extra field called “Drupal version”. This will let the user select a version of Drupal from a drop-down list.

Let’s jump right in.

Standard Contact Form

A default form called “Website feedback” is created when you install Drupal using the Standard installation profile. This form is used as the basic site-wide contact form and a link is displayed in the footer.

Fig 1.1

When the form is filled out an email is sent to a designated email address.

Custom Contact Form

As mentioned in the introduction, contact forms in Drupal 8 are now fieldable. This is great because you can create custom forms directly in core without installing extra modules.

Let’s create our “Drupal question” form.

1. Go to Structure, “Contact forms” and click on “Add contact form”.

Fig 1.0

2. Enter “Drupal question” into Label and enter in an email address into Recipients.

Fig 1.2

Once the form has been filled out, scroll to the bottom and click on Save.

3. You should’ve been redirected back to the “Contact forms” page. Now click on “Drupal question” to see the form.

Fig 1.3

You’ll notice that the form already has a few default fields.

Each contact form will have the following:

  • Sender name
  • Sender email
  • Subject
  • Message
  • Send copy to sender

Even though these are the default fields, you can disable them from the “Manage form display” page so they won’t be shown.

Add Field to Custom Contact Form

In Drupal 8, contact forms are fieldable. So let’s add a drop-down list which let’s users select a Drupal version.

Adding fields to the contact form is the same as adding one to a content type or block type. If you know how to add fields to them, you’ll know how to add them to contact forms.

1. Go to Structure, “Contact forms” and click on “Manage fields” from the Edit drop-down.

Fig 1.4

2. Click on “Add field”, then select “List (text)” from “Add a new field” and add “Drupal version” to the Label field.

Fig 1.5

Then click on “Save and continue”.

3. Enter in the following values into “Allowed values list”. Then click on “Save field settings”.

drupal-8|Drupal 8
drupal-7|Drupal 7

Fig 1.6

4. Finally, let’s make the field mandatory by checking “Required field”, then click “Save settings”.

Fig 1.7

 

Read More 3001
Read More 3002
Read More 3003
Read More 3004
Read More 3005
Read More 3006
Read More 3007
Read More 3008
Read More 3009
Read More 3010
Read More 3011
Read More 3012
Read More 3013
Read More 3014
Read More 3015
Read More 3016
Read More 3017
Read More 3018
Read More 3019
Read More 3020
Read More 3021
Read More 3022
Read More 3023
Read More 3024
Read More 3025
Read More 3026
Read More 3027
Read More 3028
Read More 3029
Read More 3030
Read More 3031
Read More 3032
Read More 3033
Read More 3034
Read More 3035
Read More 3036
Read More 3037
Read More 3038
Read More 3039
Read More 3040
Read More 3041
Read More 3042
Read More 3043
Read More 3044
Read More 3045
Read More 3046
Read More 3047
Read More 3048
Read More 3049
Read More 3050
Read More 3051
Read More 3052
Read More 3053
Read More 3054
Read More 3055
Read More 3056
Read More 3057
Read More 3058
Read More 3059
Read More 3060
Read More 3061
Read More 3062
Read More 3063
Read More 3064
Read More 3065
Read More 3066
Read More 3067
Read More 3068
Read More 3069
Read More 3070
Read More 3071
Read More 3072
Read More 3073
Read More 3074
Read More 3075
Read More 3076
Read More 3077
Read More 3078
Read More 3079
Read More 3080
Read More 3081
Read More 3082
Read More 3083
Read More 3084
Read More 3085
Read More 3086
Read More 3087
Read More 3088
Read More 3089
Read More 3090
Read More 3091
Read More 3092
Read More 3093
Read More 3094
Read More 3095
Read More 3096
Read More 3097
Read More 3098
Read More 3099
Read More 3100
Read More 3101
Read More 3102
Read More 3103
Read More 3104
Read More 3105
Read More 3106
Read More 3107
Read More 3108
Read More 3109
Read More 3110
Read More 3111
Read More 3112
Read More 3113
Read More 3114
Read More 3115
Read More 3116
Read More 3117
Read More 3118
Read More 3119
Read More 3120
Read More 3121
Read More 3122
Read More 3123
Read More 3124
Read More 3125
Read More 3126
Read More 3127
Read More 3128
Read More 3129
Read More 3130
Read More 3131
Read More 3132
Read More 3133
Read More 3134
Read More 3135
Read More 3136
Read More 3137
Read More 3138
Read More 3139
Read More 3140
Read More 3141
Read More 3142
Read More 3143
Read More 3144
Read More 3145
Read More 3146
Read More 3147
Read More 3148
Read More 3149
Read More 3150
Read More 3151
Read More 3152
Read More 3153
Read More 3154
Read More 3155
Read More 3156
Read More 3157
Read More 3158
Read More 3159
Read More 3160
Read More 3161
Read More 3162
Read More 3163
Read More 3164
Read More 3165
Read More 3166
Read More 3167
Read More 3168
Read More 3169
Read More 3170
Read More 3171
Read More 3172
Read More 3173
Read More 3174
Read More 3175
Read More 3176
Read More 3177
Read More 3178
Read More 3179
Read More 3180
Read More 3181
Read More 3182
Read More 3183
Read More 3184
Read More 3185
Read More 3186
Read More 3187
Read More 3188
Read More 3189
Read More 3190
Read More 3191
Read More 3192
Read More 3193
Read More 3194
Read More 3195
Read More 3196
Read More 3197
Read More 3198
Read More 3199
Read More 3200
Read More 3201
Read More 3202
Read More 3203
Read More 3204
Read More 3205
Read More 3206
Read More 3207
Read More 3208
Read More 3209
Read More 3210
Read More 3211
Read More 3212
Read More 3213
Read More 3214
Read More 3215
Read More 3216
Read More 3217
Read More 3218
Read More 3219
Read More 3220
Read More 3221
Read More 3222
Read More 3223
Read More 3224
Read More 3225
Read More 3226
Read More 3227
Read More 3228
Read More 3229
Read More 3230
Read More 3231
Read More 3232
Read More 3233
Read More 3234
Read More 3235
Read More 3236
Read More 3237
Read More 3238
Read More 3239
Read More 3240
Read More 3241
Read More 3242
Read More 3243
Read More 3244
Read More 3245
Read More 3246
Read More 3247
Read More 3248
Read More 3249
Read More 3250
Read More 3251
Read More 3252
Read More 3253
Read More 3254
Read More 3255
Read More 3256
Read More 3257
Read More 3258
Read More 3259
Read More 3260
Read More 3261
Read More 3262
Read More 3263
Read More 3264
Read More 3265
Read More 3266
Read More 3267
Read More 3268
Read More 3269
Read More 3270
Read More 3271
Read More 3272
Read More 3273
Read More 3274
Read More 3275
Read More 3276
Read More 3277
Read More 3278
Read More 3279
Read More 3280
Read More 3281
Read More 3282
Read More 3283
Read More 3284
Read More 3285
Read More 3286
Read More 3287
Read More 3288
Read More 3289
Read More 3290
Read More 3291
Read More 3292
Read More 3293
Read More 3294
Read More 3295
Read More 3296
Read More 3297
Read More 3298
Read More 3299
Read More 3300
Read More 3301
Read More 3302
Read More 3303
Read More 3304
Read More 3305
Read More 3306
Read More 3307
Read More 3308
Read More 3309
Read More 3310
Read More 3311
Read More 3312
Read More 3313
Read More 3314
Read More 3315
Read More 3316
Read More 3317
Read More 3318
Read More 3319
Read More 3320
Read More 3321
Read More 3322
Read More 3323
Read More 3324
Read More 3325
Read More 3326
Read More 3327
Read More 3328
Read More 3329
Read More 3330
Read More 3331
Read More 3332
Read More 3333
Read More 3334
Read More 3335
Read More 3336
Read More 3337
Read More 3338
Read More 3339
Read More 3340
Read More 3341
Read More 3342
Read More 3343
Read More 3344
Read More 3345
Read More 3346
Read More 3347
Read More 3348
Read More 3349
Read More 3350
Read More 3351
Read More 3352
Read More 3353
Read More 3354
Read More 3355
Read More 3356
Read More 3357
Read More 3358
Read More 3359
Read More 3360
Read More 3361
Read More 3362
Read More 3363
Read More 3364
Read More 3365
Read More 3366
Read More 3367
Read More 3368
Read More 3369
Read More 3370
Read More 3371
Read More 3372
Read More 3373
Read More 3374
Read More 3375
Read More 3376
Read More 3377
Read More 3378
Read More 3379
Read More 3380
Read More 3381
Read More 3382
Read More 3383
Read More 3384
Read More 3385
Read More 3386
Read More 3387
Read More 3388
Read More 3389
Read More 3390
Read More 3391
Read More 3392
Read More 3393
Read More 3394
Read More 3395
Read More 3396
Read More 3397
Read More 3398
Read More 3399
Read More 3400
Read More 3401
Read More 3402
Read More 3403
Read More 3404
Read More 3405
Read More 3406
Read More 3407
Read More 3408
Read More 3409
Read More 3410
Read More 3411
Read More 3412
Read More 3413
Read More 3414
Read More 3415
Read More 3416
Read More 3417
Read More 3418
Read More 3419
Read More 3420
Read More 3421
Read More 3422
Read More 3423
Read More 3424
Read More 3425
Read More 3426
Read More 3427
Read More 3428
Read More 3429
Read More 3430
Read More 3431
Read More 3432
Read More 3433
Read More 3434
Read More 3435
Read More 3436
Read More 3437
Read More 3438
Read More 3439
Read More 3440
Read More 3441
Read More 3442
Read More 3443
Read More 3444
Read More 3445
Read More 3446
Read More 3447
Read More 3448
Read More 3449
Read More 3450
Read More 3451
Read More 3452
Read More 3453
Read More 3454
Read More 3455
Read More 3456
Read More 3457
Read More 3458
Read More 3459
Read More 3460
Read More 3461
Read More 3462
Read More 3463
Read More 3464
Read More 3465
Read More 3466
Read More 3467
Read More 3468
Read More 3469
Read More 3470
Read More 3471
Read More 3472
Read More 3473
Read More 3474
Read More 3475
Read More 3476
Read More 3477
Read More 3478
Read More 3479
Read More 3480
Read More 3481
Read More 3482
Read More 3483
Read More 3484
Read More 3485
Read More 3486
Read More 3487
Read More 3488
Read More 3489
Read More 3490
Read More 3491
Read More 3492
Read More 3493
Read More 3494
Read More 3495
Read More 3496
Read More 3497
Read More 3498
Read More 3499
Read More 3500

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button