Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I am facing big problem.

I am making a web site for a travel agent.

I am making a form where the Admin will create a new tour.

One form contain all information related to new tour.
On another Form the Admin will enter the Itinerary for that tour.

I have 4 fields (Day no, City, Itinerary, Night Stay City).

As the tour can be of variable days. It may be for 7 days or 10 or 15 days, so accordingly I did the code for Admin to add and remove the text boxes according to tour's no of days.

Now I want to save the whole itinerary in a table.

My question is how can i send the whole bunch of array (suppose the tour is or 10 days then 10 itinerary * 4 columns ) to another form for inserting into table using the $_POST thru a URL. And another thing is how should i receive this bunch of array on the posted form and save into table.

I am giving the code which i have created please let me know how can i take the values in array and pass to another page.

This is a code for inserting itineraries for a tour in a particular tourname.

This is my javascript code which create the textboxes after clicking Add Button

JavaScript
<script type="text/javascript">

$(document).ready(function(){

    var counter = 2;

    $("#addButton").click(function () {

    if(counter>30){
            alert("Only 30 textboxes allow");
            return false;
    }

    var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv' + counter);
    newTextBoxDiv.after().html(
          '<input type="text" name="textbox' + counter +'" id="textbox' + counter + '" value="'+ counter + '" >' +
          '<input type="text" name="textbox' + counter +'" id="textbox' + counter + '" value="" >'+
          '<input type="text" name="textbox' + counter +'" id="textbox' + counter + '" value="" >'+
          '<input type="text" name="textbox' + counter +'" id="textbox' + counter + '" value="" >' );

    newTextBoxDiv.appendTo("#TextBoxesGroup");
    counter++;
     });


     $("#removeButton").click(function () {
    if(counter==1){
          alert("No more textbox to remove");
          return false;
       }

    counter--;

        $("#TextBoxDiv" + counter).remove();

     });

     $("#getButtonValue").click(function () {

    var msg = '';
    for(i=1; i<counter;>    {
      msg += "\n No. of day #" + i + " : " + $('#textbox' + i).val();
    }
          alert(msg);


     });
  });
</script>


Now I am giving you the html code for text boxes.
JavaScript
<form id="form1" name="form2" method="post"  onsubmit="" action="addtour_itinerary.php"  >
        <table width="717" height="123">
          <!--DWLayoutTable-->
          <tr>
            <td height="27" colspan="4" align="center" valign="middle" bgcolor="#FFEAFF">Enter Itinerary Details</td>
            </tr>
          <tr>
            <td height="27" colspan="2" valign="top" bgcolor="#FFEAFF">Name of Tour (category)</td>
              <td colspan="2" align="center" valign="middle" bgcolor="#FFFFCC"><label>
              <?php echo $_SESSION['tourname'];??></label></td>
            </tr>
          <tr>
            <td width="61" height="27" valign="top" bgcolor="#E1E1E1">Days</td>
            <td width="140" valign="top" bgcolor="#E1E1E1">City</td>
            <td width="345" valign="top" bgcolor="#E1E1E1">Itinerary</td>
          <td width="145" valign="top" bgcolor="#E1E1E1">Night Stay</td>
          </tr>
          <tr>
            <td height="48" colspan="4" valign="top" bgcolor="#E1E1E1">
                <!--<input type="text" name="days" id="days" />-->

                <div id="TextBoxesGroup">

                  <div id="TextBoxDiv1">

                    <label></label>

                    <input type='text'  id='dayNo'  name="itinerary[]" >
                    <input type="text"  id='cityName'  name="itinerary[]">
                    <input type='text'  id='schedule'  name="itinerary[]">
                    <input type='text'  id='nightStay'  name="itinerary[]">

                  </div>

                </div>

                <input type='button' value='Add Button' id='addButton'>
                <input type='button' value='Remove Button' id='removeButton'>
                <input type='button' value='Get TextBox Value' id='getButtonValue'>
                <input type="submit" name="submit" id="submit" value="Submit" />

                </td>
            </tr>
          </table>
        </form>

Now i want to ask does i have created the array of textboxes correctly or not. what is wrong with my code. how i should collect the values entered into the textboxes and pass to the php page so that i can be saved in table. How can i save the send array into table.
Can i pass the whole array thru session and how to receive those values, i would like to know what should i write in VALUES( ) after Getting the array values.

Thanks in Advance.
Posted
Updated 30-Aug-12 4:19am
v3

I've made a simple google search just to see if the answer is out there or not...

And of course there it is...

I've used multidimensional array php get post as the search criteria which has returned plenty of results.

Some interesting ones:
http://stackoverflow.com/questions/2433727/submitting-a-multidimensional-array-via-post-with-php[^]

http://php.net/manual/en/reserved.variables.post.php[^]

http://stackoverflow.com/questions/1719087/multi-dimensional-array-post-from-form[^]

Good luck!
 
Share this answer
 
Hi Joan
Thanks for your quick reply. I checked with those link already.
But i want to know can you check please whether i have given the array name properly to textboxes. i have no clue whether its correct or not and how should i get the vales from those rows into array and assign to variable so i can send and receive in session or thru the link
 
Share this answer
 
Comments
Joan M 3-Sep-12 9:34am    
KAP75... if you write an answer and not a comment to my answer I can't see that... I've just come to this post by error...
Joan M 3-Sep-12 9:42am    
You should definitely delete this answer. This is not an answer and is showing other CP members that your question has two answers, making it more difficult that they will come here to give you another answer...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900