Jump to content
ridgedale

PW3 - Frontend Blank Field Edit Query

Recommended Posts

Reference: PW 3.0.111 and uikit3 based site using the Regular-Master profile.

I've setup a page where a member can edit contact details via the frontend displaying the field content using the <edit> ... </edit> tags.

This works fine when the fields actually contain data. However fields that contain no data (i.e. empty) do not appear to be editable. No edit cursor appears (- possibly owing to the field width being 0px?)

Is the only solution to recreate the page using a form, for example,  or is there a simple way to allow blank fields to be editable on the frontend?

I wondered if anyone else has found a solution to this problem. Any assistance would be appreciated.

Share this post


Link to post
Share on other sites

I encountered this issue too. Maybe one can call it a bug?

I only used this functionality once, so I added a quick workaround in my template file. If the fields content is empty, I injected some chars " ... ", so the field is clickable. (The spacers are added to the $page->fieldnames in memory, it does not get saved into the DB.)

Following the dirty copy/paste of my used code

Spoiler

<?php
        // einmal Tabellenkopf ausgeben für die Haupttabelle
        echo "<table class='motive' id='tblMotive'>\n";

        // jedes Motiv als Tabelleneintrag ausgeben
        foreach($page->children() as $p) {
            if(empty($p->motiv_notizen)) {
                $p->of(false);
                $p->motiv_notizen = ' ... ';
                $p->of(true);
            }
            if(empty($p->motiv_personen)) {
                $p->of(false);
                $p->motiv_personen = ' ... ';
                $p->of(true);
            }
?>
        <tr class='<?=$p->motiv_single_1->title?>'>
            <td class='id'><?=($user->isSuperuser() ? "<a href='{$p->editUrl}'>{$p->id}</a>" : $p->id)?></td>
            <td class='title'><?=$p->edit('title')?></td>
            <td class='typ'><?=$p->motiv_single_2->title?></td>
            <td class='location'><?=$p->motiv_single_3->title?></td>
            <td class='persons'><?=$p->edit('motiv_personen')?></td>
            <td class='styling'><?=($p->motiv_schminke ? 'X' : '')?></td>
            <td class='notes'><?=$p->edit('motiv_notizen')?></td>
        </tr>

<?php
        }
        echo "</table>\n";

 

 

  • Like 1

Share this post


Link to post
Share on other sites

@horst ,

Thank you for your reply. 

I've tried the code you kindly provided and initially got an undefined $p error so I added $p = '' the top of the template and then refreshed the page and now I'm getting the following error:

Fatal error: Call to a member function edit() on string in /home/.../templates/club.php on line 71

That relates to the first instance of: <?=$p->edit('...

I don't know if this makes a difference but the code I'm currently using to display the fields is as follows:

<edit field='Field_Name'><?=page()->Field_Name?></edit>

I'm clearly not doing something right or have misunderstood how to implement the code. Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites

You need to enable the use of the Functios API in your site/config.php:

$config->useFunctionsAPI = true;  // pages()->find(), sanitizer()->pageName(), region('content', $markup),

 

Share this post


Link to post
Share on other sites

Thanks for the heads-up, @horst .

I presume I just need to add this the end of the site/config.php file.

Is that quote from your site/config.php file and are those your comments to yourself for reference?

Share this post


Link to post
Share on other sites

@horst ,

Further update. Does Processwire need to somehow be restarted after the config change?

I've added the following to the end of the site/config.php file

1 hour ago, horst said:

$config->useFunctionsAPI = true;

and refreshed the browser in the backend.

I have tried the following changes to the table elements without any success:

<edit field='First_Name'><?=page()->$p->First_Name?></edit>

or

<edit field='First_Name'><?=$p->First_Name?></edit>

and both return the following error:

Quote

Notice: Trying to get property of non-object in /.../site/templates/club.php on line ...

When I try the following code:

<?=$p->edit('First_Name')?>

I get the following error:

Quote

Fatal error: Call to a member function edit() on string in /.../site/templates/club.php on line ...
Error: Call to a member function edit() on string (line ... of /.../site/templates/club.php)

In each case the errors are referring to the <td></td> element containing $p.

I can't see what I'm doing wrong. The initial php code is inserted in the same manner directly after <table>. The full code for the template is as follows:

<?php namespace ProcessWire;

// this template is very much like the basic-page template except that it
// demonstrates making the headline, body and sidebar fields editable on the
// front-end, using the <edit> tags

$p = '';
?>

<h1 id='content-head'>Name Profile</h1>

<div id='content-body'>
    <h3><?=page()->Name?> - <?=page()->Code?></h3>
<div class="uk-grid uk-grid-small xzxzx-grid-spacer">
    
    <div class="uk-width-1-1@s uk-width-1-2@m xzxzx-grid-block-spacer">
        <h5><?php echo $M_Title ?></h5>
        <table class="uk-table">
            
            <tbody>
                <tr>
                    <td class="xzxzx-field-label">First Name:</td>
                    <td class="xzxzx-field"><edit field='M_First_Name'><?=page()->M_First_Name?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label">Last Name:</td>
                    <td class="xzxzx-field"><edit field='M_Last_Name'><?=page()->M_Last_Name?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label">Phone:</td>
                    <td class="xzxzx-field"><edit field='M_Phone'><?=page()->M_Phone?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label xzxzx-last-row">Email:</td>
                    <td class="xzxzx-field"><edit field='M_Email'><?=page()->M_Email?></edit></td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="uk-width-1-1@s uk-width-1-2@m xzxzx-grid-block-spacer">
        <h5><?php echo $D_Title ?></h5>
        <table class="uk-table">
            <tbody>
                <tr>
                    <td class="xzxzx-field-label">First Name:</td>
                    <td class="xzxzx-field"><edit field='D_First_Name'><?=page()->D_First_Name?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label">Last Name:</td>
                    <td class="xzxzx-field"><edit field='D_Last_Name'><?=page()->D_Last_Name?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label">Phone:</td>
                    <td class="xzxzx-field"><edit field='D_Phone'><?=page()->D_Phone?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label xzxzx-last-row">Email:</td>
                    <td class="xzxzx-field"><edit field='D_Email'><?=page()->D_Email?></edit></td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="uk-width-1-1@s uk-width-1-2@m xzxzx-grid-block-spacer">
        <h5><?php echo $C_Title ?></h5>
        <table class="uk-table">
            <tbody>
                <tr>
                    <td class="xzxzx-field-label">First Name:</td>
                    <td class="xzxzx-field"><edit field='C_First_Name'><?=page()->C_First_Name?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label">Last Name:</td>
                    <td class="xzxzx-field"><edit field='C_Last_Name'><?=page()->C_Last_Name?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label">Phone:</td>
                    <td class="xzxzx-field"><edit field='C_Phone'><?=page()->C_Manager_Phone?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label xzxzx-last-row">Email:</td>
                    <td class="xzxzx-field"><edit field='C_Email'><?=page()->C_Manager_Email?></edit></td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="uk-width-1-1@s uk-width-1-2@m xzxzx-grid-block-spacer">
        <h5><?php echo $S_Title ?></h5>
        <table class="uk-table">
            <tbody>
                <tr>
                    <td class="xzxzx-field-label">First Name:</td>
                    <td class="xzxzx-field"><edit field='S_First_Name'><?=page()->S_First_Name?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label">Last Name:</td>
                    <td class="xzxzx-field"><edit field='S_Last_Name'><?=page()->S_Last_Name?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label">Phone:</td>
                    <td class="xzxzx-field"><edit field='S_Phone'><?=page()->S_Phone?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label xzxzx-last-row">Email:</td>
                    <td class="xzxzx-field"><edit field='S_Email'><?=page()->S_Email?></edit></td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="uk-width-1-1@s uk-width-1-2@m xzxzx-grid-block-spacer">
        <h5><?php echo $T_Title ?></h5>
        <table class="uk-table">
            <?php
			foreach($page->children() as $p) {
				if(empty($p->T_First_Name)) {
					$p->of(false);
					$p->T_First_Name = ' ... ';
					$p->of(true);
				}
				if(empty($p->T_Last_Name)) {
					$p->of(false);
					$p->T_Last_Name = ' ... ';
					$p->of(true);
				}
				if(empty($p->T_Phone)) {
					$p->of(false);
					$p->T_Phone = ' ... ';
					$p->of(true);
				}
				if(empty($p->T_Email)) {
					$p->of(false);
					$p->T_Email = ' ... ';
					$p->of(true);
				}
			}
            ?>
            
            <tbody>
                <tr>
                    <td class="xzxzx-field-label">First Name:</td>
                    <td class="xzxzx-field"><edit field='T_First_Name'><?=$p->T_First_Name?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label">Last Name:</td>
                    <td class="xzxzx-field"><edit field='T_Last_Name'><?=$p->T_Last_Name?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label">Phone:</td>
                    <td class="xzxzx-field"><edit field='T_Phone'><?=$p->T_Phone?></edit></td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label xzxzx-last-row">Email:</td>
                    <td class="xzxzx-field"><?=$p->edit('T_Email')?></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
</div>

<?php include('./_sidebar.php'); ?>

It doesn't seem to matter where I place php foreach declaration. The same errors occur. I clearly must be doing something wrong. 😞

Any ideas appreciated and thanks for your patience.

Share this post


Link to post
Share on other sites

@horst ,

Just a quick update. I've made some progress. I realised this particular instance of PW3 had not been upgraded to 3.0.111. Apologies for that oversight. Following the upgrade to 3.0.111 the additional text is now being injected and displayed using the following code.

22 hours ago, ridgedale said:

<edit field='T_First_Name'><?=$p->T_First_Name?></edit>

This is the code that now allows the field to be edited. The original style code did not allow the field to be edited:

On 10/12/2018 at 11:18 AM, horst said:

<?=$p->edit('motiv_notizen')?>

However, when I edit and save any changes the field continues to display the ellipsis even though the changed data appears on the page in the backend. So I tried changing the above code as follows:

<?php if(!empty(page()->T_First_Name)) { page()->T_First_Name; } else { $p->T_First_Name; }?>

But that causes the field to apparently display as blank again event though again the field contains the edited data in the backend.

I also tried editing the foreach statement similarly with the same results.

I can't see what I'm doing wrong. Any ideas?

 

Share this post


Link to post
Share on other sites

Finally, I've managed to get the frontend editing and data display working as I think it is intended. Below is an excerpt of the sample data posted earlier that has been updated and appears to work:

    <div class="uk-width-1-1@s uk-width-1-2@m xzxzx-grid-block-spacer">
        <h5><?php echo $T_Title ?></h5>
        <table class="uk-table">
            <?php
			foreach($page->children() as $p) {
				if(empty($p->T_First_Name)) {
					$p->of(false);
					$p->T_First_Name = ' ... ';
					$p->of(true);
				}
				if(empty($p->T_Last_Name)) {
					$p->of(false);
					$p->T_Last_Name = ' ... ';
					$p->of(true);
				}
				if(empty($p->T_Phone)) {
					$p->of(false);
					$p->T_Phone = ' ... ';
					$p->of(true);
				}
				if(empty($p->T_Email)) {
					$p->of(false);
					$p->T_Email = ' ... ';
					$p->of(true);
				}
			}
            ?>
            
            <tbody>
                <tr>
                    <td class="xzxzx-field-label">First Name:</td>
                    <td class="xzxzx-field">
                    <?php if(!empty($page->T_First_Name)): ?>
                        <edit field='T_First_Name'><?=page()->T_First_Name?></edit>
                    <?php endif; ?>
                    <?php if(empty($page->T_First_Name)): ?>
                        <edit field='T_First_Name'><?=$p->T_First_Name?></edit>
                    <?php endif; ?>
                    </td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label">Last Name:</td>
                    <td class="xzxzx-field">
                    <?php if(!empty($page->T_Last_Name)): ?>
                        <edit field='T_Last_Name'><?=page()->T_Last_Name?></edit>
                    <?php endif; ?>
                    <?php if(empty($page->T_Last_Name)): ?>
                        <edit field='T_Last_Name'><?=$p->T_Last_Name?></edit>
                    <?php endif; ?>
                    </td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label">Phone:</td>
                    <td class="xzxzx-field">
                    <?php if(!empty($page->T_Phone)): ?>
                        <edit field='T_Phone'><?=page()->T_Phone?></edit>
                    <?php endif; ?>
                    <?php if(empty($page->T_Phone)): ?>
                        <edit field='T_Phone'><?=$p->T_Phone?></edit>
                    <?php endif; ?>
                    </td>
                </tr>
                <tr>
                    <td class="xzxzx-field-label xzxzx-last-row">Email:</td>
                    <td class="xzxzx-field">
                    <?php if(!empty($page->T_Email)): ?>
                        <edit field='T_Email'><?=page()->T_Email?></edit>
                    <?php endif; ?>
                    <?php if(empty($page->T_Email)): ?>
                        <edit field='T_Email'><?=$p->T_Email?></edit>
                    <?php endif; ?>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>

The only problem with this is that if the text to be entered is long it will break out of the display area and make the page layout look very messy. The solution to this would appear to be to display the text to be entered or edited within inputs, but the various methods of incorporating the editable data into an <input> element I've tried so far but so far have failed to work. The data is either displayed outside of the <input> or the data becomes uneditable, or the data appears to be editable but does not get saved.

Has anyone found a way to display editable data within an input to allow the data to be edited and updated?

Any assistance would be appreciated.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By muzzer
      Existing PW site version 2.7.2 core running on php7.1. Site is perhaps 7 yrs old and never misses a beat. Can't speak highly enough about this solid version, but....
      As new php versions are released (v8 in the next year I think?) and each seems to get quicker I'm looking at upgrading to php7.3 or 7.4 and upgrading the site to PW v3.x.
      I've been away from the forums since v3 was released so don't know much about it. I guess it's stable as it's been around for ages now, but what I'm wondering is:
      what are the real advantages of upgrading to v3 for a site which is actively used but with only periodic development. And what are the disadvantages if any? Is there any speed impact (good or bad) in either general site speed under 3.x or admin-use speed/ease of use? any issues with either PW version with newer php versions (>7.1) I should know about? is there any good write-ups/vids about new features etc of v3 compared to v2.7? Thank you
       
    • By benbyf
      Hi, Looking to create form elements on a page–some input with a colection of form inputs and the appropriate labels and variables for that input. I've used ProForms in the past and rolled out my own when creating simply one off forms, but I wonder if anyone has found a good way of allowing form creation on page editing so that clients can adhocly make and edit forms?
      Thanks
    • By rushy
      Hi all
      Continuing my first project where I am creating and manipulating stuff from the frontend. Till now I've always added things like images from the backend, but in this project I need to add and move images from a frontend control. This is a photo album where images are stored in albums, each album being a page containing a Pageimages array in the usual way. So what I want to know is how do I move an image from one album (page) to another in the frontend? I just need some guidance on how to approach this.  I suppose I need to do a copy and delete - but how do I copy an image or images from one page to another? What function should I use to create a new image on an existing page? I include a code snippet from the server side of my delete image request and it works fine. I'd like to implement something similar for a move and upload new image request. 
      Many thanks for any help. Paul 
      <?php namespace ProcessWire; // sanitize inputs as 1-line text $action = $sanitizer->text($input->post('action')); $instr = $sanitizer->text($input->post('input')); $sel = $input->post('selected'); // Expect JSON for image selected image list $selected = json_decode($sel); $nosel = count($selected); $response = array(); // for building JSON response switch($action) { // delete selected images case 'delete': $out = "<p>Deleted $nosel image(s)</p>"; foreach($selected as $item){ $album = $pages->get($item->album); $album->of(false); $out .= "<p>Image {$item->file} from album {$album->title}</p>"; $album->images->delete($item->file); $album->of(true); } $out .= saveUpdatedAlbums($pages, $selected); // add the response message for the delete $response['message'] = $out; break; ...... // save any album that had an image deleted function saveUpdatedAlbums($pages, $selected) { $cur = ''; $out = ''; foreach($selected as $item){ $album = $pages->get($item->album); if($album->id != $cur) { $album->of(false); $album->save('images'); $album->of(true); $cur = $album->id; $out .= "<p>Updated album {$pages->get($cur)->title}</p>"; } } return $out; }  
       
       
    • By hellomoto
      I can't tell what's wrong; my local development version appears just fine, but I copy over the site files and db online and the homepage content is not being contained. This is what it should look like (same site in the same browser, running on my localhost): http://imgur.com/UFZFzrd
      What could be the problem here? Sorry to bring up something so irrelevant to PW here, I just know that you all are a valiant and helpful group, and no one on StackExchange seems to even know what I'm talking about.
      Thanks a lot.
    • By rushy
      Bit of a newbie type question, even though I've been using PW for quite a while, I've not had to manipulate assets from the front end before.  I now have a need to update image properties from the front end and I'm trying to update an image description and tags when clicking on a link. I get the selected image and for example I can delete it with the code below. But I am missing some basic understanding when updating image description field as nothing happens, no errors but the description field remains empty. Any idea what steps I am missing? Many thanks. 
      // how to update image description? $al = $pages->get($album); $pgfile = $al->images->getFile($file); $al->of(false); $pgfile->description = "Test description"; $al->save(); // to delete an image - this works $al->of(false); $al->images->delete($file); $al->save();  
×
×
  • Create New...