Submit Your Article Forum Rules

Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24

Thread: Help Needed with PHP Logic

  1. #21
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,785
    And to add to the ruckus, we throw in the accessibility rule that says any event for the mouse should also be mapped to the keyboard. So now you have to study accessibility as it relates to form controls. This is what I mean when I tell people their pages need to be valid and accessible. It's a pain, but once you learn how to do it, it just falls into place with everything else.

  2. #22
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,785
    I'm still more in favor of a client based approach, since so few clients are not JS disabled. It would only need a simple PHP table for the rates, and they could be generated right into the form, making AJAX unnecessary. The script would do the calculation every time a field changed, then submit would catch it all. No calculations on the server, whatever. Make use of the the client CPU whenever you can. This is one case where you can.

  3. The following user agrees with weegillis:
  4. #23
    WebProWorld MVP Clicken's Avatar
    Join Date
    Jul 2004
    Posts
    327
    Quote Originally Posted by the Enlightened One
    It would only need a simple PHP table for the rates, and they could be generated right into the form,
    LOL, simple php table in the form... that's rich WG! <tears of laughter>

    The framework is designed to make such a task 'simple'... But I am having a very difficult time with this simple task.

    See, the problem is that the jobClass table and the serviceItem table are not with-in the same 'Class' of the ServiceRequest form. Nor do the two pre-populated tables have a relation to the serviceRequest table which holds the user input.

    Forwhatever reason, I can pull information from those other tables into the Request form but only through the use of CHtml::helper classes which consist of the dropDownBoxes and listData and such. Those are appropriate for form inputs but not for informational text.

    The DOC reference for listData used in this listBox said to use query however after seeking help on their forum it was findAllbySql with the CONCAT which made it work. :eyeroll:
    Code:
    <div id="ServiceRequest_selection">
    
    <?php echo CHtml::activeListBox($ServiceRequest, 'selection',
    CHtml::listData(ServiceItem::model()->findAllbySql(
                    'SELECT itemId, CONCAT(itemId, ". ", itemName) as listBoxData FROM serviceItem'),'itemId', 'listBoxData'), array('empty'=>'shift-key select multiple','prompt'=>'Select All that Apply', 'multiple'=>'multiple','style'=>'width:auto; height:138px;' )); ?>
    
    </div><!-- eof  ServiceRequest_selection -->
    When I try to call info from those other tables using a db query, I get errors such as unassigned variables and such or just the simple text of 'Array' on the page which is what this code produces...
    Code:
    <?php echo $data = Yii::app()->db->createCommand()
                    ->select('classId, CONCAT(classId, " ", className, " ", hrRate) as classRates')
                    ->from('jobClass')
                    ->queryAll();
            $res = array();
            foreach ($data as $row) {
                $res[$row['classId']] = $row['classRates'];
            }
            return $res;
    ?>
    The documentation and other pages offer explanations of how to use the getter and setter functions to assign variables of those other tables which would be usable from anywhere in the application but I keep trying and fail.

    For the classRates, I have resorted to setting application-level parameters in the config file that can be accessed using...
    Code:
    Yii::app()->params['paramName']
    I just had to see a working result after all of my failures!

    But I will keep trying to use the setter and getter methods so that the serviceItems with the timeEstimate can be pulled in from the table, for informational and manipulating purposes. I will ask for help with that on the Yii forum...

    The input received in this thread is greatly appreciated, it has helped to guide my steps and evaluate options. I'll be back, hopefully with working getter and setter methods!

  5. #24
    WebProWorld MVP Clicken's Avatar
    Join Date
    Jul 2004
    Posts
    327
    Yii-Haaaa!?!

    Report: I need to learn more before I can do things as I first envisioned. There were also problems with the dropDownList; If I selected 3 & 7 it would select all numbers between as well. I started over, ... one db table for input, and changed to the checkBoxList. simple. yeah, well...

    A validation error message for the item selection field would display, even though on screen the boxes were showing as checked.

    The form selections wouldn't pass to the widget's gridView, for visitor viewing. With AJAX vaidation enabled, the error said that the selected items were an array and the gridView was expecting a string. I need to ask about that on the yii forum.

    I do not need the gridView really, it is just how it is initially set up. Now it is set to refresh with a message, like the contact form. It is a visitor form, so there's no need to view and update. The gridView error has shed some light though.

    With the selection field set as a required field then the form doesn't work. Without that requirement, the controller will put info into the db. <YEAH> But, the itemId gets posted to the db table and not the whole concatenated string that is used to poulate the checkBoxList.

    Anyway, I just wanted to report that I haven't given up, I am just slow and running into lots of errors.

    I am also wondering,... Will this work for the display table calculations?
    Code:
    <form id="estimate-form" action="/.../Estimate/create" method="post">
    
    <div id="estimate-form_es_" class="errorSummary" style="display:none">
    	<p>Please fix the following input errors:</p>
    	<ul><li>dummy</li></ul></div> <!------- LMBO That's FUNNY ---------->
    
    <!-- ------------------------ Job Type -------------------------------------------------->
    
    	<label for="Estimate_className">Job Type</label>
    
    		<select name="Estimate[className]" id="Estimate_className">
    			<option value="">Select Job Type</option>
    			<option value="On-site">On-Site</option>
    			<option value="Drop-Off">Drop-Off</option>
    		</select>
    
    <!-- ---------------- serviceItem CHECKBOX selections ------------------------------------>
     // itemId, itemName, itemDescription, timeEstimate are the fields forming the checkBox list
    
    
    <div class="itemwrap" id="ServiceRequest_select">
    	<label for="Estimate_selection">Item Selection</label><br />
    
    <input id="ytEstimate_selection" type="hidden" value="" name="Estimate[selection]" />
    <input multiple="multiple" id="Estimate_selection_0" value="1" type="checkbox" name="Estimate[selection][]" />
    <label for="Estimate_selection_0">1. Consultation - Note client needs, evaluate current system, make recommendations. -- time est. 1.00</label><br/>
    <!-- removed the other items because this post is loooong e-nuff! -->
    
    
    <!-- ---------------------- HIDDEN Fields ------------------------------------------------->
    <div id="jrate">
    	<input value="0" size="5" maxlength="5" name="Estimate[hrRate]" id="Estimate_hrRate" type="hidden" />
    </div>
    <div id="jtime">
    	<input value="0" size="5" maxlength="5" name="Estimate[time]" id="Estimate_time" type="hidden" />
    </div>
    <div id="jest">
    	<input value="0" size="5" maxlength="5" name="Estimate[jobEst]" id="Estimate_jobEst" type="hidden" />
    </div>
    
    
    <!-- ---------------------- DISPLAY table ------------------------------------------------->
    	
    <div id="estdisplay">
    	<TABLE summary="This table represents the estimated charges for services selected on the Service Request Form. Total estimated time multiplied by the hour rate.">
    		<CAPTION>Service Estimate</CAPTION>
    		<TR>
       		<TH id="t1">Items</TH>
       		<TH id="t2">Time Est</TH>
    
    		<TR>
       		<TD id="item_selection_box" headers="t1"></TD>
       		<TD headers="t2">totalEstTime</TD>
    		<TR>
    		<TH id="t1">Hour Rate</TH>
    		<TH id="t2">Total Est</TH>
    
    		<TR>
    		<TD headers="t1">hrRate</TD>
    		<TD headers="t2">jobEst</TD>
    
    	</TABLE>
    
    <!-- ------------ hrRate -------------------------------------------------->	
    		<div> On-Site Hr Rate</div>
    		<div id="osr"><?php echo Yii::app()->params['onsiteRate'] ;?></div>
    
    		<div>Drop-Off Hr Rate</div>
    		<div id="dor"><?php echo Yii::app()->params['dropoffRate'] ;?></div>
    
    </form>

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •