Discussion: yes/no dialog
Afficher un message
Vieux 25/10/2006, 23h08   #3
Michael Kolakowski
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] yes/no dialog

Ken,

Ha ha...I'm used to programming c++, c, python, etc...not web stuff.
Thanks so much for the . I really appreciate it. It ed point
me in the right direction with forms and submit buttons. However, I
really wanted the pop up dialog, and not just buttons like you have
below. Well, I finally solved it! Here's what I did (this might be of
use to others):

1. My Smarty template has the logic for the drop down select boxes
2. After selecting and clicking the button, the form submits
3. The php code gets the values and does some work
4. Then the php code uses smarty->assign to set a 'flag' variable
5. The Smarty template reloads again
6. INSIDE THE FORM, a Smarty {if} catches the flag variable
7. inside the if block, a javascript 'confirm' dialog is launched
8. If they click 'OK' then javascript does document.write() to a hidden
variable, a flag
9. Then javascript calls form.submit() to submit the form again, WITH
THE HIDDEN VARIABLE
10. The php code runs yet again, but this time picking up the hidden
variable as well
11. I can then execute my sql statement with confidence!

Whew! Please note: this entire time I am having the page POST to
itself. What do you think? I'm pretty proud of getting it to work,
having only a couple weeks of php and smarty experience and a few hours
of javascript experience. </bragging>

Take care,
Michael Kolakowski



Ken Snyder wrote:
> Hello Michael,
>
> You've just discovered the perils of programming in a stateless
> environment. :P Generally, the way to overcome the limitations of
> stateless environments is to store data in php's $_SESSION superglobal
> array ({$smarty.session} in smarty). Also, in the web 2.0
> environment, Ajax is also used often.
>
> For this situation, however, something simpler may work for you:
>
>
>
> <?php
> if( isset($_POST['request']) || isset($_POST['i_am_sure']) ) {
> if( $willBeOverwritten==false || isset($_POST['i_am_sure']) ) {
> // do sql
> } else {
> $smarty->assign('ask_if_sure',true);
> }
> }
> ?>
> ...
> <form action="{$smarty.server.PHP_SELF}" method="post">
> Requested Operation:
> <input type="text" name="requested_operation"
> value="{$smarty.post.requested_operation}" />
> {if $ask_if_sure}
> Do you really want to overwrite?
> <input type="submit" name="i_am_sure" value="Yes" />
> <input type="submit" name="cancel" value="No" />
> {else}
> <input type="submit" name="request" value="Do It" />
> {/if}
> </form>
>
>
>
> Basically php checks of data would be overwritten, and if so, loads
> the page again with all the data as the user just filled out, but asks
> "Are you sure." Then, once the request is submitted again (using the
> "i_am_sure" submit button), the script will go ahead and overwrite the
> data.
>
> --Ken
>
>
> Michael Kolakowski wrote:
>> Hi,
>>
>> I am new to both PHP and Smarty. Also new to JavaScript, for that
>> matter. Anyhow, I am trying to create a yes/no dialog and am
>> having a lot of trouble. Could I please get some ?
>>
>> My php code looks a little like this:
>>
>> if($variable != NULL)
>> {
>> //do a sql insert statement here
>> }
>> else
>> {
>> //ask user if they really want to 'overwrite' <-- yes/no goes
>> here!!
>>
>> //if yes, then do sql update statement
>> //else, do nothing
>> }
>>
>> So, I want the yes/no dialog to pop up in that else block. Using
>> JavaScript was suggested, but I have not been able to figure out how
>> to get the value of the yes/no (I got the pop-up by using a php print
>> statement). In addition, I have a number of variables above the if
>> block that are used for the sql statements. I don't want to 'lose'
>> these variable due to POST or whatever else. I'd also like to avoid
>> complex logic to pass them around between the template and php
>> files. Ideas?
>>
>> Thanks,
>> Michael Kolakowski
>> HPC-1
>>

>

  Réponse avec citation
 
Page generated in 0,22821 seconds with 9 queries