Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pop out to get more info

Status
Not open for further replies.

MikeM2468

IS-IT--Management
Apr 5, 2011
100
US
I'm submitting a form to an update script. After the form is submitted, and depending on what is submitted, more information may be needed by the update script. How can I create a popup form that will pause script execution, get more information (from dropdown boxes), then take the info back to the script to continue processing?
 
Short Answer: You can't. You can't pause a PHP script mid execution like that.


Long answer:
What you can do is validate client side what the user has selected in your form, and act accordingly to request for info from them if they select something that requires more information.

alternatively you could use ajax to call the PHP script, and if it needs more information, have it return the request once its done processing. Then you can act accordingly to the request and re-submit all the information to the script including the original selections and whatever else may have been required.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
I was looking at ajax. I have it working in small doses, but I'm not that familiar with it. I can't use client side, because the determining factor as to whether more information is needed comes from MySQL queries based on the form submission. Basically, if x=1, continue, but if x=2 ask for more information, then continue.
 
Basically to go the ajax route, you would use it to send your form data over to your processing script, and then it would return whatever value you want to signal the requirement of more information.

Your HTML for requesting may already be present in your client page but hidden, and only becomes visible when your ajax call sends back a specific value. Or it may get sent back from the processing script for you to display.

You are going to have to draw out your flow so you know how you need to proceed.

For instance, here's a small example which shows an extra input when a specific option in a dropdown is selected.
Code:
[COLOR=#990000]<?php[/color]
[b][COLOR=#0000FF]switch[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$_GET[/color][COLOR=#990000][[/color][COLOR=#FF0000]'val'[/color][COLOR=#990000]])[/color]
[COLOR=#FF0000]{[/color]
[tab][b][COLOR=#0000FF]case[/color][/b] [COLOR=#FF0000]'1'[/color][COLOR=#990000]:[/color] [b][COLOR=#0000FF]case[/color][/b] [COLOR=#FF0000]'2'[/color][COLOR=#990000]:[/color]
[tab][tab][b][COLOR=#0000FF]echo[/color][/b] [COLOR=#FF0000]'none'[/color][COLOR=#990000];[/color]
[tab][b][COLOR=#0000FF]break[/color][/b][COLOR=#990000];[/color]
[tab][b][COLOR=#0000FF]case[/color][/b] [COLOR=#FF0000]'3'[/color][COLOR=#990000]:[/color]
[tab][tab][b][COLOR=#0000FF]echo[/color][/b] [COLOR=#FF0000]'block'[/color][COLOR=#990000];[/color]
[tab][b][COLOR=#0000FF]break[/color][/b][COLOR=#990000];[/color]
[tab][b][COLOR=#0000FF]default[/color][/b][COLOR=#990000]:[/color]
[tab][tab][b][COLOR=#0000FF]echo[/color][/b] [COLOR=#FF0000]'none'[/color][COLOR=#990000];[/color]
[tab][b][COLOR=#0000FF]break[/color][/b][COLOR=#990000];[/color]
[COLOR=#FF0000]}[/color]   
[COLOR=#990000]?>[/color]

This simply takes a value sent to it through GET and and sends something back based on that value.

The HTML is very simple, our extra info box would start out hidden, by setting its display to none in its CSS.
Code:
[b][COLOR=#0000FF]<select[/color][/b] [COLOR=#009900]name[/color][COLOR=#990000]=[/color][COLOR=#FF0000]"options"[/color] [COLOR=#009900]onchange[/color][COLOR=#990000]=[/color][COLOR=#FF0000]"submitSelect(this);"[/color][b][COLOR=#0000FF]>[/color][/b]
[b][COLOR=#0000FF]<option[/color][/b] [COLOR=#009900]value[/color][COLOR=#990000]=[/color][COLOR=#FF0000]1[/color][b][COLOR=#0000FF]>[/color][/b]One[b][COLOR=#0000FF]</value>[/color][/b]
[b][COLOR=#0000FF]<option[/color][/b] [COLOR=#009900]value[/color][COLOR=#990000]=[/color][COLOR=#FF0000]2[/color][b][COLOR=#0000FF]>[/color][/b]Two[b][COLOR=#0000FF]</value>[/color][/b]
[b][COLOR=#0000FF]<option[/color][/b] [COLOR=#009900]value[/color][COLOR=#990000]=[/color][COLOR=#FF0000]3[/color][b][COLOR=#0000FF]>[/color][/b]Three[b][COLOR=#0000FF]</value>[/color][/b]
[b][COLOR=#0000FF]</select>[/color][/b]
[b][COLOR=#0000FF]<br[/color][/b] [COLOR=#009900]style[/color][COLOR=#990000]=[/color][COLOR=#FF0000]"clear:both;"[/color][b][COLOR=#0000FF]>[/color][/b]
[tab][b][COLOR=#0000FF]<div[/color][/b] [COLOR=#009900]id[/color][COLOR=#990000]=[/color][COLOR=#FF0000]"extrainfo1"[/color] [COLOR=#009900]class[/color][COLOR=#990000]=[/color][COLOR=#FF0000]"extrainfo"[/color][b][COLOR=#0000FF]>[/color][/b]
[tab][tab][b][COLOR=#0000FF]<span>[/color][/b]Extra Info:[b][COLOR=#0000FF]</span>[/color][/b][tab][b][COLOR=#0000FF]<input[/color][/b] [COLOR=#009900]type[/color][COLOR=#990000]=[/color][COLOR=#FF0000]"text"[/color] [COLOR=#009900]name[/color][COLOR=#990000]=[/color][COLOR=#FF0000]"extrainfo"[/color][b][COLOR=#0000FF]>[/color][/b]
[tab][b][COLOR=#0000FF]</div>[/color][/b]

And this the JS that would contact the PHP page, and wait for a response, and then show the extra input if needed. You can have ti so it displays a message when no further action is required.

Code:
[b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]submitSelect[/color][/b][COLOR=#990000]([/color]ddObj[COLOR=#990000])[/color]
[COLOR=#FF0000]{[/color]
[tab]
[tab][b][COLOR=#000000]ajaxCall[/color][/b][COLOR=#990000]([/color]ddObj[COLOR=#990000].[/color]value[COLOR=#990000]);[/color]  
[COLOR=#FF0000]}[/color]   
[b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]toggleExtraInfo[/color][/b][COLOR=#990000]([/color]statusVar[COLOR=#990000])[/color]
[COLOR=#FF0000]{[/color]
[tab]
[tab][b][COLOR=#000000]alert[/color][/b][COLOR=#990000]([/color]statusVar[COLOR=#990000]);[/color]
[tab]document[COLOR=#990000].[/color][b][COLOR=#000000]getElementById[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]"extrainfo1"[/color][COLOR=#990000]).[/color]style[COLOR=#990000].[/color]display[COLOR=#990000]=[/color]statusVar[COLOR=#990000];[/color]  
[tab]
[tab]
[COLOR=#FF0000]}[/color]


[b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]ajaxCall[/color][/b][COLOR=#990000]([/color]theValue[COLOR=#990000])[/color]
[COLOR=#FF0000]{[/color]
[tab]
[tab][b][COLOR=#0000FF]var[/color][/b] xmlhttp[COLOR=#990000];[/color]

[tab]xmlhttp[COLOR=#990000]=[/color][b][COLOR=#0000FF]new[/color][/b] [b][COLOR=#000000]XMLHttpRequest[/color][/b][COLOR=#990000]();[/color]

[tab]xmlhttp[COLOR=#990000].[/color]onreadystatechange[COLOR=#990000]=[/color][b][COLOR=#0000FF]function[/color][/b][COLOR=#990000]()[/color]
[tab][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color]xmlhttp[COLOR=#990000].[/color]readyState[COLOR=#990000]==[/color][COLOR=#993399]4[/color] [COLOR=#990000]&&[/color] xmlhttp[COLOR=#990000].[/color]status[COLOR=#990000]==[/color][COLOR=#993399]200[/color][COLOR=#990000])[/color]
[tab][tab][COLOR=#FF0000]{[/color]
[tab][tab][tab][b][COLOR=#000000]toggleExtraInfo[/color][/b][COLOR=#990000]([/color]xmlhttp[COLOR=#990000].[/color]responseText[COLOR=#990000]);[/color]
[tab][tab][COLOR=#FF0000]}[/color]
[tab][COLOR=#FF0000]}[/color]
xmlhttp[COLOR=#990000].[/color][b][COLOR=#000000]open[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]"GET"[/color][COLOR=#990000],[/color][COLOR=#FF0000]"ProcessingScript.php?val="[/color] [COLOR=#990000]+[/color] theValue[COLOR=#990000],[/color][b][COLOR=#0000FF]true[/color][/b][COLOR=#990000]);[/color]

xmlhttp[COLOR=#990000].[/color][b][COLOR=#000000]send[/color][/b][COLOR=#990000]();[/color]
[COLOR=#FF0000]}[/color]




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
I think I'll take a different approach. I'll push the ids for the items that need more info into an array, then carry that into another form after the other items are processed. There I can construct the form based on the information needed, maybe with ajax for dynamic update.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top