6 Replies - 793 Views - Last Post: 09 May 2014 - 11:05 AM Rate Topic: -----

#1 kyle_denney  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 171
  • Joined: 10-August 12

Changing Label from External PHP File

Posted 07 May 2014 - 08:04 PM

Hello,

I currently have a form that I am posting data from to an external PHP file that redirected to an included file outside of the root of my main folder. However, I am not sure how to go about changing a label back on the original form posting page. In other words, I would like to validate the data on the form in an external file so that it is secure using a database. Once I validate the data if anything is an error I would like to change an label on the form showing the error or change the label saying the form submission was a success. I currently do Javascript validation but would also like to use PHP to confirm on the server side as well. Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: Changing Label from External PHP File

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5078
  • View blog
  • Posts: 13,705
  • Joined: 18-April 07

Re: Changing Label from External PHP File

Posted 07 May 2014 - 10:33 PM

Well normally you would just redirect from the validation script back to your form (maybe passing a parameter along with it). If the original form does a check for this variable's existence, then it knows that an error occurred and you can print a message accordingly...

if (isset($_GET['error']) {
    // print some message saying that an error occurred
}



Then of course from your validation script if something went wrong you would do a header redirect header("Location: oringalform.php?error=2");

That is one way you could do it. :)
Was This Post Helpful? 0
  • +
  • -

#3 kyle_denney  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 171
  • Joined: 10-August 12

Re: Changing Label from External PHP File

Posted 08 May 2014 - 05:36 AM

So in the portion you are saying to use a GET it would be because you are passing something back from the script in your redirect and I get that. (Although I did not know header redirects could have variables - good to know). So how would you say change a label? Would you do something along the lines of 1
<input type="text" name="something" value="<?=$php-variable-goes-here-that-is-the-[GET]-variable?>"/>
then the question is how does the html form's php know that what I am passing back to it in the GET is correct? Is it just because of the name or do I need to do it as a session variable? Thanks for the input and feedback.

This post has been edited by andrewsw: 09 May 2014 - 10:58 AM
Reason for edit:: Removed unnecessary previous post

Was This Post Helpful? 0
  • +
  • -

#4 kyle_denney  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 171
  • Joined: 10-August 12

Re: Changing Label from External PHP File

Posted 09 May 2014 - 10:30 AM

Thanks! That seemed to have worked. However, do you know how to style the element? It seems when using echo from PHP to spit out the variable that when I apply CSS via a code behind file it does not want to style the text itself. Here is the html:

	<div id="loginpara2">
	<p id="test"><?php echo $_GET['error']; ?> </p>
	</div>




and part of the CSS

#loginpara2 {
    margin-left: 8%;
    color: red;
}


Was This Post Helpful? 0
  • +
  • -

#5 grizrule  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 88
  • Joined: 29-December 13

Re: Changing Label from External PHP File

Posted 09 May 2014 - 10:54 AM

With that CSS you are styling the div. You could take out the div and have this css:

#test {
    margin-left: 8%;
    color: red;
}


The CSS above will style the #test paragraph with a left margin of 8% of its container and style the text red.

You could also leave the div and have this CSS:

#loginpara2 {
    margin-left: 8%;
}

#test {
    color: red;
}


The CSS above will make the div have a left margin of 8% of its container and the error, or anything within the #test paragraph, will be red.

This post has been edited by grizrule: 09 May 2014 - 11:04 AM

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • say what now
  • member icon

Reputation: 6409
  • View blog
  • Posts: 25,903
  • Joined: 12-December 12

Re: Changing Label from External PHP File

Posted 09 May 2014 - 11:00 AM

View Postgrizrule, on 09 May 2014 - 05:54 PM, said:

With that CSS you are styling the div. You could take out the div and have this css:

#test {
    margin-left: 8%
    color: red;
}

That css is missing a semi-colon.
Was This Post Helpful? 0
  • +
  • -

#7 grizrule  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 88
  • Joined: 29-December 13

Re: Changing Label from External PHP File

Posted 09 May 2014 - 11:05 AM

Thanks for noticing that Andrew. Fixed now.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1