HTML Form with URL post and variables

I need to set up a simple HTML form that contains 5 text fields on it: USERNAME, PASSWORD, PHONE NUMBER, FROM NAME and SAMPLE TEXT.

When the user has completed the 5 fields and clicks the submit button on the form, it should run the following PHP code/script, passing the 5 variables to it:

<?php 
    $username = 'USERNAME';
    $password = 'PASSWORD';
    $destination = 'PHONE NUMBER';
    $source = 'FROM NAME';
    $text = 'SAMPLE TEXT';
        
    $content =  'action=sendsms'.
                '&user='.rawurlencode($username).
                '&password='.rawurlencode($password).
                '&to='.rawurlencode($destination).
                '&from='.rawurlencode($source).
                '&text='.rawurlencode($text);
    
    $smsglobal_response = file_get_contents('http://www.smsglobal.com.au/http-api.php?'.$content);
    
    //Sample Response
    //OK: 0; Sent queued message ID: 04b4a8d4a5a02176 SMSGlobalMsgID:6613115713715266 
    
    $explode_response = explode('SMSGlobalMsgID:', $smsglobal_response);
    
    if(count($explode_response) == 2) { //Message Success
        $smsglobal_message_id = $explode_response[1];
        
        //SMSGlobal Message ID
        echo $smsglobal_message_id;
    } else { //Message Failed
        echo 'Message Failed'.'<br />';
        
        //SMSGlobal Response
        echo $smsglobal_response;    
    }
?> 

Open in new window


How do I do this?

Thanks
wesmanbigmig13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cornelia YoderArtistCommented:
If the code you posted is the action script, then you need to retrieve the input values from the $_POST array:


    $username = $_POST['USERNAME'];
    $password =$_POST[ 'PASSWORD'];
    $destination = $_POST['PHONE NUMBER'];
    $source = $_POST['FROM NAME'];
    $text = $_POST['SAMPLE TEXT'];


This is assuming your form uses  METHOD=POST, which is the best way.
0
wesmanbigmig13Author Commented:
Thanks yodercm, but please can you confirm what the <form> tag should look like on the HTML form page, and also what code should we use for the Submit button on that page?
0
Julian HansenCommented:
Not for points

<form action="name_of_php_file.php" method="post">
Define input fields here
Change the Value to whatever text you want to see on the button
<input type="submit" value="Send" />
</form>

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Ray PaseurCommented:
PHP has this exact topic documented in the online manual:
http://php.net/manual/en/tutorial.forms.php

If you want to go a little further, this article will help you find some good learning resources and more importantly avoid the many bad PHP examples that litter the internet.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

<?php // RAY_temp_wesmanbigwig13.php 2013-10-15
error_reporting(E_ALL);

// http://www.experts-exchange.com/Web_Development/Web_Frameworks/Q_28267038.html

// IF THERE IS A REQUEST
if (!empty($_POST))
{
    $username    = $_POST['USERNAME'];
    $password    = $_POST['PASSWORD'];
    $destination = $_POST['PHONENUMBER'];
    $source      = $_POST['FROMNAME'];
    $text        = $_POST['SAMPLETEXT'];

    $content =  'action=sendsms'.
                '&user='.rawurlencode($username).
                '&password='.rawurlencode($password).
                '&to='.rawurlencode($destination).
                '&from='.rawurlencode($source).
                '&text='.rawurlencode($text);

    $smsglobal_response = file_get_contents('http://www.smsglobal.com.au/http-api.php?'.$content);

    //Sample Response
    //OK: 0; Sent queued message ID: 04b4a8d4a5a02176 SMSGlobalMsgID:6613115713715266

    $explode_response = explode('SMSGlobalMsgID:', $smsglobal_response);

    if(count($explode_response) == 2) { //Message Success
        $smsglobal_message_id = $explode_response[1];

        //SMSGlobal Message ID
        echo $smsglobal_message_id;
    } else { //Message Failed
        echo 'Message Failed'.'<br />';

        //SMSGlobal Response
        echo $smsglobal_response;
    }
}

$form = <<<EOD
<form method="post">
<input name="USERNAME" />
<input name="PASSWORD" />
<input name="PHONENUMBER" />
<input name="FROMNAME" />
<input name="SAMPLETEXT" />
<input type="submit" />
</form>
EOD;

echo $form;

Open in new window

HTH, ~Ray
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wesmanbigmig13Author Commented:
Hi Ray - that code looks great, however when we run it as a PHP page it simply says Message Failed when we submit the form. We have double-checked that we are using the correct variable names and the correct values for the variables, but it just will not send the message to the SMSGlobal gateway. It simply errors with the message: "Message Failed"

Is there possibly something out of line in the code you have supplied?

Thanks
0
Ray PaseurCommented:
I don't know -- I cannot test it because I do not have the credentials to test it.  If you want to try it on my server, the link is here.  Please let me know what you find!
http://www.laprbass.com/RAY_temp_wesmanbigwig13.php

Thanks and regards, ~Ray
0
wesmanbigmig13Author Commented:
Thanks Experts - I couldn't get it working successfully using the code supplied, but Ray's method was best.
0
Ray PaseurCommented:
Please take a quick look at the grading guidelines.  When you're giving us incomplete information (eg: we cannot test because the resource you want to acquire is behind a password-protected wall) it's nearly impossible to give you a complete answer.  In these cases the best approach is to set up a test account so you can give out the credentials and get help from those of us who can test and show you the answer.  Giving a marked-down grade is not the right way to get additional help.
http://support.experts-exchange.com/customer/portal/articles/481419
0
wesmanbigmig13Author Commented:
Thanks Ray, but in this case it isn't possible to give out test credentials because the only credentials we have are our own account details. I did award you the lion's share of the points for your help but after spending 2 hours trying to get the code you supplied to work and still not being able to get it to work we had to seek out an alternate solution that did work. Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Frameworks

From novice to tech pro — start learning today.