PDA

View Full Version : Add checkbox to submit and detail pages


predator
02-20-2009, 09:35 PM
Mod Title: Add Checkbox Forms

Last Updated: Feb.20, 2009

Supported by Mod Developer: No

Where to Download: none

Support Via This Thread or Download Site: This Thread

Compatible With: IE 7, FIREFOX



Below is how to add a checkbox form on submit.tpl and how to show the results on detail.tpl. It is a compilation of many discussions on the forum! There are many other variations but this should get you in the right direction! :)

Text in black is the code to change/insert and grey text is where to insert.


-------------------------------------------------------------------------------------------------
The new field in the database is here called "STYPES".
Database: ALTER TABLE ‘PLD_LINK’ ADD ‘STYPES’ VARCHAR(255) NULL
/templates/professional/Submit.tpl
<tr>
<td class="label">{l}Service(s){/l}:</td>
<td class="field">
<input type="checkbox" name="STYPES[0]" value="In-Office"{if !empty($STYPES[0])} checked="checked"{/if} >In Office &nbsp;&nbsp;
<input type="checkbox" name="STYPES[1]" value="In-Home"{if !empty($STYPES[1])} checked="checked"{/if} >In Home Services &nbsp;&nbsp;


</td>

</tr>

Submit.php

['OWNER_NAME'], 0, USER_NAME_MAX_LENGTH - 4).' ...' : trim ($data['OWNER_NAME'])) : '');
}
$data['DESCRIPTION'] = (!empty ($data['DESCRIPTION']) ? (strlen ($data['DESCRIPTION']) > DESCRIPTION_MAX_LENGTH ? substr ($data['DESCRIPTION'], 0, DESCRIPTION_MAX_LENGTH - 4).' ...' : trim ($data['DESCRIPTION'])) : '');
$data['META_DESCRIPTION'] = (!empty ($data['META_DESCRIPTION']) ? (strlen ($data['META_DESCRIPTION']) > META_DESCRIPTION_MAX_LENGTH ? substr ($data['META_DESCRIPTION'], 0, META_DESCRIPTION_MAX_LENGTH - 4).' ...' : trim ($data['META_DESCRIPTION'])) : '');
$data['META_KEYWORDS'] = (!empty ($data['META_KEYWORDS']) ? clean_meta_keywords($data['META_KEYWORDS']) : '');
$RegularLink_notif = true;

#File Uploader (after this if you have added the file uploader)

//checkbox start
if (is_array($data['STYPES']) && !empty($data['STYPES']))
{
$data['STYPES'] = implode (',', $data['STYPES']);
}
//checkbox end
if ($action == 'edit')

include/Tables.php

'STYPES' => 'C(255) NULL'

templates/professional/Detail.tpl

<tr>
<td class="label">&nbsp;</td>
<td class="label">{l}Services{/l}:</td>
<td class="smallDesc" align="left">{$STYPES|escape|trim|replace:",":", "} </td>
</tr>

Detail.php

$data['STYPES'] = $rdata['STYPES'];

templates/core/defaultadmin/dir_links edit.tpl

<tr>
<td class="smallDesc"><label for="service">{l}Services{/l}:</label></td>
<td class="smallDesc">
<input type="checkbox" name="STYPES[0]" value="In-Office"{if in_array('In-Office', $STYPES)} checked="checked"{/if} >In Office &nbsp;&nbsp;<input type="checkbox" name="STYPES[1]" value="In-Home"{if in_array('In-Home', $STYPES)} checked="checked"{/if} >In Home Services
</td>
</tr>


admin/dir_links_edit.php

if (empty ($_POST['submit']))
{
$data['STYPES'] = explode (',', $data['STYPES']);
SmartyValidate :: connect($tpl);

And also add the following:

//Editor is on unallowed page, block access
http_redirect("unauthorized.php");
exit();
}

if (is_array($_POST['STYPES']) && !empty($_POST['STYPES']))
{
$data['STYPES'] = implode (',', $_POST['STYPES']);
}

if (SmartyValidate :: is_valid($data, 'dir_links_edit'))
{

mmastation
02-20-2009, 10:14 PM
got an example?

predator
02-21-2009, 01:31 AM
Soon, I would prefer not to have the site shown yet...
But I can assure you that it works. Most of the code came from discussions on this site so it's nothing new, just without the many conversations between the codes...

ikram84
02-24-2009, 02:04 PM
this mod good with what version? 2.2?

James
02-24-2009, 05:20 PM
its not a mod

its a copy and paste from other threads from other users

btrades
02-28-2009, 01:07 AM
Ok, May be a dumb question. But 3.4 has no file named "dir_links_edit.php" atleast I can't locate it. What file needs to be edited in place of it, if any?

bruleo
02-28-2009, 03:24 AM
That file is, or should be, in your public_html/admin folder.

Bruce.

btrades
02-28-2009, 04:31 AM
Ok, Got that. Now Submit.php

above -> if ($action == 'edit')

"if ($action == 'edit')" is located in a number of locations.
:eek: Wich one, all of them?

predator
02-28-2009, 05:33 PM
I have a file uploader in there. Is it below this part. Line 559 or so (depending on what you've added)...

['OWNER_NAME'], 0, USER_NAME_MAX_LENGTH - 4).' ...' : trim ($data['OWNER_NAME'])) : '');
}
$data['DESCRIPTION'] = (!empty ($data['DESCRIPTION']) ? (strlen ($data['DESCRIPTION']) > DESCRIPTION_MAX_LENGTH ? substr ($data['DESCRIPTION'], 0, DESCRIPTION_MAX_LENGTH - 4).' ...' : trim ($data['DESCRIPTION'])) : '');
$data['META_DESCRIPTION'] = (!empty ($data['META_DESCRIPTION']) ? (strlen ($data['META_DESCRIPTION']) > META_DESCRIPTION_MAX_LENGTH ? substr ($data['META_DESCRIPTION'], 0, META_DESCRIPTION_MAX_LENGTH - 4).' ...' : trim ($data['META_DESCRIPTION'])) : '');
$data['META_KEYWORDS'] = (!empty ($data['META_KEYWORDS']) ? clean_meta_keywords($data['META_KEYWORDS']) : '');
$RegularLink_notif = true;

predator
03-02-2009, 03:53 PM
Question: How do I add the checkbox results to the search queries?