• Resolved jadeivee

    (@jadeivee)


    HI again,

    Is there an easy way to add a custom field just beside the name field? I am aiming to a select box that hold’s the value Mr. Mrs. or Miss.

    Hope this is an east tweak.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • NateWr

    (@natewr)

    Hi @jadeivee,

    To accomplish this, you’d need to write some custom PHP code. Are you comfortable working with WordPress’s actions and filters system? If so, you’ll find a quick rundown of how to create and save custom fields.

    I do offer a Custom Fields addon, but it won’t get you two fields directly side-by-side in the manner that you want. It would add a new dropdown field on it’s own row.

    Thread Starter jadeivee

    (@jadeivee)

    Hi @natewr,

    Thanks for that. I was able to create the custom fields to the contact array but I am not sure how to position it as the first field in the group – that is before the name field. I’m thinking, I could just use CSS to adjust the width of the new field I created and the name field so that they will appear next to each other.

    Here is my code so far: https://gist.github.com/jadebermas/f66d5b10cefdd5224c0135ba5dea85d3

    Thanks for the great support as always.

    NateWr

    (@natewr)

    Nice! Looks like you’re just about there. I left a code suggestion on your Gist.

    Thread Starter jadeivee

    (@jadeivee)

    Thanks, that was very helpful.

    I am now stuck on how to save the field correctly. I am not sure if it is okay to bypass its validation since it is not really a required field. Would you mind giving me a bit of a guide? I tried going through the step 2 on the link you have provided on your first reply but I can’t seem to figure it out.

    NateWr

    (@natewr)

    Can you show your code somewhere?

    You will need to hook in to the validation routine to sanitize and store the field in the booking object. For example this is done to the phone and message fields even though they’re not required:

    https://github.com/NateWr/restaurant-reservations/blob/master/includes/Booking.class.php#L410

    This way you can attach your title data to the $booking object so that when you hook into rtb_insert_booking_metadata the appropriate value is waiting for you in $this.

    If you can put up a Gist with your code I’ll take a quick look.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to add a custom selectbox field before the name’ is closed to new replies.