--- brucewhealton <[EMAIL PROTECTED]> wrote:

>         This might be a little off topic as I am seeking advice on
> finding a good form processor.  I had one very simple one but it
> requires that I change the code for radio buttons and check boxes to
> use arrays.  I'd rather not have to use that if I don't have a need to
> do so otherwise.
>        I had this other form that has been sending lots of spam to my
> email.  I thought that a good form written in php would prevent
> spam-bots from being able to do that.  Being able to send to more than
> one email address is a nice feature as is simplicity.  Perhaps, later,
> I might want to add the ability to keep things in a database when
> submitted but now, the goal is simplicity.
>     I am  hoping I don't have to write new php code, since so many
> form processors are already out there.
>      A couple other things have come to mind.  On one form, I use it
> for poetry submissions to a poetry magazine.  Sometimes it takes
> apostrophe's and such and turns them into something that at times
> looks like escape characters and at other times it is just garbage
> content, making it hard to read what the original author intended.  Or
> additionally, the poem might come to me via email and not be formatted
> as the author intended, as it comes out looking like prose, with none
> of the author's formatting or layout for each line of the poem.  
>     Any recommendations are appreciated.  Also, if you could explain
> anything about what I wrote in the previous paragraph, that would be
> helpful to know.  I mean perhaps I would need to create or modify some
> existing form processor to address those needs.
> Thanks,
> Bruce

<input type='radio' name='var' value='val1'> Value 1<br />
<input type='radio' name='var' value='val2'> Value 2<br />
<input type='radio' name='var' value='val3'> Value 3<br />
<input type='radio' name='var' value='val4'> Value 4<br />
<!-- only one value goes into var -->

Radio button inputs with the same variable name passes only a single value to
your PHP script.  However, if done correctly, a collection of checkboxes can
pass multiple values to the script.  Hence, an array is a variable which can
hold multiple values and is well suited for this task.  The same is true for
select lists vs. select lists with the multiple option.

<input type='checkbox' name='arr[]' value='val1'> Value 1<br />
<input type='checkbox' name='arr[]' value='val2'> Value 2<br />
<input type='checkbox' name='arr[]' value='val3'> Value 3<br />
<input type='checkbox' name='arr[]' value='val4'> Value 4<br />
<!-- array arr may hold any of 0, 1, 2, 3, or 4 values -->

Once you have the array in your script, you can do things like use join() to
put the array elements together in a string with some separation characters. 
I, for one, would have a greater understanding of your needs with a bit more
specific detail of what you are trying to accomplish.

Text inputs, whether they are in an <input type='text'> or a <textarea> field
will pass values to your script.  This may place backslashes in front of
certain special characters (ie single quotes) if a server configuration feature
called magic_quotes_gpc is "on" (old way) or "off".  You can learn the value of
this parameter in several ways:

* look for line with magic_quotes_gpc in /etc/php.ini (typical Linux location)
* run a program with phpinfo() and look for the value
* print ini_get('magic_quotes_gpc');

If it is on, you can remove the backslashes by using stripslashes() on the
variable or changing the value of magic_quotes_gpc with an:

ini_set('magic_quotes_gpc', 0);

at the top of your program.  I haven't tried this but it should work if the
processing is done soon enough in the sequence.

More likely, your odd characters are coming in when someone copies text from a
program like MS Word and pastes it into a <textarea> field.  Curly quotes and
apostrophes and other special characters don't always translate well into the
plain ASCII text that browsers are used to displaying.

However, the function htmlentities() is useful when you have text like this
that you want to output in a browser-friendly manner.  An HTML entity is where
something special like the copyright symbol is converted into &copy; for
display.

It is worth getting into the habit of using htmlentities() or a similar
function to process your inputted values.  You may need to use it in
conjunction with stripslashes() and use double quotes if you are going to show
this value in a <input type='text'> field.

<input type='text' name='textinput' value="<?php print
htmlentities(stripslashes($in)); ?>">

Since you could be doing these functions multiple times, it is often good to
use a function to clean things up a bit:

function fix($in)
{
 return htmlentities(stripslashes($in));
}

Then you could rewrite the above as:

<input type='text' name='textinput' value="<?php print fix($in)); ?>">

In short, it all depends on what you want to do.  PHP has functions for most
tasks related to web page creation.

http://www.php.net and its function list are very helpful and contain examples
submitted by users.  It's worth looking into.

James

Reply via email to