PHP Save info from textbox script

bladee4r

Regular Member
Joined
May 3, 2021
Messages
390
Reaction score
358
I had a script like this before, but I lost it. I'm not too good with PHP, can someone provide me a simple script that just collects user input from a text box upon "submit button"?
Even if that submit button is a redirect to another page?

I tried it myself, but I can't figure out how to activate the <a href> at the same time as "saving" the user textbox input into a server-side txt file.
I just want the script to append whatever is added into the text box, to a server-side txt file. Can anyone help me out? I'm not doing web2.0 otherwise I would use something from there.
 

plopza

Junior Member
Joined
Nov 24, 2021
Messages
184
Reaction score
144
To get what is submitted and use is just $_POST['fieldname'];

So like this
//form page
<Form method=post action=processingpage.php>
<input type=text name=textbox>
<input type=submit name=submit value=submit>

//processingpage.php
<?php
$text=$_POST['textbox'];
do what you want with variable $text

Hope that helps
 

bladee4r

Regular Member
Joined
May 3, 2021
Messages
390
Reaction score
358
To get what is submitted and use is just $_POST['fieldname'];

So like this
//form page
<Form method=post action=processingpage.php>
<input type=text name=textbox>
<input type=submit name=submit value=submit>

//processingpage.php
<?php
$text=$_POST['textbox'];
do what you want with variable $text

Hope that helps
Okay, yeah that looks familiar I think my last one was quite similar.
How would I get that button to also redirect to a new link (other page on website)
Could I include a redirect in processingpage.php ?
 

Machairodont

Junior Member
Joined
Oct 9, 2021
Messages
163
Reaction score
150
It's the "action" attribute of the form that defines which script/page will be loaded if you press the submit button.

1637921572332.png


Another approach would be to use JS to send the data with AJAX to a backend script, and then redirect to another page.
 
Top