MVC Basics?

Permalink
How would I get the user assigned value of a datepicker object in another php? Do I have to include it as part of my Jquery $.post? I think I'm missing basic's here!

Do I reference it as part document.getElementById('dateInQuestion');

Or is there a SESSION approach I'm missing.

 
JohntheFish replied on at Permalink Reply
JohntheFish
As long as the value of your datepicker is attached to a form element in an add or edit, and that form element is submitted as part of a form, the place to process it is in the save method of the associated controller. Handling form submission from view gets a bit more complicated.
harpboy929 replied on at Permalink Reply
John thanks as always. Your patience and help in getting me acclimated is truly helpful.

<?php 
if (date("w") == 0) { 
    $adjuster = 6; 
} 
else { 
    $adjuster = (date("w") - 1); 
} 
$myToday = date('m/d/Y');
$myMonday = date("Y-m-d", strtotime("-" .($adjuster). " days")); 
$dttStart = Loader::helper('form/date_time');
$dttEnd = Loader::helper('form/date_time');
print $dttStart->date('check-in', $myMonday, true);
print $dttEnd->date('check-out', $myToday, true);
?>


would I need to wrap these elements some how in the above block's controller.php (listed below)

<?php
   class BasicTestBlockController extends BlockController {
      var $pobj;
      protected $btDescription = "A simple testing block for developers.";
      protected $btName = "Basic Test";
      protected $btTable = 'btBasicTest';
      protected $btInterfaceWidth = "350";
      protected $btInterfaceHeight = "300";
      public function on_page_view() {
      $textHelper = Loader::helper("text"); 
      $html = Loader::helper("html");
      $this->addHeaderItem($html->css("jquery.ui.css"));
      $this->addHeaderItem($html->javascript("jquery.ui.js"));
      }
   }

:) edit!
And if so, would I then able to reference them as $variables (all I need is the value--.validate?) or would I need to point to this-->?

If I'm completely off base could you tell me more about the save method (would I be actually pulling the variables out of the db-The block itself is never "submitted" per see)?
JohntheFish replied on at Permalink Reply
JohntheFish
It looks like you are using the C5 date picker, I don't think you need instantiate 2 objects. Your datepicker code needs to be within a form that submits somewhere, maybe back to your block controller (maybe you have left that out of the snip), or maybe to a tool associated with the block controller.
$datehelper = Loader::helper('form/date_time');
print $datehelper ->date('check-in', $myMonday, true);
print $datehelper ->date('check-out', $myToday, true);


I am not sure which jQuery and css the C5 datepicker actually needs, but you are doing the right sort of thing with on_page_view() and addHeaderItem() in your block controller.

Is the date returned directly associated with the block? (ie. do the dates map 1:1 with the block?), Or is the block the frontend interface for a whole list of dates? If it is, you may need to build a model ( a few database routines doing SQL). Or are you simply doing something with the dates and showing the result to the user?

Anyway, with any of these the dates will be available to the php processing the form as $_POST['check-in'] and as $_POST['check-out'] (you may need to use underscores rather than hyphens, not sure on that). What changes with the above questions is where you put the code to read that $_POST[ ] data. Having seen more of what you are doing, this is unlikely to the save() method of your block controller. save() is run after add or edit.

PS - the trick with code blocks on the forum is to just have 'code' or '/code' between the [ ].

PS2 - have edited my previous comment so as to not mislead anyone else reading this thread.
harpboy929 replied on at Permalink Reply
Thats the problem I think. NONE of the forms submit, anywhere - The user selects from a google table which is "listening" for clicks, and then ajax pumps the selection to the PHP for DB retrieval.

Looks like datepicker.value (or something) is gonna have to go through with my $.post ( jquery ajax )

I was my naive hope that I could simply reference the javascript datepicker from wherever in the ajax PHP and get a value, but that dosen't seem to be in the physics here.
JohntheFish replied on at Permalink Reply
JohntheFish
You may find looking through the php code for one of the games I built as add-ons helpful (or it may confuse further). Ignore the complexity of the jQuery and the actual games and popup dialogs. What may help is the way a result in a form is submitted (by ajax) and then saved in a list of results.

(our posts crossed, but I think I anticipated you)
harpboy929 replied on at Permalink Reply
I'd love that - please point it to me! I'm going to have to get extremely comfy with JSON/AJAX dataflow/passing b/c that's the meat and potatoes of my app.

Link below was very helpful:

http://www.c5tutorials.com/tutorials/ajax-ifying-your-site-part-1/...

Any others in your pocket for C5/Jquery Ajax?

Thanks again John - let me know where to send this beer.
JohntheFish replied on at Permalink Reply
JohntheFish