Insert date

Cupara

Well-known member
On one of my blocks I need to insert a date that the member adds when making a new event. The problem I run into is that it keeps wanting to enter no date and no id. As well I keep getting this error now since I started using Zend_Date:
Server Error

Object of class Zend_Date could not be converted to int
  1. XenForo_Application::handlePhpError()
  2. intval() in XenForo/DataWriter.php at line 725
  3. XenForo_DataWriter->_castValueToType() in XenForo/DataWriter.php at line 663
  4. XenForo_DataWriter->_isFieldValueValid() in XenForo/DataWriter.php at line 585
  5. XenForo_DataWriter->set() in xPortal/ControllerAdmin/xPortal/Events.php at line 108
  6. xPortal_ControllerAdmin_xPortal_Events->actionSave() in XenForo/FrontController.php at line 310
  7. XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
  8. XenForo_FrontController->run() in /home/xen/public_html/admin.php at line 13
This is the save process page:
PHP:
$this->_assertPostOnly();

        $dwInput = $this->_input->filter(array(
            'eid' => XenForo_Input::UINT,
            'event_date' => XenForo_Input::UINT,
            'event_month' => XenForo_Input::NUM,
            'event_day' => XenForo_Input::NUM,
            'event_year' => XenForo_Input::NUM,
            'event_hour' => XenForo_Input::NUM,
            'event_minute' => XenForo_Input::NUM,
            'event_message' => XenForo_Input::STRING,
            'event_username' => XenForo_Input::STRING
        ));

        $datearray = array('year' => $dwInput['event_year'],
                       'month' => $dwInput['event_month'],
                       'day' => $dwInput['event_day'],
                       'hour' => $dwInput['event_hour'],
                       'minute' => $dwInput['event_minute'],
                       'second' => 0);
        $date = new Zend_Date($datearray);

        $dw = XenForo_DataWriter::create('xPortal_DataWriter_Events');
        if ($dwInput['eid'])
            $dw->setExistingData($dwInput['eid']);
        
        $dw->set('eid', $dwInput['eid']);
        $dw->set('event_date', $date);
        $dw->set('event_message', $dwInput['event_message']);
        $dw->set('event_username', $dwInput['event_username']);
        $dw->save();
        
        $redirectType = ($dwInput['eid'] ?
            XenForo_ControllerResponse_Redirect::RESOURCE_UPDATED :
            XenForo_ControllerResponse_Redirect::RESOURCE_CREATED);
            
        return $this->responseRedirect(
            $redirectType,
            XenForo_Link::buildAdminLink('xportal/events')
        );
    }
Here is my page with the fields:
HTML:
<xen:title>xPortal Event :: Add</xen:title>

<div class="selection">
    <h2 class="heading">{xen:phrase xportal_adding_an_event}</h2>
    <div class="sectionContent secondaryContent">

        <xen:form action="{xen:adminlink 'xportal/events/save'}">
                    <xen:textboxunit name="event_message" value="" label="{xen:phrase xportal_event_message}">
                        <xen:explain>{xen:phrase xportal_event_message_explain}</xen:explain>
                        </xen:textboxunit>
                    <xen:controlunit label="{xen:phrase xportal_event_date}:">
                        <xen:select name="event_month" value="" inputclass="autoSize">
                            <xen:option value=""></xen:option>
                            <xen:option value="1">{xen:phrase month_1}</xen:option>
                            <xen:option value="2">{xen:phrase month_2}</xen:option>
                            <xen:option value="3">{xen:phrase month_3}</xen:option>
                            <xen:option value="4">{xen:phrase month_4}</xen:option>
                            <xen:option value="5">{xen:phrase month_5}</xen:option>
                            <xen:option value="6">{xen:phrase month_6}</xen:option>
                            <xen:option value="7">{xen:phrase month_7}</xen:option>
                            <xen:option value="8">{xen:phrase month_8}</xen:option>
                            <xen:option value="9">{xen:phrase month_9}</xen:option>
                            <xen:option value="10">{xen:phrase month_10}</xen:option>
                            <xen:option value="11">{xen:phrase month_11}</xen:option>
                            <xen:option value="12">{xen:phrase month_12}</xen:option>
                        </xen:select>
                        <xen:textbox name="event_day" value="" size="2" inputclass="autoSize" placeholder="{xen:phrase day}" />
                        <xen:textbox name="event_year" value="" size="4" inputclass="autoSize" placeholder="{xen:phrase year}" /> at 
                        <xen:textbox name="event_hour" value="" size="2" inputclass="autoSize" placeholder="{xen:phrase xportal_hour}" />
                        <xen:textbox name="event_minute" value="" size="2" inputclass="autoSize" placeholder="{xen:phrase xportal_minute}" />
                    </xen:controlunit>
                    <xen:textboxunit name="event_username" value="" label="{xen:phrase xportal_event_username}:">
                        <xen:explain>{xen:phrase xportal_event_username_explain}</xen:explain>
                    </xen:textboxunit>
        <xen:submitunit save="Save Event">
            
        </xen:submitunit>
        </xen:form>
    </div>
<xen:include template="xportal_footer" />
</div>

<xen:require css="filter_list.css" />
<xen:require js="js/xenforo/filter_list.js" />
I know the input for username should grab the name of the person logged in but I have not quite figured out how to get that atm, I'll worry about that after my insert issue is resolved.
Thanks for any and all help
 
Same answer as always: start debugging:P

Have you checked what Zend_Date toString returns???
Error says that it's no integerer (as it it requested by the dw) so check Zend_Date Help and check how you can get the needed value^^
 
Same answer as always: start debugging:p

Have you checked what Zend_Date toString returns???
Error says that it's no integerer (as it it requested by the dw) so check Zend_Date Help and check how you can get the needed value^^
I figured out how to mktime() work but now to make 'new Zend_Date()' to work.
 
Top Bottom