Forum Moderators: coopster & phranque

Message Too Old, No Replies

form in pul to .pl mail script

Getting a .pl mail script to send the right numbers of form fields

         

hafnius

2:32 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



Hi all

I am designing the interface to a newsletter whereby an assistent have a form where he/she can have a prewritten header and footer and then chooses have many items there should be in the newsletter by using a jump menu. so that the right number of input form fields are shown dynamically 1 to 4 headline/content pairs like this:

header

headline1
content1

headline2
content2

...
...

footer

This gets sent to the .pl script which puts $header, footer in the DB and sends out the email.

The problem is how do i refer to the headline/content pairs in the .pl script $headline, $content wont work as they are numbered 1-4. it has to work dynamic somehow.

in my .pl i have at the top:

my $header = $q->param('header');
my $footer = $q->param('footer');

but how do i include the headline/content pairs in this?
- both in the email and when i insert into the DB - i guess that the right solution solves both probs.

I hope i have explainet it clearly enough.

if you guys have a smarter way of achieving this i would be all ears.

Kind Regards
/Hafnius

MichaelBluejay

8:03 pm on Jun 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't really understand what you're asking.

1. Where is the content coming from? The database? The assistant typing it in? If the assistant is typing it in, is (s)he typing it into the form that calls the script?

2. What do you mean a "jump" menu? A jump menu takes you to another page, but that doesn't seem to be what you're saying. Do you mean a <SELECT> menu?

3. If you mean a <SELECT> menu, what exactly are the choices in the <SELECT> menu? Just numbers, like 1, 2, 3, 4, 5?

4. What do you want to happen when the user chooses an item from the <SELECT> menu, before they hit the SUBMIT button? Anything?

5. What fields does the form have? What is the HTML of the form?

6. What fields does your database have?

Rather than answering these questions individually, maybe you could rephrase your whole question. When I come to this forum I look for any question that doesn't already have a reply to see if I can answer it, but those are rare. If a question has been here for several hours and hasn't been answered yet it's usually because nobody could understand the question. I'll see if I can help you if I can understand better what you're trying to do.

hafnius

11:02 am on Jun 18, 2004 (gmt 0)

10+ Year Member



Hi MichaelBluejay

thanx for your heads up. usually when a question others dont understand are posted its because the one who is asking the question doesnt understand it. This is the case here - so i will try again since i think i have a better understanding now.

Simplified:
I have a html form like this:


<form method=post action=script.pl>
<input type=text name=email>your email</input>
<input type=text name=news[1][1]>headline 1</input>
<input type=text name=news[1][2]>text 1</input>
<input type=text name=news[2][1]>headline 2</input>
<input type=text name=news[2][2]>text 2</input>
</form>

etc...

The question is now how do i acces the fields in the .pl script. The email field is easy enough - it simply becomes $email and i can put it in the db and mail it - this part works fine.

The prob is the headline/text pairs. How do i access them in the script - both for mailing them and putting them in the db. I havent yet made the mysql fields for this but i expect it to be evident when i find out how to access them.

I have found out that an array in perl is indicated by the @ sign so i could maybe do something like this to iterate through the array:

foreach $i (@news) { do something; }

what is importent in the array construct is that the right headline is paired with the right text of course. the array i have made in the form is just how i picture it. Maybe i am making it more complicated then it has to be - i dont know. But i certainly hope this is much clearer :)

Kind Regards
/Hafnius

VectorJ

2:22 pm on Jun 18, 2004 (gmt 0)

10+ Year Member



I'm not sure how you're receiving the values of the form in your script, but I doubt that making the form field names look like a perl array will make them actually come out as an array in the perl script, and that appears to be the problem here. I think you should just rename the form fields as headline1, content1, headline2, content2 and access them the same way you do the email field: $email, $headline1, $content1, $headline2, $content2.

MichaelBluejay

1:25 am on Jun 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Okay, I understood that a lot better. First of all, I seriously doubt you can use bracket characters in your field names, though I haven't tested it. Why don't you just use "name=news11", "name=news12", etc.?

hafnius

4:06 pm on Jun 19, 2004 (gmt 0)

10+ Year Member



Hi VectorJ and MichaelBluejay

Well you are both suggesting the same - that i drop the array thingy and just name them headline1 content1, etc.

I just had the idea that there had to be a better solution than this but i guess this i where i should stick with KISS.

I will try with this approach and just check the formfields for content with conditionals. I havent forund a way of putting it into the DB when i choose this solution but thats a different post..

Thanx for your thougts :)

Kind Regards
/Hafnius