New Community Forums are coming. Watch this space for news.
Subscribe: RSS
  • Quote from: xwisdom at Oct 20, 2006, 01:57 PM

    New efield="column:datatype:default" attribute
    <input name="name" type="text" eform="Your name:string-50:1" efield="fname:string:" emessage="You must enter a name" />

    Note here that the -50 represents the length of the field. More on this in time to come.

    Thank you! This sounds like some very cool stuff. I am anticipating seeing/using the new methods. Can’t you just feel the buzz?
      Mike Reid - www.pixelchutes.com
      MODx Ambassador / Contributor
      [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
      ________________________________
      Where every pixel matters.
    • Quote from: pixelchutes at Oct 20, 2006, 12:21 AM

      Query a table’s MetaData using $modx->db->getTableMetaData, followed by an update query on only the form fields that are named after table columns!




      In this quick example, I grab the columns from our `leads` table, and for any form field submitted that matches a column name in the table, a definition is defined for that column, using the validated, submitted form value.
      (NOTE: I am not passing {PREFIX} because I don’t use one here)

      	// Grab our table's columns
      	$tblColumns = array_keys( $modx->db->getTableMetaData( 'leads' ) );
      	// Loop through each column, and insert it if present in the form
      	foreach( $tblColumns as $tblCol )
      		if( isset( $fields[ $tblCol ] ) ) $dbTable[ $tblCol ] = $fields[ $tblCol ]
      


      However, my contact form asks for both Best Time to Call and whether in AM or PM. I also need to convert the time they submitted the form to be MySQL-insert-friendly.

      So, I handle any custom processing immediately after:

      		// Custom processing (e.g. date values, field joining, PHP logic, etc)
      		// Insert field/value pairs to insert/update in our table
      		$dbTable[datetime] = date( 'YmdHis', strtotime( $fields[postdate] ) );
      		$dbTable[call_time] = $fields[time] . ' ' . $fields[amorpm];
      


      And then, simply invoke the insert SQL (as in my original example):

      $dbQuery = $modx->db->insert( $dbTable, 'leads' );
      


      And here is the result...eForm records right in the db!

        Mike Reid - www.pixelchutes.com
        MODx Ambassador / Contributor
        [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
        ________________________________
        Where every pixel matters.
      • @pixelchutes

        I was really hoping this would happen... This is truly great stuff.

        However, I think TobyL’s intentions may have been to keep [ eForm <-> "DB Stuff" ] separate to reduce "bloated code"? Especially since his callback functions allow for it the way I’ve illustrated here.

        Yes, that was indeed my intention but an extra event wouldn’t ga amiss I think. Once I’ve cleaned up the niggly bits you and others have pointed out in eForm I’ll have a look at other possible events.

        • Oh and I just noticed this one:

          I believe the form is not fully parsed until after it’s first submission...wait, that can’t be true since the parser DOES remove all eform="" tags...
          In that case, we might need to create db2eForm Cheesy

          The form template is indeed not fully parsed until after the first form submission (would be pretty useless as it’s meant for parsing data for validation at the moment). It does merge any placeholders for which it finds a value in the $fields array. The eform pseudo-attributes are simply removed with a regular expression.
          • @TobyL--

            Thank you for clarifying this. Definitely points out that an event such as onBeforeFormLoad Would be pretty useful.

            What if you built the parser to capture from <form id="eFormID" ... to </form> and maybe pass that as an argument to be referenced in the user function. They could setPlaceholders from db, etc, whatever they’d like really, then return the modified string-HTML. Is this the idea?


              Mike Reid - www.pixelchutes.com
              MODx Ambassador / Contributor
              [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
              ________________________________
              Where every pixel matters.
            • Quote from: pixelchutes at Oct 22, 2006, 07:04 PM

              Thank you for clarifying this. Definitely points out that an event such as onBeforeFormLoad Would be pretty useful.

              What if you built the parser to capture from <form id="eFormID" ... to </form> and maybe pass that as an argument to be referenced in the user function. They could setPlaceholders from db, etc, whatever they’d like really, then return the modified string-HTML. Is this the idea?

              Working on it... See this post.
              • Quote from: TobyL at Oct 23, 2006, 12:47 AM

                Working on it... See this post.

                Woo hoo! This is getting good! In the post you reference, you mentioned correction of "some small bug fixes" ...mind sharing high-level, is it anything to be concerned about?
                  Mike Reid - www.pixelchutes.com
                  MODx Ambassador / Contributor
                  [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                  ________________________________
                  Where every pixel matters.
                • Quote from: pixelchutes at Oct 23, 2006, 03:55 PM

                  Woo hoo! This is getting good! in the post you reference, you mentioned correction of "some small bug fixes" ...mind sharing high-level, is it anything to be concerned about?
                  # Fixed: Missing language file produces fatal error. (Will now generate a debug message if debug is on)
                  # Fixed: Missing ’replyto’ in AddAddressToMailer function.
                  # Fixed: Erroneous closing slash (/) being added in <option ..> tags
                  # Fixed: Missing whitespace before ’selected’ and ’checked’ attributes
                  • I’d love to see this thing in action! Is there an example out there?
                    • Quote from: TheBear at Oct 30, 2006, 05:40 AM

                      I’d love to see this thing in action! Is there an example out there?

                      @TheBear,

                      Unfortunately, my only active example is on my local testing machine. However, if you have MODx installed, with the most recent eForm snippet, you can follow my example in the very first post to customize mapping of validated form data into the DB.

                      Another post in this same thread shows a screen shot of captured data in a MySQL GUI.
                        Mike Reid - www.pixelchutes.com
                        MODx Ambassador / Contributor
                        [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                        ________________________________
                        Where every pixel matters.