Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

URL redirect code for submit button

General discussions related to php

Moderators: macek, egami, gesf

URL redirect code for submit button

Postby scoobysteve » Tue Nov 06, 2012 12:28 pm

Hey folks is there any easy way that I can add code to the following code to create a redirect to an external URL

<input type="submit" value="<?php echo $PLS_LANG['front_register_submit']; ?>" onclick="return VRL.Utils.submitRegistrationForm('frmPLRegister');" />

Thanks in advance
Steve
scoobysteve
New php-forum User
New php-forum User
 
Posts: 13
Joined: Thu May 31, 2012 1:08 am

Re: URL redirect code for submit button

Postby seandisanti » Wed Nov 07, 2012 3:27 pm

I'm not sure i'm understanding what you're asking.... if you mean you want your form to submit to another site, you can just set your action attribute to be the page receiving the form submission. if you want to process the submission locally and then redirect, the way that i do all redirects is in a functions.php that i require first in every script. in that script, i have this function:
Code: Select all

function redirect_to( $location = NULL ) {
   if ($location != NULL) {
      header("Location: {$location}");
      exit;
      }
   }
that way I can just call that function to send the user wherever
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 783
Joined: Mon Oct 01, 2012 12:32 pm

Re: URL redirect code for submit button

Postby scoobysteve » Thu Nov 08, 2012 1:44 am

Thank you for your reply, I need the form data to be entered into the normal page but then divert to a external url, I think I understand what your saying, but where in the existing code are the changes to be make to call this page,

what needs to be entered into this code to call the php page you mention,

<input type="submit" value="<?php echo $PLS_LANG['front_register_submit']; ?>" onclick="return VRL.Utils.submitRegistrationForm('frmPLRegister');" />

So I create a php page called direct.php and in that page I put your code is that correct.

Sorry I am a newbie so please excuse my ignorance.

Kind Regards
Steve
scoobysteve
New php-forum User
New php-forum User
 
Posts: 13
Joined: Thu May 31, 2012 1:08 am

Re: URL redirect code for submit button

Postby seandisanti » Thu Nov 08, 2012 9:29 am

No worries man. If the external url is to process the form data, just do it like this;

Code: Select all
<form action="http://seandisanti.com/tryit.php" method="post">
   <input type="text" name="echoString" />
   <input type="submit" />
</form>

that code works if you want to see a cross site submission


***edit***
also, here's the code for the page at seandisanti.com/tryit.php

Code: Select all
<?php
   echo (isset($_POST['echoString']))?strip_tags($_POST['echoString']):'You must post a variable named echoString to have it displayed';
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 783
Joined: Mon Oct 01, 2012 12:32 pm

Re: URL redirect code for submit button

Postby scoobysteve » Thu Nov 08, 2012 11:12 am

Thanks for your response, I am really sorry I am being really thick here, the redirect is only to a static page, there is no external processing. BUT the script I posted has to run on the server to add the data from the form to the database.

The below script cant change as I dont think the data will be added as it should be, I was hoping that it could be modified a little or have a little bit added onto it to allow for a redirect after it has processed the form data, I dont see this code anywhere on the snippets you have posted so I am really confused as to where your code should be, I am sorry this is probably getting to hard for me to understand. I just thought that maybe it was just a extra piece of code to be added so after the data was processed it directed to a static html page I needed which was on another url location.

I am trying to improve on a vacation rental script I purchased, because on the existing logon/register page. if a new user registers after they hit submit the page doesn't do anything, so its confusing to the new user that all they need to do is login, if it diverted away they would at least know something had happened.

Sorry to be a pain if this is too much to ask I understand and thanks for your input so far. Steve

<input type="submit" value="<?php echo $PLS_LANG['front_register_submit']; ?>" onclick="return VRL.Utils.submitRegistrationForm('frmPLRegister');" />
scoobysteve
New php-forum User
New php-forum User
 
Posts: 13
Joined: Thu May 31, 2012 1:08 am

Re: URL redirect code for submit button

Postby seandisanti » Thu Nov 08, 2012 1:06 pm

without seeing your code, i can't really tell you what changes would be necessary. if you put the redirect_to() function from my first response in a file named functions.php, and then do require('functions.php'); as the first line of your html form page then you'll be able to call redirect_to at any point in your page.

i would just write a function to do your database work, and then have that function call the redirect on success...
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 783
Joined: Mon Oct 01, 2012 12:32 pm

Re: URL redirect code for submit button

Postby scoobysteve » Sat Nov 10, 2012 2:32 am

OK man,

thanks for having a go for me, much appreciated, I have attached the php file that contains the submit button code just in case you can see anything easy, sorry to be a pain it would be really nice to sort this of poss.

By the way had to rename the file did not like php files as you can imagine. OK it would not let me upload any txt, pdf files so here is the code on the page it is below.

Cheers
Steve

<div class="property-container">

<?php
include_once VIEWS_PATH . 'Listings/elements/layout_1/menu.php';
?>

<div class="property-search-empty property-heading"><?php echo $PLS_LANG['front_login_title']; ?></div>

<form action="<?php echo BASE_PATH;?>index.php?controller=Admin&amp;action=login" method="post" target="_blank" class="property-search-form" name="frmPLLogin">
<input type="hidden" name="login_user" value="1" />

<?php
if (isset($_GET['iframe']))
{
?><input type="hidden" name="iframe" value="" /><?php
}
?>

<div class="property-search property-search-left">
<p>
<label><?php echo $PLS_LANG['front_login_username']; ?>:</label>
<input type="text" name="login_username" id="login_username" value="<?php echo isset($_GET['login_username']) ? htmlspecialchars(stripslashes($_GET['login_username'])) : NULL; ?>" class="property-text property-text-medium" />
</p>
<p>
<label><?php echo $PLS_LANG['front_login_password']; ?>:</label>
<input type="password" name="login_password" id="login_password" value="<?php echo isset($_GET['login_password']) ? htmlspecialchars(stripslashes($_GET['login_password'])) : NULL; ?>" class="property-text property-text-medium" />
</p>
</div>

<div class="clear_left"></div>

<input type="submit" value="<?php echo $PLS_LANG['front_login_submit']; ?>" onclick="return VRL.Utils.submitLoginForm('frmPLLogin');" />
</form>

<br/>
<br/>

<div class="property-search-empty property-heading"><?php echo $PLS_LANG['front_register_title']; ?></div>

<?php
if (isset($_GET['err']))
{
switch ($_GET['err'])
{
case 9999:
?><p class="status_success"><?php echo $PLS_LANG['status'][9999]; ?></p><?php
break;
case 9998:
?><p class="status_success"><span>&nbsp;</span><?php echo $PLS_LANG['status'][9998]; ?></p><?php
break;
case 9997:
?><p class="status_err"><span>&nbsp;</span><?php echo $PLS_LANG['status'][9997]; ?></p><?php
break;
}
}
?>

<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="get" class="property-search-form" name="frmPLRegister">
<input type="hidden" name="controller" value="Listings" />
<input type="hidden" name="action" value="add" />
<input type="hidden" name="listing_register" value="1" />

<?php
if (isset($_GET['iframe']))
{
?><input type="hidden" name="iframe" value="" /><?php
}
?>

<div class="property-search property-search-left">
<p>
<label><?php echo $PLS_LANG['front_register_username']; ?>:</label>
<input type="text" name="register_username" id="register_username" value="<?php echo isset($_GET['register_username']) ? htmlspecialchars(stripslashes($_GET['register_username'])) : NULL; ?>" class="property-text property-text-medium" />
</p>
<p>
<label><?php echo $PLS_LANG['front_register_password']; ?>:</label>
<input type="password" name="register_password" id="register_password" value="<?php echo isset($_GET['register_password']) ? htmlspecialchars(stripslashes($_GET['register_password'])) : NULL; ?>" class="property-text property-text-medium" />
</p>
<p>
<label><?php echo $PLS_LANG['front_register_password_repeat']; ?>:</label>
<input type="password" name="register_password_repeat" id="register_password_repeat" value="<?php echo isset($_GET['register_password_repeat']) ? htmlspecialchars(stripslashes($_GET['register_password_repeat'])) : NULL; ?>" class="property-text property-text-medium" />
</p>
<p>
<label><?php echo $PLS_LANG['front_register_name']; ?>:</label>
<input type="text" name="name" id="name" value="<?php echo isset($_GET['name']) ? htmlspecialchars(stripslashes($_GET['name'])) : NULL; ?>" class="property-text property-text-medium" />
</p>
<p>
<label><?php echo $PLS_LANG['front_register_email']; ?>:</label>
<input type="text" name="email" id="email" value="<?php echo isset($_GET['email']) ? htmlspecialchars(stripslashes($_GET['email'])) : NULL; ?>" class="property-text property-text-medium" />
</p>
</div>

<div class="clear_left"></div>

<input type="submit" value="<?php echo $PLS_LANG['front_register_submit']; ?>" onclick="return VRL.Utils.submitRegistrationForm('frmPLRegister');" />


</form>
</div>
scoobysteve
New php-forum User
New php-forum User
 
Posts: 13
Joined: Thu May 31, 2012 1:08 am


Return to PHP General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron