Гость
18 Июнь 2014 02:17

I want to run some php code to pre-load some fields before allowing the user to complete the article form. I can do it by running custom php code that first asks the user to enter some information, then stores that info in a 'holding' sql file, and finally links to a new record screen (by copying the link on the article list screen). Then, I've modified the text templates to pre-load their values from this 'holding' sql file.

The problem is that the article list also has a link that allows the user to enter a new article which then bypasses my pre-load code.

How can I either... * Remove the ability for a user to enter a new article from the article list button ("+ Post

here") * Locate a place within Cobalt code to place my custom code. I've tried placing the code in the Article List Template, for example, and while I can load up the 'holding' file, the text value have already been pre-loaded from the previous new article.

Последние изменения: 11 Авг 2014


Sergey
Total posts: 13,748
18 Июнь 2014 08:14

Guest How can I either... * Remove the ability for a user to enter a new article from the article list button ("+ Post here")

Very simple. in markup template parameters you can allow this button only for special users.

Guest I want to run some php code to pre-load some fields before allowing the user to complete the article form. I can do it by running custom php code that first asks the user to enter some information, then stores that info in a 'holding' sql file, and finally links to a new record screen (by copying the link on the article list screen). Then, I've modified the text templates to pre-load their values from this 'holding' sql file.

Why not to use session to store values? How long that data have to be stored?


Гость
28 Июнь 2014 18:58

Sergey Very simple. in markup template parameters you can allow this button only for special users.

But this prevents the public from entering a new record. (see below).

Sergey Why not to use session to store values? How long that data have to be stored?

Not sure what you mean by use 'session' to hold values.

I only need to hold the values long enough to preload the Cobalt fields. The values are computed by decoding the entry string. (These are automobile VIN numbers).

I have written code that places a 'POST' on the screen where the user enters a VIN number. I then calculate some of the fields (which also are used for the composite title), store them temporarily in a separate SQL file, and then use an html link for the 'Post Here' button in Cobalt. Each of the Cobalt text fields involved have been modified to grab values from the temporary SQL file, pre-load them, and set them to 'readonly'.


Гость
28 Июнь 2014 19:03

Sergey Why not to use session to store values?

It occured to me that you meant that 'why don't I insert my custom php code in Cobalt code somewhere'. I tried that, but couldn't find a place (template, etc.) that allowed me to add the POST code before Cobalt presented the fields for a new record.


Sergey
Total posts: 13,748
29 Июнь 2014 07:17

In form template you can add any hidden elements like

<input type="hiden" name="your_name" value="you_ravule">

And this will be submited along with form.


Гость
29 Июнь 2014 20:07

OK, I've added my code to an alternate default template under 'submission form' (default_form_default_alt.php) and I am able to input a VIN, do some calculations, and see that they are placed on the screen form in the proper place.

Two problems.

  1. I cannot save the form unless I remove the POST statements and hardcode the VIN value ($vin). Is there another way to input the VIN in that template that allows it to save? or could there be something else going on?

  2. When I hardcode the VIN value it saves the record, but the vin value is not saved. (nor are the other values I created and calculated from the VIN. The code I am using is....

$this->fields[36]->result = $vin;

This code.... "echo $this->fields[42]->label.': '.$this->fields[42]->result;" gives "VIN: WP0JB0929GS860917", which is correct.

Here's what the 'fields' field looks like in : jos_js_res_record: {"36":"","41":"","39":"","43":"","42":"","40":""}. There is no corresponding set of records in jos_js_res_record_values, probably because the values are null.


Sergey
Total posts: 13,748
29 Июнь 2014 23:50

$this->fields[42]->result should иу field input. At least hidden to be saved.

  1. In this case better to edit field input template or even create new and set it in parameters.
  2. I do not know what is the field. If it a text based, just add there echo $vin and change type="text" to type="hidden" for input.
  3. Also in value="..." insert your $vin.

Final HTML on the form should be something like this

WP0JB0929GS860917
<input type="hidden" name="fields[36]" value="WP0JB0929GS860917">

I am not sure about other fields.

I ccould be more helpfull if I better understand what you need. Actualy I am still do not understand the concept.


Гость
30 Июнь 2014 07:11

We are creating a Registry of cars. Each record has a unique composite title of four text fields. The four fields can be calculated from the VIN. We don't want the user to change the four fields.

We want the user to select the 'add a record' button on the article list, then have the program: * ask for the vin, * calculate the four title values from the VIN * and then provide the submittal form with the four fields readony and the rest available for input (photos, mileage, etc.). >

From your reply...

"$this->fields[42]->;result` should иу field input"

What is the word between 'should' and 'field above?


Sergey
Total posts: 13,748
30 Июнь 2014 07:28

Guest What is the word between 'should' and 'field above?

be

Guest calculate the four title values from the VIN

Where is the calculation in JS or PHP?


Гость
30 Июнь 2014 16:04

It is written in PHP.


Sergey
Total posts: 13,748
01 Июль 2014 00:30

So you need a point in PHP when before save you could populate other 2 fields. I see. Let me think....

DOes this code make any queries to external services or just decode VIN number?


Гость
01 Июль 2014 03:04

No, the VIN number tells us the Year, Model, Country, and Production Number so we don't need to look up any other information from outside data tables.

So we need to find a point where we can ask the user to enter the VIN, and then populate VIN, Year/Model, Country, and Production Number fields in the Cobalt record.


Sergey
Total posts: 13,748
01 Июль 2014 11:06

I think it is possible to do with Javascript on custom submission form. When VIN field is changed, check if vin is complte, and if it is complete, parse it and populate other fields which you can make readonly.


Гость
01 Июль 2014 15:43

Are you suggesting that I place javascript code in a modified submission form default template that asks for a VIN? Can the remainder of the work - i.e., check VIN, parse, store, etc. be done in PHP (since I've already written that code)?

I know nothing about javascript, so trying to keep my research and learning time to a minimum.


Гость
01 Июль 2014 19:33

To test the concept, I have created a custom form submission template where I set $vin to a test value, calculate the other fields, and then placed this code at the end of the Cobalt code (before the functions). (The custom template does not open any foriegn data tables.)

$this->fields[36]->result = $vin; $this->fields[39]->result = $market; $this->fields[42]->result = $production_number;

When I select this 'type', the article list comes up. Then I select the menu item to add a new article.

The form comes up, but none of the fields are preloaded. I included code in the custom form to echo the VIN, and the test value appears on the form.

If I simply added javascript to set $vin, I believe the results would be the same, i.e. fail.


Sergey
Total posts: 13,748
02 Июль 2014 00:50

Give me link to you form so I can see fields IDs and give me axample in PHP how you parse VIN, I'll suggest you a javascript.


Гость
02 Июль 2014 02:11

Here is the form

Don't know how to tell you the login and password confidentially.

Here is the code. It continues for other years in the same fashion.

//End BVV. next is standard VIN DECODER CODE
$market_num = (int) substr($vin, -6); $vin_production = (int) substr($vin, -6, 6); if ( strlen($vin) <= 11 ) { if ( strlen($vin)==10 ) { $temp = substr($vin, 0, 4); if( $temp == '9288' ) { $year_model = 1978; if ( $market_num >= 100001 && $market_num <= 102646 ) { $market = $MARKET_ROW; $model = '928'; $production_number = find_production(100001); } else if ( $market_num >= 200001 && $market_num <= 201139 ) { $market = $MARKET_USA; $model = '928'; $production_number = find_production(200001); } else if ( $market_num >= 209501 && $market_num <= 209575 ) { $market = $MARKET_JAPAN; $model = '928'; $production_number = find_production(209501); } else { //ERROR $error = $ERROR_MARKET_NUMBER; } } else if ( $temp == '9289' ) { $year_model = 1979; if ( $market_num >= 100011 && $market_num <= 103059 ) { $market = $MARKET_ROW; $model = '928'; $production_number = find_production(100011); } else if ( $market_num >= 200011 && $market_num <= 202285 ) { $market = $MARKET_USA; $model = '928'; $production_number = find_production(200011); } else if ( $market_num >= 209511 && $market_num <= 209623 ) { $market = $MARKET_JAPAN; $model = '928'; $production_number = find_production(209551); } else { //ERROR $error = $ERROR_MARKET_NUMBER; } } } else if ( strlen($vin) == 11 ) { $temp = substr($vin, 3, 2); if ( $temp == '08' ) { $year_model = 1980; if ( $market_num >= 11 && $market_num <= 1192 ) { $market = $MARKET_ROW; $model = '928'; $production_number = find_production(11); } else if ( $market_num >= 100011 && $market_num <= 101649 ) { $market = $MARKET_USA; $model = '928'; $production_number = find_production(100011); } else if ( $market_num >= 200011 && $market_num <= 201466 ) { $market = $MARKET_JAPAN; $model = '928 S'; $production_number = find_production(200011); } else { //ERROR $error = $ERROR_MARKET_NUMBER; } } else { //ERROR $error = $ERROR_VIN; } } else { //ERROR $error = $ERROR_VIN; }


Sergey
Total posts: 13,748
02 Июль 2014 02:13

Hope this is better.

//End BVV. next is standard VIN DECODER CODE        
    $market_num = (int) substr($vin, -6);
    $vin_production = (int) substr($vin, -6, 6);
    if ( strlen($vin) <= 11 ) {
        if ( strlen($vin)==10 ) {
            $temp = substr($vin, 0, 4);
            if( $temp == '9288' ) {
                $year_model = 1978;
                if ( $market_num >= 100001 && $market_num <= 102646 ) {
                    $market = $MARKET_ROW;
                    $model = '928';
                    $production_number = find_production(100001);
                } else if ( $market_num >= 200001 && $market_num <= 201139 ) {
                    $market = $MARKET_USA;
                    $model = '928';
                    $production_number = find_production(200001);
                } else if ( $market_num >= 209501 && $market_num <= 209575 ) {
                    $market = $MARKET_JAPAN;
                    $model = '928';
                    $production_number = find_production(209501);
                } else {
                    //ERROR
                    $error = $ERROR_MARKET_NUMBER;
                }
            } else if ( $temp == '9289' ) {
                $year_model = 1979;
                if ( $market_num >= 100011 && $market_num <= 103059 ) {
                    $market = $MARKET_ROW;
                    $model = '928';
                    $production_number = find_production(100011);
                } else if ( $market_num >= 200011 && $market_num <= 202285 ) {
                    $market = $MARKET_USA;
                    $model = '928';
                    $production_number = find_production(200011);
                } else if ( $market_num >= 209511 && $market_num <= 209623 ) {
                    $market = $MARKET_JAPAN;
                    $model = '928';
                    $production_number = find_production(209551);
                } else {
                    //ERROR
                    $error = $ERROR_MARKET_NUMBER;
                }
            }
        } else if ( strlen($vin) == 11 ) {
            $temp = substr($vin, 3, 2);
            if ( $temp == '08' ) {
                $year_model = 1980;
                if ( $market_num >= 11 && $market_num <= 1192 ) {
                    $market = $MARKET_ROW;
                    $model = '928';
                    $production_number = find_production(11);
                } else if ( $market_num >= 100011 && $market_num <= 101649 ) {
                    $market = $MARKET_USA;
                    $model = '928';
                    $production_number = find_production(100011);
                } else if ( $market_num >= 200011 && $market_num <= 201466 ) {
                    $market = $MARKET_JAPAN;
                    $model = '928 S';
                    $production_number = find_production(200011);
                } else {
                    //ERROR
                    $error = $ERROR_MARKET_NUMBER;
                }
            } else {
                //ERROR
                $error = $ERROR_VIN;
            }
        } else {
            //ERROR
            $error = $ERROR_VIN;
        }

Гость
02 Июль 2014 02:17

I give up. The code block feature is not intuitive.


Sergey
Total posts: 13,748
02 Июль 2014 03:05

Guest I give up. The code block feature is not intuitive.

There should not me empty space between ``` and php. And you have to put ``` at the end.

```php
echo 123;
```

Like this. Exactly the same as on Github.


Sergey
Total posts: 13,748
02 Июль 2014 03:06

Guest Don't know how to tell you the login and password confidentially.

You can either edit topic and add credentials or post private comment.

Работает на Cobalt