Custom php code in Chronoforms

Mikeymore 25 Apr, 2013
Hi all,

I am building on a pregnancy form. It calculates the day of birth approximately.
I have the following custom php code on load:

* show html
* custum code:

<?php
echo "<p>Als je zwanger bent, wil je waarschijnlijk graag weten wanneer je bent uitgerekend.
Beantwoord de volgende twee vragen om een zo nauwkeurig mogelijke schatting maken van je uitgerekende datum.<p>"."<br/>";

echo "Kies de eerste dag van uw laatste menstruatie:"."<br/><br/>";
  
function date_dropdown($year_limit = 0){
        $html_output = '    <div id="date_select" >'."\n";
        $html_output .= '        <label for="date_day">Datum:</label>'."\n";

        /*dagen*/
        $html_output .= '           <select name="date_day" id="day_select">'."\n";
            for ($day = 1; $day <= 31; $day++) {
                $html_output .= '               <option>' . $day . '</option>'."\n";
            }
        $html_output .= '           </select>'."\n";

        /*maanden*/
        $html_output .= '           <select name="date_month" id="month_select" >'."\n";
        $months = array("", "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December");
            for ($month = 1; $month <= 12; $month++) {
                $html_output .= '               <option value="' . $month . '">' . $months[$month] . '</option>'."\n";
            }
        $html_output .= '           </select>'."\n";

        /*jaren*/
        $html_output .= '           <select name="date_year" id="year_select">'."\n";
            for ($year = 2012; $year <= (date("Y") - $year_limit); $year++) {
                $html_output .= '               <option>' . $year . '</option>'."\n";
            }
        $html_output .= '           </select>'."\n";

        $html_output .= '   </div>'."\n";
    return $html_output;
}

echo date_dropdown()."<br/><br/>";

echo "<p>Hoe veel dagen duurt je gemiddelde cyclus?:</p>"."<br/>";

function cyclus_dropdown(){
        /*cyclus*/
        $html_output .= '           <select name="cyclus" id="cyclus">'."\n";
            for ($cyclus = 20; $cyclus <= 45; $cyclus++) {
                $html_output .= '               <option>' . $cyclus . '</option>'."\n";
            }
        $html_output .= '           </select>'."\n"; 
    return $html_output;
}
echo cyclus_dropdown();

?>


The mode: on view
And on submit (controller):

<?php

$input = $_POST['date_day'] . '-' . $_POST['date_month'] . '-' . $_POST['date_year'];
echo date("d-m-Y", strtotime($input . " + 245 DAYS"));

?>


What I want is get the date filled in, and calculate 245 days + cyclus (for example 20) and then output the date of birth. So 23 april 2013 with a cylcus of 20 must be output 20 januar 2014!

Now it gives the value of 01-01-1970, so there is something wrong. I guess the code is correct (?) and I do sth. wrong in chronoforms?

Anybody an idea?
Thanks already!
GreyHead 25 Apr, 2013
Hi Mikeymore,

You aren't using ChronoForms here except as a holder for your PHP so my best guess is that there is a bug in your code. Try adding a Debugger action to the On Submit event. That will show you what is being submitted.

Bob
This topic is locked and no more replies can be posted.