tags:

views:

496

answers:

3

I don't know where to begin.. I have 2 pages. The first page is a form that has 4 textfields that pass to the second page and separate each with an comma (only if they filled something into a field - so if they only filled one field in, it would not have any commas) and ending with a period.

How do I do this in PHP?

+1  A: 

link to explain how to send form in php

http://apptools.com/phptools/forms/forms1.php

you can check in php if you get a request form, according to this show the result instead the form - (in the same php page).

4 fields can be an array give a name to the element with []

like : text_array[0] ,text_array[1] , text_array[2] , text_array[3]

easy to run over the array

to show with coma do

join(',',$_POST['text_array']);
Haim Evgi
A: 

You can either test your 4 text fields, quick example below:

$str = '';
if( $_POST['first'] )
    $str = $_POST['first'];
if( $_POST['second'] )
    $str .= ($str != '' ? ',' : '') . $_POST['second'];
if( $_POST['third'] )
    $str .= ($str != '' ? ',' : '') . $_POST['third'];
if( $_POST['fourth'] )
    $str .= ($str != '' ? ',' : '') . $_POST['second'];
$str .= ($str != '' ? '.' : '');

or simpler: make your fields produce an array, by naming all of them my_text[], then:

$str = '';
if( ! empty( $_POST['my_text'] ) && is_array( $_POST['my_text'] ) )
    $str = join( ',', $_POST['my_text'] ) . '.';
streetpc
A: 

I'm not sure you need to separate parameters with comma, as long as you consider using php it's really simple and you can find a ton's of tutorial over the internet. In general you need to do like:

<form action="second_page.php" method="get">
    <input type="text" name=text_field[]>
    <input type="text" name=text_field[]>
    <input type="text" name=text_field[]>
    .....
</form>

And then in second_page.php you can refer to those text field:

<?
  $fields = $_GET['text_field'];
?>
Artem Barger