x
 
Create New Page
 View Previous Changes    ( Last updated by leejb )

Standalone Form-Hardcoding

If you want to customize the standalone entry form, it’s easy to do.

For example, if you only want to show some of your custom fields, you can’t use the {custom_fields} tag- because it will display them all- and it will display them as formatted in the control panel.

First thing you’ll need to do is enable PHP and set PHP Parsing Stage to INPUT on the template(s) you’re using this on.  Templates - Preferences - (Allow PHP) (INPUT)

With a little php, it’s easy to add the fields by hand. Here’s a very simple example:

<?php

if (isset($_POST['field_id_1'])) {
$field_id_1
= $_POST['field_id_1'];
}

else {
$field_id_1
= '';
}

if (isset($_POST['field_id_2'])) {
$field_id_2
= $_POST['field_id_2'];
}

else {
$field_id_2
= '';
}


?>

{exp
:weblog:entry_form weblog="weblog1" return="weblog/index" preview="weblog/entry"}
<p>Title<br />
<
input type="text" name="title" id="title" value="{title}" size="50" maxlength="100" onkeyup="liveUrlTitle();" /></p>

<
p>URL Title<br />
<
input type="text" name="url_title" id='url_title' value="{url_title}" maxlength="75" size="50" /></p>

{formatting_buttons}

---The part below is hard coded---

<
p>My first hard coded custom field
<input type="text" name="field_id_1" id="field_id_1" size="50" maxlength="100" value="<?php echo $field_id_1;?>"></p>
<
input type='hidden' name='field_ft_1' value='none' />

<
p>My second hard coded custom field<br />
<
input type="text" name="field_id_2" size="50" maxlength="100" value="<?php echo $field_id_2;?>"></p>
<
input type='hidden' name='field_ft_2' value='none' />

----
End of the customization---

<
input type="submit" name="submit" value="Submit" />
<
input type="submit" name="preview" value="Preview" />
{/exp:weblog:entry_form}

You need the php bits in order for the preview you to work- and the php needs to be on the preview page. If you aren’t going to allow preview, you could leave out the php.

What is important, and what does differ from using the custom field tag, is you MUST use the column name rather than the field short name.

For example, if ‘My first hard coded field’ is the ‘Field Label’ and its short name is ‘first’, in ” Admin › Field Groups › Custom Fields ” if I put my cursor over the ‘edit’ link for that field, I see the url is:
http://www.example.com/system/index.php?S=0&C=admin&M=blog_admin&P=edit_field&field_id=1

BINGO- there’s my field id number!

If you DON’T include a field, it’s just like leaving it empty on the regular publish page- the default value (usually nothing) will be entered.

This means it’s very easy to create a highly customized publish page. For example, I use check boxes instead of text fields for quick entry of binary data. Now, that’s a little trickier to hold the ‘select in the preview- here’s what I do:

<?
if (isset($_POST['field_id_1'])) {
$field_id_1
= $_POST['field_id_1'];
}

else {
$field_id_1
= '';
}

if (isset($_POST['field_id_2'])) {
$field_id_2
= $_POST['field_id_2'];
}

else {
$field_id_2
= '';
}

if ($field_id_1 == 'First') {
$field_id_1
= 'checked';
}

if ($field_id_2 == 'Second') {
$field_id_2
= 'checked';
}

?>

{exp
:weblog:entry_form weblog="weblog1" return="weblog/index" preview="weblog/entry"}
<p>Title<br />
<
input type="text" name="title" id="title" value="{title}" size="50" maxlength="100" onkeyup="liveUrlTitle();" /></p>

<
p>URL Title<br />
<
input type="text" name="url_title" id='url_title' value="{url_title}" maxlength="75" size="50" /></p>

{formatting_buttons}

---The part below is hard coded---

<
label for="field_id_1">First custom field?</label>
<
INPUT class=radio type=checkbox value=First id=field_id_1 id=field_id_1 name=field_id_1 <?php echo $field_id_1 ; ?>>
<
INPUT type=hidden value=none name=field_ft_1>

<
label for="field_id_2">Second custom field?</label>
<
INPUT class=radio type=checkbox value=Second id=field_id_2 id=field_id_2 name=field_id_2 <?php echo $field_id_2 ; ?>>
<
INPUT type=hidden value=none name=field_ft_2>

---
End of the customization---

<
input type="submit" name="submit" value="Submit" />
<
input type="submit" name="preview" value="Preview" />
{/exp:weblog:entry_form}

In fact, if you go to the trouble of hard coding this mess out, it’s actually pretty easy to make your own custom EDIT form as well.

The logic- do a query based on the entry id- easy to pass via a segment in a link next to the article:

$query = $DB->query("SELECT * FROM exp_weblog_data, exp_weblog_titles WHERE exp_weblog_titles.entry_id = '{segment_3}' AND exp_weblog_titles.entry_id=exp_weblog_data.entry_id LIMIT 0,1");

and use:

if (isset($query->row['field_id_1'])) {
$field_id_1
= $query->row['field_id_1'];
}
else {
$field_id_1
= '';
}

Instead of $_POST!

But the details on that are the subject of another post.

NOTE- with the query, you should be able to use just:

$field_id_1 = $query->row['field_id_1'];

But I’m lazy and just did a search/replace of $_POST with $query- hence mine looks like the above.

NOTE- if you want to use the formatting buttons on a textarea field, you must add the following attribute to the textarea tag:

onclick="setFieldName(this.name)"

So in the top example you could add the definition for a 3rd field:

$field_id_3 = (isset($_POST['field_id_3'])) ? $_POST['field_id_3'] : '';

and then add a text area custom field that will function with the {formatting_buttons} tag:

<p>My third hard coded custom field<br />
<
textarea name="field_id_3" id="field_id_3" cols="70" rows="20" onclick="setFieldName(this.name)"><?php echo $field_id_3;?></textarea></p>

Category:Templates
Category:SAEF

Categories: