123 Posts
EclipseMedia
9 years ago
11
Topic

Hey everyone,

I have a client who will be offering a children adoption site. Each article will be the details on the child and there will need to be a form to submit to adopt the child. I need the form upon submitting to then unpublish that article (child detail) since there is a pending adoption and no one else can select that child.

Get a VIP membership
123 Posts
EclipseMedia
9 years ago
0
Level 1

Bump.Anyone?

178 Posts
Jeka
9 years ago
0
Level 1

Hi.

As i can understand "to adopt the child" form is another content type?

9 years ago
3
Level 1

Hello EclipseMedia,

the state of the article can be manage by the field Article State;

If you want that the article is unpublished on the création, you have to add the Article state field in the form with the hidden variation and set the live value "0".


You can also add the restriction Workflow "Add", so this field will work only at the creation.

Then you add an alias of this field with the restriction workflow "Edition". With that an administrator will be able to manage the state.


Regards.

Lionel

123 Posts
EclipseMedia
9 years ago
2
Level 2

The form would be part of the content item.... OR "a" form would be shown with the content item.

So Lionel, it is possible to have a form to fill out by a potential adopter within the content article (the child person) that when submitted will turn the state of that article off. :)

123 Posts
EclipseMedia
9 years ago
1
Level 3

Just bumping to hope Lionel will be able to reply

154 Posts
WebOne
9 years ago
0
Level 4

EclipseMedia - you can change the state of fields after submitting a form with the Code Pack.

www.seblod.com/products/1854

123 Posts
EclipseMedia
9 years ago
0
Level 1

Awesome, thank you.

123 Posts
EclipseMedia
8 years ago
2
Level 1

I installed the Code pack but I don't know what to add as code in

AfterStore field.

1283 Posts
Bucklash
8 years ago
1
Level 2

Hi EclipseMedia

So you have a form, that when saved, unpublishes an article

Option 1: Form on same page as article (content view)

Option 2: Article selected within the form. (are there more options? hmmm...)

Option 1

Create a new field of type Text and put it in your form. Let's say the machine name is 'art_id_value'

Select [2] in your form to get access to live values.

select 'url' for Live, and in live values click 'configure', and for variable enter 'id'

You might as well set the type to 'int' (integer) for good measure

Now you will have the article's id placed in the form for reference. If you do not want to store the id, set Storage to 'none'.

Create a new field of type Afterstore and enter code that updates a db record similar to the code below:

    // assign id to a variable
    $artId = $config['post']['art_id_value'];
    // assign desired state to a variable (if you want)
    $artState = 0;
    // get db connection
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    // Field(s) to update.
    $fields = array( // 
        $db->quoteName('state') . ' = ' . $db->quote($artState)
    );
    // Conditions for which records should be updated.
    $conditions = array(
        $db->quoteName('id') . ' = ' . $db->quote($artId)
    );
    $query->update($db->quoteName('#__content'))->set($fields)->where($conditions);
    $db->setQuery($query);
    $result = $db->execute();

Option 2

Create a new field of type Select - Dynamic and put it in your form. Let's say the machine name is 'art_id_value'

Create a query to get desired values.

I use the 'Query' : 'Free' option to write the query, and the example is below:

    SELECT title AS text, id AS value
    FROM #__content
    WHERE catid = 17 AND state = 1; // 17 is to be changed to the catid you require

You need to check out this link and get funky with it:

Inserting,_Updating_and_Removing_data_using_JDatabase

This might help:

learning-beforerender-form-not-value

learning-php-print-r

This is probably a bit confusing...

how-to-call-a-single-value-form-fieldx

// gets results if beforerender

$fields['art_id_value']->form;
	

// gets results if beforestore

$config['post']['art_id_value'];
	

// gets results if afterstore

$config['post']['art_id_value'];
	

Hope that helps

Bucklash

123 Posts
EclipseMedia
8 years ago
0
Level 3

Option 1 worked perfect!!!! Thank you Thank you

310 Posts
ricco
8 years ago
0
Level 1

Wow, thank you Bucklas.

Get a Book for SEBLOD