We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22303 MODX Staff
    • 10,725 Posts
    Quote from: heliotrope at Mar 14, 2006, 12:31 PM

    I’ve been trying for several days to setup a form according to my needs.
    But until now I don’t get the right result to include Javascript events.

    Here is the correct output I’d like
    <input type=’checkbox’ name=’langue[]’ value=’0’ onclick="checkBox(’langue’);" />

    Coul you please post a sample code to call events with makeForm Class.

    Here is a sample form array being generated that has an onchange event defined on the client_user_id element:

    <?php
    $result= array(
    	'request_id'=> array('type'=>'hidden', 'label'=>'Request ID', 'name'=>'request_id', 'value'=>$row['request_id']),
    	'expert_id'=> array('type'=>'hidden', 'label'=>'Expert ID', 'name'=>'expert_id', 'value'=>$row['expert_id']),
    	'client_id'=> array('type'=>'hidden', 'label'=>'Client ID', 'name'=>'client_id', 'value'=>$row['client_id']),
    	'client_user_id'=> array('type'=>'select', 'label'=>'Client User ID', 'name'=>'client_user_id', 'size'=>'1', 'options'=>$this->createOptions($this->getClientUserOptions($row['client_id']), $clientUserID), 'onchange'=>'javascript:document.location.href=\'[~[*id*]~]?id='.$requestID.'&expert='.$expertID.'&user=\'+this.options[this.selectedIndex].value'),
    	'client_email'=> array('type'=>'hidden', 'label'=>'Client Email', 'name'=>'client_email', 'value'=>$row['client_email']),
    	'expert_email'=> array('type'=>'hidden', 'label'=>'Expert Email', 'name'=>'expert_email', 'value'=>$row['expert_email']),
    	'admin_email'=> array('type'=>'hidden', 'label'=>'Admin Email', 'name'=>'admin_email', 'value'=>'[+admin_email+]'),
    	'subject'=> array('type'=>'hidden', 'label'=>'Email Subject', 'name'=>'subject', 'value'=>"[CircleOfExperts] Availability for Consultation"),
    	'message_body'=> array('type'=>'textarea', 'label'=>'Message', 'name'=>'message_body', 'value'=>$message_body, 'rows'=>'24', 'cols'=>'60'),
    	'send-invite'=> array('type'=>'submit', 'label'=>'Send Invitation to Expert', 'name'=>'send-invite', 'value'=>'Send Invite', 'style'=>'width:90px;')
    );
    ?>


    Hope that helps. Let me know if you still have questions.
      • 34162
      • 1 Posts
      Very nice work! I will spend sometime try to digest this piece of work.

      Thanks
        • 11975
        • 2,542 Posts
        You really make me happy with this piece of code.

        Thank you for all your contributions for modx community and modx users smiley .

          Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • 11975
          • 2,542 Posts
          Really useful your class but I still have a problem to make "options" for <select> tag and so one more question smiley

          I’ve looked at the chunk "MakeForm-Select" and MakeForm-SelectOption.

          In your sample code you write

          ’options’=>$this->createOptions($this->getClientUserOptions($row[’client_id’])

          I suppose that function "createOptions" and "getClientUserOptions" are specific to the project from which comes the sample code.

          Anyway I’ve tried to pass an array to ’options’=>$myoptions

          with $myoptions defined as follow


          $myoptions = array(
          (’label’=>’test1’, ’value’=>’1’),
          ....
          );

          But it doesn’t work as expected.

          One more time could you please give a hand to a php newbie.

          Thx smiley
            Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: heliotrope at Mar 15, 2006, 07:18 AM

            In your sample code you write

            ’options’=>$this->createOptions($this->getClientUserOptions($row[’client_id’])

            I suppose that function "createOptions" and "getClientUserOptions" are specific to the project from which comes the sample code.

            Here are the functions from the project I am taking this from; you were just not putting your options in another array wrapper:

            <?php
            	function createOptions($options, $selectedOption='') {
            		$optionsArray= array();
            		if (is_array($options)) {
            			foreach ($options as $option) {
            				if (is_array($option)) {
            					$optionLabel= $option[0];
            					$optionValue= $option[1];
            				}
            				$optionsArray[]= array(
            					'label'=> $optionLabel? $optionLabel: $option,
            					'value'=> $optionValue? $optionValue: $option,
            					'selected'=> $optionValue? ($optionValue==$selectedOption? true: false): ($option==$selectedOption? true: false)
            				);
            			}
            		}
            		return $optionsArray;
            	}
            
                    function getClientUserOptions($clientID, $addBlank=false) {
            		$query= "SELECT cu.id, CONCAT_WS(' ', cu.first_name, cu.last_name) AS client_user FROM client_users cu WHERE cu.clientid=$clientID ORDER BY client_user ASC";
            		if ($addBlank) $result[]= array('Select a client contact:', 0);
            		if ($ds= $this->db->query($query)) {
            			while ($row= $this->db->getRow($ds)) {
            				$name= $row['client_user'];
            				$label= stripslashes($name);
            				$value= $row['id'];
            				$result[]= array($label, $value);
            			}
            		}
            		return $result;
            	}
            ?>


            Let me know if you don’t understand something in this code...
              • 11975
              • 2,542 Posts
              Thank you for your time. smiley

              I’ve tried tu use the two functions in my code and I’ve had this error.

              Fatal error: Call to a member function on a non-object

              I’ve proceeded as follows:

              I’ve copied and pasted the two functions in the makeform.class.inc.php , and changed the sql query to my table.

              After that, I’ve tried to make a select tag with this code:
              getCalLangOptions -> is my customised getClientUserOptions

              			$results= array(
              				'categorie'=> array('type'=>'select', 'label'=>'[*id*]', 'name'=>'name', 'value'=>$row['name'], 'options'=>$this->createOptions($this->getCalLangOptions($row['id_langue']), $id_langue)),
              			);
              


              I’ve also tried by copying the functions in the snippet but still have error.

              I’m not of sure of how to use these functions in my own snippet based on the sample provided with the archive file.

                Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: heliotrope at Mar 15, 2006, 03:19 PM

                Fatal error: Call to a member function on a non-object
                You’ll need to change references of $this->db to $modx->db and any other references of $this-> need to be removed. These methods were part of a class. Since you are putting them directly in the snippet, you need to call the functions without $this->.

                'options'=>createOptions(getCalLangOptions($row['id_langue']), $id_langue))


                I hope that makes sense.
                wink
                  • 11975
                  • 2,542 Posts
                  YOU SAVED MY DAY grin !!!!!!!!

                  Everything is fine now, these two classes (makeForm&makeTable) are very useful and powerful tools.

                  Thanks again for your work, your time and for sharing them with us. smiley
                    Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                    • 17833
                    • 28 Posts
                    Is the link at the start of this thread for the latest version of this class?

                    I installed it per the instructions, and it all seemed to work fine, but when i look at the table, i see that it creats 3 records for the one ’submit.’ If, after submitting the form, i try to edit the entry, the second record of the trio in the db, is the one that get’s edited. Using the ’remove’ button also deletes that 2nd of the trio or records. So far, I’ve not been able to trace the creation of the all three records.
                      • 16429
                      • 254 Posts
                      Hi!
                      I’m not a php wizard and I’m in trouble understanding where I have to make changes to personalize the form...
                      What can I change in the snippet file? Which parts are necessary, and which variable names I’ve to retain?

                      Thanks!
                        kudo
                        www.kudolink.com - webdesign (surprised?)

                        [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]