Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 4th, 2004, 08:34 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default Options values into a string

I am using many <INPUT type="checkbox"> values in an HTML from.
I am getting these all $_POST into an array and imploding it into a string delimited by commas.

User can select only few of checkboxes.
So i am getting pattern like: val1,,,val5,,,val9,,,,,val15,
(say) for 15 checkboxes.
It should be: val1, val5, val9, val15

Some good use of PHP string functions can do so ?
Please HELP..
__________________
`~@#\^%&*/\.<.\/-|+|_!:;..=?>
PHP, SEO | anshul shrivastava | mediasworks.org | FB
Reply With Quote
  #2 (permalink)  
Old November 4th, 2004, 09:07 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

This isn't too difficult to overcome. Assuming that you have an array of checkboxes that looks similar to the following:

<input type='checkbox' name='field[0]' value='value0' />
<input type='checkbox' name='field[1]' value='value1' />
<input type='checkbox' name='field[2]' value='value2' />

You can access this in PHP by doing the following. You should only have POST entries for the checkboxes that were checked in the form. Those that were not checked will not be set on the server.

if (isset($_POST['field']) && is_array($_POST['field']))
{
    $_POST['field'] = implode(',', $_POST['field']);
    // Now $_POST['field'] is a string and no longer an array.
}

The checkbox fields must be constructed with array syntax for this to work though.

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail
Reply With Quote
  #3 (permalink)  
Old November 6th, 2004, 06:59 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

i've tried this for
<input type='text' name='field_xyz[0]' etc.
it is not working

but if(is_array($_POST['field']) evaluates to true
Reply With Quote
  #4 (permalink)  
Old November 6th, 2004, 09:42 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

How about seeing the HTML source of the form and the PHP code you're using to access it.

Regards,
Rich

--
[http://www.smilingsouls.net]
[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail
Reply With Quote
  #5 (permalink)  
Old November 7th, 2004, 03:31 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

i m using
<input type="text" name="keyword[0]" size="15">
..
..
<input type="text" name="keyword[11]" size="15">

so there are 12 textfields.
i want to combine these inputs into a single string delimited by commas and dump it into db.

if (isset($_POST['field']) && is_array($_POST['field']))
   $_string = implode(',', $_POST['field']);
did well for checkboxes

i even used:
if ($_POST['keyword']!="" && $_POST['keyword']!=NULL && $_POST['keyword']!=" " && (strlen($_POST['keyword'])!=0) && $_POST['keyword']!=0 && isset($_POST['keyword']) && is_array($_POST['keyword'])) {
    $f_keywords = implode(', ', $_POST['keyword']);
    }
to filter out empty values for <input type="text"
but can get it.

what else can be done?

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Place string values into ListBox semilemon C# 2005 2 April 13th, 2007 06:36 PM
getting a count of values from within a string cole SQL Server 2000 6 September 5th, 2006 11:20 AM
How to hide the values in query string Ramakrishna.G General .NET 8 May 8th, 2006 07:29 PM
Return ASCII values for a given string sal C# 1 May 19th, 2005 03:59 PM
store multiple values in a string bamboat_3 General .NET 3 May 23rd, 2004 07:32 AM



All times are GMT -4. The time now is 11:40 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.