How do I echo different forms for different selected options

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adsegzy
Forum Contributor
Posts: 184
Joined: Tue Jul 28, 2009 9:26 am

How do I echo different forms for different selected options

Post by adsegzy »

Hello there,

Am developing a site where members can add events. On the
add_event.php
page, the only field is Event Type (which includes Seminar, Wedding, Birthday, etc). The form for Seminar is different from the form for wedding etc. On selecting the type of event they want to add, I want the form for the selected event type to appear below the Event Type field without refreshing or redirecting the page. How do I do it? Can only php scripts do this or i'll need other languages like javascript etc?

Thanks in advance
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: How do I echo different forms for different selected opt

Post by califdon »

You've got it. If you want to do anything to a web page after sending it to the browser, it can't be done with PHP because the server is all done now. That's what AJAX does, which is a way for Javascript in the browser to send an asychronous request to the server to ask for data to be sent to the browser's Javascript callback function, which then uses the data in some way to modify the existing page.

But if the first appearance of the page has only a small amount of content, such as one form field and a submit button, I'd suggest that you consider actually sending a new page with the appropriate form. You're going to have to send a lot of data anyway, I doubt that you would see much difference in what the user sees, whether you use AJAX or just submit the Event Type to the server which then sends the specific form page. I think I'd probably do it that way.
Post Reply