• Hi,

    I am attempting to create my own add record (signup) form, and am stuck.

    What I would like to do is to be able to grab individual input fields, NOT loop through all the input fields.

    The current loop works well to retrieve all the given fields in the database:

     while ( $this->have_groups() ) : $this->the_group();
              while ( $this->have_fields() ) : $this->the_field();
                 $this->field->print_element_with_id();
               endwhile;
            endwhile;
    

    But what I’m aiming to do is output a single input label / field, something similar to the method used for outputting fields on a listing page.

    This will output fields singularly.

    $this_record = new PDb_Template($this);
     $this_record ->print_field('field_name'); ?>
    

    So I was hoping I could use a similar process, instantiate the pdb_template object and then using print_element_with_id( ‘field_name’), output the field.

    Unfortunately this does not work. I can’t seem to wrap my head around what I’m doing wrong to be able to output single fields.

    If anyone has done this, has a working example I could peek at / point me in the right direction, I’d be most grateful.

    thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author xnau webdesign

    (@xnau)

    Can you explain why you don’t want to do this in a loop? It’s not hard to configure the loop to show only the fields you want and in the order you want, that would be a much easier way to go.

    Thread Starter loxx927

    (@loxx927)

    I would be fine if I could figure out a way to show only certain fields in the loop, but so far I have only been able to show all the fields in the loop, I can’t figure out the right syntax to get it to grab only select input fields.

    The only success I’ve had getting fields to display on a page is using this method:

     while ( $this->have_groups() ) : $this->the_group();
              while ( $this->have_fields() ) : $this->the_field();
              print_r( $this->field->print_element_with_id() );
               endwhile;
            endwhile;
    

    But that displays ALL the fields. print_element_with_id doesn’t seem to take an individual field ie, this doesn’t work print_element_with_id(‘field_name’), so I’m stuck as to how to show only specific fields.

    I’m sure as you’ve mentioned there’s a way to do it, I’m just stumped as to how.

    Thanks for the assistance. ??

    Plugin Author xnau webdesign

    (@xnau)

    Well, you can configure the shortcode to only show certain fields using the “fields” attribute…for example:

    [pdb_record fields=”first_name,last_name,city,state”]

    If you want to do it in the template, you can insert code into the loop that skips certain fields

    while ( $this->have_groups() ) : $this->the_group();
       while ( $this->have_fields() ) : $this->the_field();
          if ( $this->field->name === 'first_name' ) {
             continue;
          }
          $this->field->print_element_with_id();
       endwhile;
    endwhile;
    Thread Starter loxx927

    (@loxx927)

    Oh my gosh, is it that simple and I just never stumbled on to it?

    so I could write…

    while ( $this->have_groups() ) : $this->the_group();
       while ( $this->have_fields() ) : $this->the_field();
          if ( $this->field->name === 'first_name' ) {
             $this->field->print_element_with_id();
          }
       endwhile;
    endwhile;
    

    …and that would print the input field for the first_name field, yes?

    If so, thank you so much for that. I don’t know how I didn’t find that on my own…so big thanks!! ??

    Thread Starter loxx927

    (@loxx927)

    I just discovered my (rookie) mistake.. I was incorrectly assuming it wanted the ID of the field, not the actual field name. Whoops. My bad.

    The above code does work. My apologies.

    So for anyone else to avoid this simple mistake, call the field by it’s field name, not by it’s ID.

    =D

    • This reply was modified 4 years, 6 months ago by loxx927.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom add record (signup) form’ is closed to new replies.