Help me reverse the behavior of this current php code

I am modifying someone else’s code to do this website and I am not sure how to do this correctly in html5 and php.

This is how it currently is.
[php]/*------------------------------------------------------------------
Begin to find start/end times

  NOTE: if s_date_time_opts is false we are editing all events and 
        there will not be any data to get 
-------------------------------------------------------------------*/ 

if( $s_date_time_opts )
{
if( request_var(‘calAllDay’, ‘’) == “ON” )
{
$event_start_date = 0;
$event_end_date = 0;
$event_data[‘event_all_day’] = 1;
$event_data[‘event_day’] = sprintf(’%2d-%2d-%4d’, $date[‘day’], $date[‘month_no’], $date[‘year’]);
$sort_timestamp = gmmktime( 0,0,0,$date[‘month_no’], $date[‘day’], $date[‘year’]);
}
else
{
$start_hr = request_var(‘calHr’, 0);
$start_mn = request_var(‘calMn’, 0);
$event_start_date = gmmktime($start_hr, $start_mn, 0, $date[‘month_no’], $date[‘day’], $date[‘year’] ) - $user->timezone - $user->dst;
$sort_timestamp = $event_start_date;
$end_m = request_var(‘calMEnd’, 0);
$end_d = request_var(‘calDEnd’, 0);
$end_y = request_var(‘calYEnd’, 0);
$end_hr = request_var(‘calHrEnd’, 0);
$end_mn = request_var(‘calMnEnd’, 0);
$event_end_date = gmmktime($end_hr, $end_mn, 0, $end_m, $end_d, $end_y ) - $user->timezone - $user->dst;
$event_data[‘event_all_day’] = 0;
$event_data[‘event_day’] = ‘’;

// validate start and end times
if( $event_end_date < $event_start_date )
{
$error[] = $user->lang[‘NEGATIVE_LENGTH_EVENT’];
}
else if( $event_end_date == $event_start_date )
{
$error[] = $user->lang[‘ZERO_LENGTH_EVENT’];
}
}
$event_data[‘event_start_time’] = $event_start_date;
$event_data[‘event_end_time’] = $event_end_date;
$event_all_day = $event_data[‘event_all_day’];
$event_day = $event_data[‘event_day’];
}
/------------------------------------------------------------------
End start/end times
-------------------------------------------------------------------
/ [/php]
and an input field in the same php file
[php]$all_day_check = “”; [/php]
some javascript in the html file

function toggle_all_day_event() { if( document.postform.calAllDay.checked ) { document.postform.calMEnd.disabled=true; document.postform.calDEnd.disabled=true; document.postform.calYEnd.disabled=true; document.postform.calHr.disabled=true; document.postform.calMn.disabled=true; document.postform.calHrEnd.disabled=true; document.postform.calMnEnd.disabled=true; } else { document.postform.calMEnd.disabled=false; document.postform.calDEnd.disabled=false; document.postform.calYEnd.disabled=false; document.postform.calHr.disabled=false; document.postform.calMn.disabled=false; document.postform.calHrEnd.disabled=false; document.postform.calMnEnd.disabled=false; } }
and some html further down in the html file

[code]


All Day Event:

{ALL_DAY_CHECK}

[/code]

First off I would like the All Day Event checkbox currently on the page to be hidden and unchecked by default, or baring that unchecked and the disabled fields to be enabled and if checked later to disable the fields.

I thought I might be able to initialize the calAllDay variable earlier in the php file with this
[php]// Intialize Calendar All Day Event to Off
$calAllDay = ‘OFF’; [/php]
and change the input checkbox to this

[php]$all_day_check = “”;
[/php]
but the behavior of this sets the checkbox to unchecked (like I could live with) but the disabled fields in the form are still disabled untill I check the checkbox and then uncheck it again. I want the fields to be enabled on load.

first off, ‘calAllDay’ is a field name, not a variable name, so you trying to initialize it would not work that way. besides, it gets it from the html so that’s really where you should start anyway.

this would make the checkbox hidden, and unchecked.

[php]$all_day_check = “”;[/php]

change hidden back to checkbox to show it but have it start off unchecked still.

[php]$all_day_check = “”;[/php]

the key part here is removing ‘checked=“checked”’. it’s actually all html that is the issue not php, but since it’s so intermingled I understand you not recognizing that.

That second option of yours where the checkbox is on the webpage and being unchecked is what I tried last. See very bottom php field in my first post.

and change the input checkbox to this

[php]$all_day_check = “”;
[/php]

but the behavior of this sets the checkbox to unchecked (like I could live with) but the disabled fields in the form are still disabled untill I check the checkbox and then uncheck it again. I want the fields to be enabled on load.

Unfortunately this give it a very weird behavior even though it is unchecked, the other fields are still disable until I check the checkbox once and then uncheck it back to its original state and then the fields finally become enabled.

The end result that I would like to see is:
on page load the fields are enabled, the check box is unchecked. If the checkbox is checked after the page was loaded the fields become disabled.

Sponsor our Newsletter | Privacy Policy | Terms of Service