Skip to main content
Known Participant
March 31, 2010
Answered

Is it possible to change submit button's URL link based on user input?

  • March 31, 2010
  • 1 reply
  • 1363 views

I have a separate html page that does this with a php script, but I had help creating that php file which is just a form that allows users to enter a passcode that I provide them which will then simply link them to an external html page.  Since I don't know about php, I am thinking a possible work around would be to have a text input box which would allow a user to enter (passwordA) then click Submit to load (pageX.hmtl) or they could enter (passwordB) and Submit would load (pageY.html).  

If anyone knows how I could link my new flash project with my .php file, that would be great, or if there is AS3 code that would do this I would love that!

This topic has been closed for replies.
Correct answer kglad

You are correct in saying that I'm not concerned with security here.  To be honest, I just want to hide the amount of clients I have from the average user.  Doing it all in flash was the direction I was going with my initial post, but seeing as how I have a php file doing the trick elsewhere, I thought that would be a good way to go. 

I can mark this thread as answered, but I will probably seek more help in how exactly to code the "if / else" statements to determine the navigateToURL()

Thanks for the help kglad!


use:

submit_btn.addEventListener(MouseEvent.CLICK,navF );


function navF(event:MouseEvent):void{

if(passcode_txt.text=="passwordA"){

navigateToURL(new URLRequest("http://www.site1.com"));

} else {

navigateToURL(new  URLRequest("http://www.site2.com"));

}

}

1 reply

kglad
Community Expert
Community Expert
March 31, 2010

you mean you want to bypass your php file?


music3000Author
Known Participant
March 31, 2010

I am having a difficult time getting Flash to communicate with the php file that currently exists (pasted below for reference)  Ideally my Flash project would utilize that php file, or a slight variation thereof.  If I could get help making that happen, I would be grateful, but I am just trying to find a way around doing that because I can't figure that out.  Here is my flash project: http://www.jmusicphoto.com/fullscreen8_contact.php  If you click on the Client Access button, you can see the start of my form.  I simply want to instruct the user to enter their specific gallery code, then have the submit button link them into their gallery based on the code they input.

the php file:


<?php

/*
First off, we check to see if their is a submission for 'key'.
The form, which will call itself, will populate this when it is submitted.
If the form wasn't submitted this whole block will be ignored and the form will show.

It is important that the code go first because if we use php header redirection nary
a character can be output before the redirection takes place.
*/
if($_REQUEST['key']) {

     //now that we know it exists, deposit the key into a variable that is easier to type
     $key = $_REQUEST['key'];


     //switch is case sensitive, Banana, banana and banAna would all be different cases
     //strtolower() is a handy function that will take our string and force lower
     //case on every character.  If you want case-sensitivity leave this out
     $key = strtolower($key);


     
     //now that we have key, we need to compare it to all valid values, the switch statement
     //will make this fairly easy
     switch($key) {
          //add a case statement for every possible correct entry
          case 'passwordA':
               header('Location: http://www. randomsite. com/pageY.html');          
               break;
          case 'passwordB':
               header('Location: http://www. randomsite. com/pageY.html');          
               break;
          
          default:
               echo "Oh noes!  You got something wrong.  You typed " . $key . " maybe there is a mistake?<br><br>";
               break;
     }
}
?>

<!--
The form will call itself, so the action needs to be the same filename as this file.
It will pass along the key for our above function to check
-->
<form name='theform' action='thisfile.php'>
     <input type="text" name="key" />
    <input type="image" name="submit" src="submit.gif" border='0' style='vertical-align:top' width="100" height="20">
</form>
kglad
Community Expert
Community Expert
March 31, 2010

if your php file is in a different domain from the domain that hosts your swf, you'll need a cross-domain security file.  can you place one on the server that hosts your php file?