/    Sign up×
Community /Pin to ProfileBookmark

What am I doing wrong here?

Hey!

I hope you can help please.

I have just finished making a ticket system, which is working great, but the one annoying thing that happens is that data is lost. Our validation is done by a .php script, and if there are errors and the user clicks their Back button, the data is lost.

Therefore I’m trying to save it… using:

(in my .php page the data is submitted to)

[code=php]
$direct_name = $_POST[‘NAME’];
$direct_email = $_POST[‘EMAIL’];
[/code]

Then in the actual form itself…

[code=php]
<input type=”text” name=”NAME” class=”formwidth” maxlength=”32″ <?php echo (isset($direct_name) ? “value=”$direct_name”” : ”); ?> />
[/code]

I don’t get any errors, but it simply doesn’t work.

I looked at my phpinfo, and see that:

[code]register_globals On On[/code]

Thanks!

to post a comment
PHP

23 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Feb 28.2007 — Try this instead:[code=php]<input type="text" name="NAME" class="formwidth" maxlength="32" value="<?php echo (isset($direct_name) ? $direct_name : ""); ?>" />[/code]
Copy linkTweet thisAlerts:
@MrCoderFeb 28.2007 — Try this instead:[code=php]<input type="text" name="NAME" class="formwidth" maxlength="32" value="<?php echo (isset($direct_name) ? $direct_name : ""); ?>" />[/code][/QUOTE]

Shouldn't that be..

[code=php]<input type="text" name="NAME" class="formwidth" maxlength="32" value="<?php echo (isset($direct_name)) ? $direct_name : ""; ?>" />[/code]
Copy linkTweet thisAlerts:
@NightShift58Feb 28.2007 — Shouldn't that be..[/QUOTE]They are functionally equivalent. The following should all do the same:[code=php]<?php
$direct_name = "Mr. Coder";
?>
<input type="text" name="NAME" class="formwidth" maxlength="32" value="<?php echo (isset($direct_name) ? $direct_name : ""); ?>" />
<br>
<input type="text" name="NAME" class="formwidth" maxlength="32" value="<?php echo ((isset($direct_name)) ? $direct_name : ""); ?>" />
<br>
<input type="text" name="NAME" class="formwidth" maxlength="32" value="<?php echo (isset($direct_name)) ? $direct_name : ""; ?>" />
<br>
<input type="text" name="NAME" class="formwidth" maxlength="32" value="<?php echo isset($direct_name) ? $direct_name : ""; ?>" />
[/code]
Copy linkTweet thisAlerts:
@MrCoderFeb 28.2007 — Its true what they say, you indeed do learn something new every day!
Copy linkTweet thisAlerts:
@prophitMar 01.2007 — you can also use,
<i>
</i>$direct_name = htmlentities($_POST['NAME']);
$direct_email = htmlentities($_POST['EMAIL']);

&lt;input type="text" name="NAME" class="formwidth" maxlength="32" value="&lt;?php echo 'htmlspecialchars(stripslashes($direct_name))'; ?&gt;" /&gt;

Copy linkTweet thisAlerts:
@DanUKauthorMar 03.2007 — Hi there ?

Thanks for your replies.

I still can't get this working, if I click the back button, nothing is populated and I still see value="" in the source

Am I setting them wrong with the $direct_name = ..?

Thanks!
Copy linkTweet thisAlerts:
@prophitMar 03.2007 — post your code.

I'll test it on my server and make any adjustments and repost it for you
Copy linkTweet thisAlerts:
@prophitMar 03.2007 — Bettery Yet
<i>
</i>
&lt;?php
$direct_name = htmlentities($_POST['NAME']);
$direct_email = htmlentities($_POST['EMAIL']);
?&gt;
&lt;input type="text" name="NAME" class="formwidth" maxlength="32" value="&lt;?php echo htmlspecialchars(stripslashes($direct_name)); ?&gt;" /&gt;
&lt;input type="text" name="email" class="formwidth" maxlength="32" value="&lt;?php echo htmlspecialchars(stripslashes($direct_email)); ?&gt;" /&gt;
Copy linkTweet thisAlerts:
@Paul_JrMar 03.2007 — If you need the values to be available when you go [i]back[/i] to the form page [i]from[/i] the page that processes the form, you'll need to carry the values back with sessions or redirect back to the page and pass the values through the URL in a query string.

I'm assuming the form and the processing script are [i]not[/i] on the same page, correct?
Copy linkTweet thisAlerts:
@DanUKauthorMar 03.2007 — Hi ? thank you

They're not on the same page, I have a form.php (html page) and the goform.php as the processor. I have the lines which set the $_POST data to the sessionon goform.php (the $direct_name = htmlentities($_POST['NAME'])?

Should they be on the actual form itself?
Copy linkTweet thisAlerts:
@prophitMar 03.2007 — yes. I have a few scripts that i have it on both just to be sure
Copy linkTweet thisAlerts:
@DanUKauthorMar 06.2007 — Hi there ?

Just took a look at this again as I haven't had a chance, and I still can't get it working. Not sure what I'm doing wrong!

So... I have my HTML form with the <form tag that submits to a 'goform.php', in goform.php, just under session_start(); I have:

[code=php]
$direct_name = htmlentities($_POST['NAME']);
$direct_email = htmlentities($_POST['EMAIL']);
[/code]


Then back on the actual form (which is a .php yes) I have:

[code=php]
<input type="text" name="NAME" value="<?php echo (isset($direct_name) ? $direct_name : ""); ?>"" />

<input type="text" name="EMAIL" value="<?php echo (isset($direct_email) ? $direct_email : ""); ?>"" />
[/code]


If the errors show up about missing input, and the user selects their back button, the fields aren't populated - and no php errors.

Any ideas? ?
Copy linkTweet thisAlerts:
@prophitMar 06.2007 — send me the full script of your main form. I will adjust it for you. Im not sure where you keep getting the
<i>
</i>&lt;?php echo (isset($direct_email) ? $direct_email : ""); ?&gt;""


That should be
<i>
</i>="&lt;?php echo htmlspecialchars(stripslashes($direct_name)); ?&gt;" <br/>
Copy linkTweet thisAlerts:
@NightShift58Mar 06.2007 — Don't build a script or application on the assumption that any values will be there when clicking on the "Back" button.

Each browser and each user can have their own settings, now or in the future, that will prevent this from working reliably.

The only way to keep such values going back and forth is if they have previously been stored to session variables or are passed via GET/URL.
Copy linkTweet thisAlerts:
@bokehMar 06.2007 — [code=php]<?php
$direct_name = "Mr. Coder";
?>
<input type="text" name="NAME" class="formwidth" maxlength="32" value="<?php echo (isset($direct_name) ? $direct_name : ""); ?>" />[/QUOTE][code=php]<input type="text" name="NAME" class="formwidth" maxlength="32" value="<?php echo @$direct_name ?>">[/code]
Copy linkTweet thisAlerts:
@DanUKauthorMar 08.2007 — Hi there ?

I managed to get this working, thank god.

One problem I'm still having though is adding this data, all the others work except these...

Basically it's a rota box, and it comprises like:

[code=php]
$_SESSION['staffappsunstart1'] = stripslashes(strip_tags($_POST['start1[0]']));
$_SESSION['staffappsunfinish2'] = stripslashes(strip_tags($_POST['finish1[0]']));
$_SESSION['staffappsunstart2'] = stripslashes(strip_tags($_POST['start2[0]']));
$_SESSION['staffappsunfinish2'] = stripslashes(strip_tags($_POST['finish2[0]']));
[/code]


Each of the [0] changes to [1] [2] etc depending on the day. These don't get populated, which I think is because with the []'s it treats it differently? Is there anyway I can work around this, as we use this in another way which works out total hours per day and weekly total.

Also, to remember a selected menu, would I need to add something like

echo "<option value="value here" ". ($_SESSION["something"]==!"" ? 'selected="selected"' : '').">option value</option>n";

for it to work? Or is there a simpler way? The reason I ask is we have so many select menus it will take forever - but if it has to be done, it has to be done ?

Thanks!
Copy linkTweet thisAlerts:
@MrCoderMar 08.2007 — [code=php]<input type="text" name="NAME" class="formwidth" maxlength="32" value="<?php echo @$direct_name ?>">[/code][/QUOTE]

That really works?

I assumed it was only used for functions.
Copy linkTweet thisAlerts:
@DanUKauthorMar 08.2007 — I'm just using

[code=php]value="<?php echo $directname; ?>"[/code]

As I'm setting the session with stripslahses/strip_tags elsewhere ?
Copy linkTweet thisAlerts:
@bokehMar 08.2007 — That really works?[/QUOTE]Yes it does. First the delimiter is not needed as there is nothing to delimit. The code posted above (post #19) by DanUK would raise an error notice if error reporting were set to E_ALL and the variable were not already not set.

[B]From the manual:[/B]

PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.The @-operator works only on expressions. A simple rule of thumb is: if you can take the value of something, you can prepend the @ operator to it. For instance, [B]you can prepend it to variables[/B], function and include() calls, constants, and so forth.

Error Control Operators
Copy linkTweet thisAlerts:
@DanUKauthorMar 09.2007 — Any ideas on my questions please guys ?
Copy linkTweet thisAlerts:
@NightShift58Mar 10.2007 — [code=php]$_SESSION['staffappsunstart1'] = stripslashes(strip_tags($_POST['start1'][0]));
$_SESSION['staffappsunfinish2'] = stripslashes(strip_tags($_POST['finish1'][0]));
$_SESSION['staffappsunstart2'] = stripslashes(strip_tags($_POST['start2'][0]));
$_SESSION['staffappsunfinish2'] = stripslashes(strip_tags($_POST['finish2'][0]));[/code]
Copy linkTweet thisAlerts:
@DanUKauthorMar 10.2007 — Brilliant, thank you - that's working nicely ?)

How would you suggest doing the select menus I mentioned in my post a couple back too? Is there an easy way, or would I have to do it like I mentioned?

Thanks!
Copy linkTweet thisAlerts:
@NightShift58Mar 10.2007 — It's the only way I know to make menus/selects sticky.

The snippet you posted will not work, as you need to compare 2 values but I'm assuming it's just an example.
×

Success!

Help @DanUK spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...