Form block default value for Select dropdown

Permalink
I have a form block in my page that I have modified to have placeholders instead of labels on input fields. However this does not work for the Select inputs. How in the Form Block can I set a default value for my Select dropdowns? It can just be the 1st option if easier. Would like to say something like "Select your state" or whatever. I have 3 of them in the form that are different.

Anyone been successful at this? I am using v5.7.5

Thanks in advance!

 
ramonleenders replied on at Permalink Reply
ramonleenders
Just set the first option/value to the option you want as "Placeholder".
GrizzlyAdams replied on at Permalink Reply 1 Attachment
There is no option to do that though (screenshot attached)

It just shows (----) in the dropdown
ramonleenders replied on at Permalink Best Answer Reply
ramonleenders
Ah, true. Since you are on 5.7.5, do the following.

- Go to the /concrete/blocks/form directory;
- Copy the view.php file from there;
- Go to /application/blocks directory;
- Create a directory /form (if it does not exist yet);
- Paste the view.php file into this directory (alternatively create a template, but this is just for showcasing the example);
- Search for the following code

//Make type names common-sensical
if ($questionRow['inputType'] == 'text') {
      $question['type'] = 'textarea';
   } else if ($questionRow['inputType'] == 'field') {
      $question['type'] = 'text';
   } else {
      $question['type'] = $questionRow['inputType'];
   }


Replace that with this code:

//Make type names common-sensical
   if ($questionRow['inputType'] == 'text') {
      $question['type'] = 'textarea';
   } else if ($questionRow['inputType'] == 'field') {
      $question['type'] = 'text';
   } else if ($questionRow['inputType'] == 'select') {
      $question['input'] = str_replace('----</option>', '-- Your placeholder here --', $question['input']);
   } else {
      $question['type'] = $questionRow['inputType'];
   }


Of course, I renamed it to "Your placeholder here" and you can put any text you want there. You could also use the title/name of the field in some way, but at least this is a working example on how to change it.

For creating block templates, look here:

https://documentation.concrete5.org/developers/working-with-blocks/w...

This example is for the "Form" block only on 5.7.x, watch that if you upgrade to 8.x, the Form block changed into "Form Legacy" and may have different view contents.
GrizzlyAdams replied on at Permalink Reply
PERFECT! That was easy as pie ;)

Was really easy to add the question as the placeholder as well.
heinrichundgretchen replied on at Permalink Reply
heinrichundgretchen
Hi there -
we have our site running under 8.1.0 and encounter the same problem. And, as you wrote, changing the form block's view.php does not have any effect. Do you happen to have any idea on what to do now to get rid of the ** none option and just have the first entry in the select menu?

Help would be very appreciated!
ramonleenders replied on at Permalink Reply
ramonleenders
You are probably using the "Express Form" instead of "Legacy Form" (the "Form" block type as known in 5.7 isn't default for 8.x anymore). Perhaps someone else can give you a good solution for the Express form, I haven't looked into that (yet) myself.