【Salon Booking System】can't be empty bug fix

When I introduced the Salon Booking System in a project I was involved in before, I encountered a bug when applying for a guest.


I did not know the solution even if I contacted the plugin forum etc., but since I had time, I analyzed the source and confirmed the workaround, so I will publish it.

Salon Booking System v 7.6.4

What happened in Salon Booking System

It was a bug that the required item was always "Can't be empty" when applying for a guest.

There are two conditions for an event to occur.

  • Guest application
  • There are required fields

I get an error even though I have filled in the required fields.

can't be empty bug
can't be empty bug

How to bug fix

The target file is

wp-content/plugins/salon-booking-system/views/shortcode/salon_details.php

Here is the source before the change

<?php
foreach ($fields as $key => $field):
?>
<?php
 $value = !$bb->get($key) &amp;&amp; null !== $field['default_value'] ? $field['default_value'] : $bb->get($key) ;
 $type = $field['type'];
 $width = $field['width'];
?>

Here is the modified source. After looping with foreach, I'm overwriting the variable key with the key stored in the field array.

foreach ($fields as $key => $field):
?>
<?php
 $key = $field['key']; //Add this line
 $value = !$bb->get($key) &amp;&amp; null !== $field['default_value'] ? $field['default_value'] : $bb->get($key) ;
 $type = $field['type'];
 $width = $field['width'];
?>

Since the corresponding source is conditional branching according to the size, there are multiple corrections. There are three places that need to be modified: near line 181, near line 253, and near line 329.

Cause of the bug

This event will occur only in the "required items" when you try to apply as a guest. It does not occur for logged-in members. So, let's compare the screens for guests and members.

Required items for guests

can't be empty bug fix1

Required items for members

can't be empty bug fix2

Of note is the name parameter in the bottom item.


In Salon Booking System, when you add an item at the time of application from the management screen, the system will automatically issue an ID. Labels and input values ​​are managed for each ID.

However, in the case of "Application as a guest" on the left, the ID is not referenced correctly and the ID is assigned from 0.

This is the cause of the bug. Let's go back to the source of the screen display.

<?php
foreach ($fields as $key => $field):
?>
<?php
 $value = !$bb->get($key) &amp;&amp; null !== $field['default_value'] ? $field['default_value'] : $bb->get($key) ;
 $type = $field['type'];
 $width = $field['width'];
?>
-----------中略------------
$additional_opts = array(
 'sln[' . $key . ']', $value,
 array('required' => $field->isRequiredNotHidden())
);
[php]</pre>
<!-- /wp:preformatted -->

<!-- wp:paragraph -->
<p id="tw-target-text">The value of the variable key is set in the array of sln. Since this is displayed on the screen as it is, the value of this variable key should be stored correctly.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p id="tw-target-text">This variable key is obtained from the variable $ fields in foreach, which is the cause of the bug.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p id="tw-target-text">The correct ID can be obtained from the field, so if you overwrite the value of the variable key with the key obtained from the array of field, it will work without problems.</p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">[php title='salon_details.php']
foreach ($fields as $key => $field):
?>
<?php
 $key = $field['key']; //Add this line
 $value = !$bb->get($key) &amp;&amp; null !== $field['default_value'] ? $field['default_value'] : $bb->get($key) ;
 $type = $field['type'];
 $width = $field['width'];
?>

コメントを残す